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: 9a3a0cc9cc8fccdba2b842555238622255e7a4e2 (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
# 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 { described_class.new(parent, user, params).execute }

    new_list

    expect { described_class.new(parent, user, params).execute }.not_to exceed_query_limit(control)
  end

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

    items = described_class.new(parent, user, 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 = described_class.new(parent, user, 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 = described_class.new(parent, user, 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 = described_class.new(parent, user, 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
    service = described_class.new(parent, user, board_id: board.id, id: list.id)

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

  it 'raises an error if list id is invalid' do
    service = described_class.new(parent, user, board_id: board.id, id: nil)

    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 = described_class.new(parent, user, params).execute

    expect(items).to match_array(all_items)
  end
end