diff options
Diffstat (limited to 'spec/support/shared_examples/services/boards/items_list_service_shared_examples.rb')
-rw-r--r-- | spec/support/shared_examples/services/boards/items_list_service_shared_examples.rb | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/spec/support/shared_examples/services/boards/items_list_service_shared_examples.rb b/spec/support/shared_examples/services/boards/items_list_service_shared_examples.rb index 9a3a0cc9cc8..ed05a150f8b 100644 --- a/spec/support/shared_examples/services/boards/items_list_service_shared_examples.rb +++ b/spec/support/shared_examples/services/boards/items_list_service_shared_examples.rb @@ -3,17 +3,17 @@ 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 } + control = ActiveRecord::QueryRecorder.new { list_service(params).execute } new_list - expect { described_class.new(parent, user, params).execute }.not_to exceed_query_limit(control) + expect { list_service(params).execute }.not_to exceed_query_limit(control) end - it 'returns opened items when list_id is missing' do + it 'returns opened items when list_id and list are missing' do params = { board_id: board.id } - items = described_class.new(parent, user, params).execute + items = list_service(params).execute expect(items).to match_array(backlog_items) end @@ -21,7 +21,7 @@ RSpec.shared_examples 'items list service' do 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 + items = list_service(params).execute expect(items).to match_array(backlog_items) end @@ -29,7 +29,7 @@ RSpec.shared_examples 'items list service' do 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 + items = list_service(params).execute expect(items).to match_array(list1_items) end @@ -37,20 +37,24 @@ RSpec.shared_examples 'items list service' do 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 + 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 - service = described_class.new(parent, user, board_id: board.id, id: list.id) + 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 id is invalid' do - service = described_class.new(parent, user, board_id: board.id, id: nil) + 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 @@ -58,8 +62,22 @@ RSpec.shared_examples 'items list service' do 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 + 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 |