Update Boards::Issues::ListService to list issues for a board list

parent 1a4b1e97
...@@ -10,6 +10,10 @@ module Boards ...@@ -10,6 +10,10 @@ module Boards
private private
def board
@board ||= project.boards.find(params[:board_id])
end
def list def list
@list ||= board.lists.find(params[:id]) @list ||= board.lists.find(params[:id])
end end
......
...@@ -4,7 +4,7 @@ describe Boards::Issues::ListService, services: true do ...@@ -4,7 +4,7 @@ describe Boards::Issues::ListService, services: true do
describe '#execute' do describe '#execute' do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project_with_board) } let(:project) { create(:project_with_board) }
let(:board) { project.board } let(:board) { create(:board, project: project) }
let(:bug) { create(:label, project: project, name: 'Bug') } let(:bug) { create(:label, project: project, name: 'Bug') }
let(:development) { create(:label, project: project, name: 'Development') } let(:development) { create(:label, project: project, name: 'Development') }
...@@ -13,10 +13,10 @@ describe Boards::Issues::ListService, services: true do ...@@ -13,10 +13,10 @@ describe Boards::Issues::ListService, services: true do
let(:p2) { create(:label, title: 'P2', project: project, priority: 2) } let(:p2) { create(:label, title: 'P2', project: project, priority: 2) }
let(:p3) { create(:label, title: 'P3', project: project, priority: 3) } let(:p3) { create(:label, title: 'P3', project: project, priority: 3) }
let!(:backlog) { project.board.backlog_list } let!(:backlog) { create(:backlog_list, board: board) }
let!(:list1) { create(:list, board: board, label: development, position: 0) } let!(:list1) { create(:list, board: board, label: development, position: 0) }
let!(:list2) { create(:list, board: board, label: testing, position: 1) } let!(:list2) { create(:list, board: board, label: testing, position: 1) }
let!(:done) { project.board.done_list } let!(:done) { create(:done_list, board: board) }
let!(:opened_issue1) { create(:labeled_issue, project: project, labels: [bug]) } let!(:opened_issue1) { create(:labeled_issue, project: project, labels: [bug]) }
let!(:opened_issue2) { create(:labeled_issue, project: project, labels: [p2]) } let!(:opened_issue2) { create(:labeled_issue, project: project, labels: [p2]) }
...@@ -37,7 +37,7 @@ describe Boards::Issues::ListService, services: true do ...@@ -37,7 +37,7 @@ describe Boards::Issues::ListService, services: true do
end end
it 'delegates search to IssuesFinder' do it 'delegates search to IssuesFinder' do
params = { id: list1.id } params = { board_id: board.id, id: list1.id }
expect_any_instance_of(IssuesFinder).to receive(:execute).once.and_call_original expect_any_instance_of(IssuesFinder).to receive(:execute).once.and_call_original
...@@ -46,7 +46,7 @@ describe Boards::Issues::ListService, services: true do ...@@ -46,7 +46,7 @@ describe Boards::Issues::ListService, services: true do
context 'sets default order to priority' do context 'sets default order to priority' do
it 'returns opened issues when listing issues from Backlog' do it 'returns opened issues when listing issues from Backlog' do
params = { id: backlog.id } params = { board_id: board.id, id: backlog.id }
issues = described_class.new(project, user, params).execute issues = described_class.new(project, user, params).execute
...@@ -54,7 +54,7 @@ describe Boards::Issues::ListService, services: true do ...@@ -54,7 +54,7 @@ describe Boards::Issues::ListService, services: true do
end end
it 'returns closed issues when listing issues from Done' do it 'returns closed issues when listing issues from Done' do
params = { id: done.id } params = { board_id: board.id, id: done.id }
issues = described_class.new(project, user, params).execute issues = described_class.new(project, user, params).execute
...@@ -62,12 +62,29 @@ describe Boards::Issues::ListService, services: true do ...@@ -62,12 +62,29 @@ describe Boards::Issues::ListService, services: true do
end end
it 'returns opened issues that have label list applied when listing issues from a label list' do it 'returns opened issues that have label list applied when listing issues from a label list' do
params = { id: list1.id } params = { board_id: board.id, id: list1.id }
issues = described_class.new(project, user, params).execute issues = described_class.new(project, user, params).execute
expect(issues).to eq [list1_issue3, list1_issue1, list1_issue2] expect(issues).to eq [list1_issue3, list1_issue1, list1_issue2]
end end
end end
context 'with list that does not belongs to the board' do
it 'raises an error' do
list = create(:list)
service = described_class.new(project, user, board_id: board.id, id: list.id)
expect { service.execute }.to raise_error(ActiveRecord::RecordNotFound)
end
end
context 'with invalid list id' do
it 'raises an error' do
service = described_class.new(project, user, board_id: board.id, id: nil)
expect { service.execute }.to raise_error(ActiveRecord::RecordNotFound)
end
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment