2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
RSpec.shared_examples 'issues move service' do |group|
|
2019-09-30 21:07:59 +05:30
|
|
|
shared_examples 'updating timestamps' do
|
|
|
|
it 'updates updated_at' do
|
|
|
|
expect {described_class.new(parent, user, params).execute(issue)}
|
|
|
|
.to change {issue.reload.updated_at}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
context 'when moving an issue between lists' do
|
|
|
|
let(:issue) { create(:labeled_issue, project: project, labels: [bug, development]) }
|
|
|
|
let(:params) { { board_id: board1.id, from_list_id: list1.id, to_list_id: list2.id } }
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
it_behaves_like 'updating timestamps'
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
it 'delegates the label changes to Issues::UpdateService' do
|
2018-11-20 20:47:30 +05:30
|
|
|
service = double(:service)
|
|
|
|
expect(Issues::UpdateService).to receive(:new).and_return(service)
|
|
|
|
expect(service).to receive(:execute).with(issue).once
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
described_class.new(parent, user, params).execute(issue)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes the label from the list it came from and adds the label of the list it goes to' do
|
|
|
|
described_class.new(parent, user, params).execute(issue)
|
|
|
|
|
|
|
|
expect(issue.reload.labels).to contain_exactly(bug, testing)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when moving to closed' do
|
|
|
|
let!(:list3) { create(:list, board: board2, label: regression, position: 1) }
|
|
|
|
|
|
|
|
let(:issue) { create(:labeled_issue, project: project, labels: [bug, development, testing, regression]) }
|
|
|
|
let(:params) { { board_id: board1.id, from_list_id: list2.id, to_list_id: closed.id } }
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
it_behaves_like 'updating timestamps'
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
it 'delegates the close proceedings to Issues::CloseService' do
|
|
|
|
expect_any_instance_of(Issues::CloseService).to receive(:execute).with(issue).once
|
|
|
|
|
|
|
|
described_class.new(parent, user, params).execute(issue)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes all list-labels from boards and close the issue' do
|
|
|
|
described_class.new(parent, user, params).execute(issue)
|
|
|
|
issue.reload
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(issue.labels).to contain_exactly(bug, regression)
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(issue).to be_closed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
context 'when moving to backlog' do
|
|
|
|
let(:milestone) { create(:milestone, project: project) }
|
|
|
|
let!(:backlog) { create(:backlog_list, board: board1) }
|
|
|
|
|
|
|
|
let(:issue) { create(:labeled_issue, project: project, labels: [bug, development, testing, regression], milestone: milestone) }
|
|
|
|
let(:params) { { board_id: board1.id, from_list_id: list2.id, to_list_id: backlog.id } }
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
it_behaves_like 'updating timestamps'
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
it 'keeps labels and milestone' do
|
|
|
|
described_class.new(parent, user, params).execute(issue)
|
|
|
|
issue.reload
|
|
|
|
|
|
|
|
expect(issue.labels).to contain_exactly(bug, regression)
|
|
|
|
expect(issue.milestone).to eq(milestone)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
context 'when moving from closed' do
|
|
|
|
let(:issue) { create(:labeled_issue, :closed, project: project, labels: [bug]) }
|
|
|
|
let(:params) { { board_id: board1.id, from_list_id: closed.id, to_list_id: list2.id } }
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
it_behaves_like 'updating timestamps'
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
it 'delegates the re-open proceedings to Issues::ReopenService' do
|
|
|
|
expect_any_instance_of(Issues::ReopenService).to receive(:execute).with(issue).once
|
|
|
|
|
|
|
|
described_class.new(parent, user, params).execute(issue)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds the label of the list it goes to and reopen the issue' do
|
|
|
|
described_class.new(parent, user, params).execute(issue)
|
|
|
|
issue.reload
|
|
|
|
|
|
|
|
expect(issue.labels).to contain_exactly(bug, testing)
|
|
|
|
expect(issue).to be_opened
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when moving to same list' do
|
2019-09-30 21:07:59 +05:30
|
|
|
let(:assignee) { create(:user) }
|
|
|
|
let(:params) { { board_id: board1.id, from_list_id: list1.id, to_list_id: list1.id } }
|
|
|
|
let(:issue1) { create(:labeled_issue, project: project, labels: [bug, development]) }
|
|
|
|
let(:issue2) { create(:labeled_issue, project: project, labels: [bug, development]) }
|
|
|
|
let(:issue) do
|
|
|
|
create(:labeled_issue, project: project, labels: [bug, development], assignees: [assignee])
|
|
|
|
end
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(described_class.new(parent, user, params).execute(issue)).to eq false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'keeps issues labels' do
|
|
|
|
described_class.new(parent, user, params).execute(issue)
|
|
|
|
|
|
|
|
expect(issue.reload.labels).to contain_exactly(bug, development)
|
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
it 'keeps issues assignees' do
|
|
|
|
described_class.new(parent, user, params).execute(issue)
|
|
|
|
|
|
|
|
expect(issue.reload.assignees).to contain_exactly(assignee)
|
|
|
|
end
|
2018-03-27 19:54:05 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
it 'sorts issues' do
|
|
|
|
reorder_issues(params, issues: [issue, issue1, issue2])
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
described_class.new(parent, user, params).execute(issue)
|
|
|
|
|
|
|
|
expect(issue.relative_position).to be_between(issue1.relative_position, issue2.relative_position)
|
|
|
|
end
|
2018-05-01 15:08:00 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
it 'does not update updated_at' do
|
|
|
|
reorder_issues(params, issues: [issue, issue1, issue2])
|
|
|
|
|
|
|
|
updated_at = issue.updated_at
|
|
|
|
updated_at1 = issue1.updated_at
|
|
|
|
updated_at2 = issue2.updated_at
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
travel_to(1.minute.from_now) do
|
2019-09-30 21:07:59 +05:30
|
|
|
described_class.new(parent, user, params).execute(issue)
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(issue.reload.updated_at.change(usec: 0)).to eq updated_at.change(usec: 0)
|
|
|
|
expect(issue1.reload.updated_at.change(usec: 0)).to eq updated_at1.change(usec: 0)
|
|
|
|
expect(issue2.reload.updated_at.change(usec: 0)).to eq updated_at2.change(usec: 0)
|
|
|
|
end
|
|
|
|
|
2018-05-01 15:08:00 +05:30
|
|
|
if group
|
|
|
|
context 'when on a group board' do
|
|
|
|
it 'sends the board_group_id parameter' do
|
|
|
|
params.merge!(move_after_id: issue1.id, move_before_id: issue2.id)
|
|
|
|
|
|
|
|
match_params = { move_between_ids: [issue1.id, issue2.id], board_group_id: parent.id }
|
|
|
|
expect(Issues::UpdateService).to receive(:new).with(issue.project, user, match_params).and_return(double(execute: build(:issue)))
|
|
|
|
|
|
|
|
described_class.new(parent, user, params).execute(issue)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
def reorder_issues(params, issues: [])
|
|
|
|
issues.each do |issue|
|
|
|
|
issue.move_to_end && issue.save!
|
|
|
|
end
|
|
|
|
|
|
|
|
params.merge!(move_after_id: issues[1].id, move_before_id: issues[2].id)
|
|
|
|
end
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
|
|
|
end
|