Welcome to mirror list, hosted at ThFree Co, Russian Federation.

items_list_service_shared_examples.rb « boards « services « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ed05a150f8b01e718445c5575b5a822d19f0ff07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# frozen_string_literal: true

RSpec.shared_examples 'items list service' do
  it 'avoids N+1' do
    params = { board_id: board.id }
    control = ActiveRecord::QueryRecorder.new { list_service(params).execute }

    new_list

    expect { list_service(params).execute }.not_to exceed_query_limit(control)
  end

  it 'returns opened items when list_id and list are missing' do
    params = { board_id: board.id }

    items = list_service(params).execute

    expect(items).to match_array(backlog_items)
  end

  it 'returns opened items when listing items from Backlog' do
    params = { board_id: board.id, id: backlog.id }

    items = list_service(params).execute

    expect(items).to match_array(backlog_items)
  end

  it 'returns opened items that have label list applied when listing items from a label list' do
    params = { board_id: board.id, id: list1.id }

    items = list_service(params).execute

    expect(items).to match_array(list1_items)
  end

  it 'returns closed items when listing items from Closed sorted by closed_at in descending order' do
    params = { board_id: board.id, id: closed.id }

    items = list_service(params).execute

    expect(items).to eq(closed_items)
  end

  it 'raises an error if the list does not belong to the board' do
    list = create(list_factory) # rubocop:disable Rails/SaveBang
    params = { board_id: board.id, id: list.id }

    service = list_service(params)

    expect { service.execute }.to raise_error(ActiveRecord::RecordNotFound)
  end

  it 'raises an error if list and list id are invalid or missing' do
    params = { board_id: board.id, id: nil, list: nil }

    service = list_service(params)

    expect { service.execute }.to raise_error(ActiveRecord::RecordNotFound)
  end

  it 'returns items from all lists if :all_list is used' do
    params = { board_id: board.id, all_lists: true }

    items = list_service(params).execute

    expect(items).to match_array(all_items)
  end

  it 'returns opened items that have label list applied when using list param' do
    params = { board_id: board.id, list: list1 }

    items = list_service(params).execute

    expect(items).to match_array(list1_items)
  end

  def list_service(params)
    args = [parent, user].push(params)

    described_class.new(*args)
  end
end