2016-07-28 06:33:41 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 14:24:02 +00:00
|
|
|
describe Boards::Issues::MoveService do
|
2016-07-28 06:33:41 +00:00
|
|
|
describe '#execute' do
|
|
|
|
let(:user) { create(:user) }
|
2016-10-05 17:32:53 +00:00
|
|
|
let(:project) { create(:empty_project) }
|
2016-10-05 17:50:44 +00:00
|
|
|
let(:board1) { create(:board, project: project) }
|
2016-07-28 06:33:41 +00:00
|
|
|
|
|
|
|
let(:bug) { create(:label, project: project, name: 'Bug') }
|
|
|
|
let(:development) { create(:label, project: project, name: 'Development') }
|
|
|
|
let(:testing) { create(:label, project: project, name: 'Testing') }
|
|
|
|
|
2016-10-05 17:50:44 +00:00
|
|
|
let!(:list1) { create(:list, board: board1, label: development, position: 0) }
|
|
|
|
let!(:list2) { create(:list, board: board1, label: testing, position: 1) }
|
2017-03-24 12:40:35 +00:00
|
|
|
let!(:closed) { create(:closed_list, board: board1) }
|
2016-07-28 06:33:41 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
project.team << [user, :developer]
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when moving an issue between lists' do
|
|
|
|
let(:issue) { create(:labeled_issue, project: project, labels: [bug, development]) }
|
2016-10-05 17:50:44 +00:00
|
|
|
let(:params) { { board_id: board1.id, from_list_id: list1.id, to_list_id: list2.id } }
|
2016-07-28 06:33:41 +00:00
|
|
|
|
|
|
|
it 'delegates the label changes to Issues::UpdateService' do
|
|
|
|
expect_any_instance_of(Issues::UpdateService).to receive(:execute).with(issue).once
|
|
|
|
|
2016-08-16 04:07:25 +00:00
|
|
|
described_class.new(project, user, params).execute(issue)
|
2016-07-28 06:33:41 +00:00
|
|
|
end
|
|
|
|
|
2016-08-16 04:07:25 +00:00
|
|
|
it 'removes the label from the list it came from and adds the label of the list it goes to' do
|
|
|
|
described_class.new(project, user, params).execute(issue)
|
2016-07-28 06:33:41 +00:00
|
|
|
|
|
|
|
expect(issue.reload.labels).to contain_exactly(bug, testing)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-24 12:40:35 +00:00
|
|
|
context 'when moving to closed' do
|
2016-10-05 17:50:44 +00:00
|
|
|
let(:board2) { create(:board, project: project) }
|
|
|
|
let(:regression) { create(:label, project: project, name: 'Regression') }
|
|
|
|
let!(:list3) { create(:list, board: board2, label: regression, position: 1) }
|
|
|
|
|
|
|
|
let(:issue) { create(:labeled_issue, project: project, labels: [bug, development, testing, regression]) }
|
2017-03-24 12:40:35 +00:00
|
|
|
let(:params) { { board_id: board1.id, from_list_id: list2.id, to_list_id: closed.id } }
|
2016-07-28 06:33:41 +00:00
|
|
|
|
|
|
|
it 'delegates the close proceedings to Issues::CloseService' do
|
|
|
|
expect_any_instance_of(Issues::CloseService).to receive(:execute).with(issue).once
|
|
|
|
|
2016-08-16 04:07:25 +00:00
|
|
|
described_class.new(project, user, params).execute(issue)
|
2016-07-28 06:33:41 +00:00
|
|
|
end
|
|
|
|
|
2016-10-05 17:50:44 +00:00
|
|
|
it 'removes all list-labels from project boards and close the issue' do
|
2016-08-16 04:07:25 +00:00
|
|
|
described_class.new(project, user, params).execute(issue)
|
2016-07-28 06:33:41 +00:00
|
|
|
issue.reload
|
|
|
|
|
|
|
|
expect(issue.labels).to contain_exactly(bug)
|
|
|
|
expect(issue).to be_closed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-24 12:40:35 +00:00
|
|
|
context 'when moving from closed' do
|
2016-07-28 06:33:41 +00:00
|
|
|
let(:issue) { create(:labeled_issue, :closed, project: project, labels: [bug]) }
|
2017-03-24 12:40:35 +00:00
|
|
|
let(:params) { { board_id: board1.id, from_list_id: closed.id, to_list_id: list2.id } }
|
2016-07-28 06:33:41 +00:00
|
|
|
|
|
|
|
it 'delegates the re-open proceedings to Issues::ReopenService' do
|
|
|
|
expect_any_instance_of(Issues::ReopenService).to receive(:execute).with(issue).once
|
|
|
|
|
2016-08-16 04:07:25 +00:00
|
|
|
described_class.new(project, user, params).execute(issue)
|
2016-07-28 06:33:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds the label of the list it goes to and reopen the issue' do
|
2016-08-16 04:07:25 +00:00
|
|
|
described_class.new(project, user, params).execute(issue)
|
2016-07-28 06:33:41 +00:00
|
|
|
issue.reload
|
|
|
|
|
|
|
|
expect(issue.labels).to contain_exactly(bug, testing)
|
2017-07-19 14:03:50 +00:00
|
|
|
expect(issue).to be_opened
|
2016-07-28 06:33:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-17 14:50:22 +00:00
|
|
|
context 'when moving to same list' do
|
2017-03-07 17:57:24 +00:00
|
|
|
let(:issue) { create(:labeled_issue, project: project, labels: [bug, development]) }
|
2017-02-27 15:45:55 +00:00
|
|
|
let(:issue1) { create(:labeled_issue, project: project, labels: [bug, development]) }
|
|
|
|
let(:issue2) { create(:labeled_issue, project: project, labels: [bug, development]) }
|
2017-03-07 17:57:24 +00:00
|
|
|
let(:params) { { board_id: board1.id, from_list_id: list1.id, to_list_id: list1.id } }
|
2016-08-17 14:50:22 +00:00
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(described_class.new(project, user, params).execute(issue)).to eq false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'keeps issues labels' do
|
|
|
|
described_class.new(project, user, params).execute(issue)
|
|
|
|
|
|
|
|
expect(issue.reload.labels).to contain_exactly(bug, development)
|
|
|
|
end
|
2017-02-27 15:45:55 +00:00
|
|
|
|
|
|
|
it 'sorts issues' do
|
2017-03-07 17:57:24 +00:00
|
|
|
[issue, issue1, issue2].each do |issue|
|
|
|
|
issue.move_to_end && issue.save!
|
|
|
|
end
|
2017-02-27 15:45:55 +00:00
|
|
|
|
2017-03-07 17:57:24 +00:00
|
|
|
params.merge!(move_after_iid: issue1.iid, move_before_iid: issue2.iid)
|
2017-02-27 15:45:55 +00:00
|
|
|
|
2017-03-07 17:57:24 +00:00
|
|
|
described_class.new(project, user, params).execute(issue)
|
2017-02-27 15:45:55 +00:00
|
|
|
|
2017-03-06 16:08:18 +00:00
|
|
|
expect(issue.relative_position).to be_between(issue1.relative_position, issue2.relative_position)
|
2017-02-27 15:45:55 +00:00
|
|
|
end
|
2016-08-17 14:50:22 +00:00
|
|
|
end
|
2016-07-28 06:33:41 +00:00
|
|
|
end
|
|
|
|
end
|