2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-15 08:41:40 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Issues::MoveService do
|
2016-02-15 08:41:40 -05:00
|
|
|
let(:user) { create(:user) }
|
2016-02-24 07:20:08 -05:00
|
|
|
let(:author) { create(:user) }
|
2016-02-22 05:00:40 -05:00
|
|
|
let(:title) { 'Some issue' }
|
|
|
|
let(:description) { 'Some issue description' }
|
2018-06-20 10:41:23 -04:00
|
|
|
let(:group) { create(:group, :private) }
|
|
|
|
let(:sub_group_1) { create(:group, :private, parent: group) }
|
|
|
|
let(:sub_group_2) { create(:group, :private, parent: group) }
|
|
|
|
let(:old_project) { create(:project, namespace: sub_group_1) }
|
|
|
|
let(:new_project) { create(:project, namespace: sub_group_2) }
|
2016-02-24 05:52:02 -05:00
|
|
|
|
2016-02-24 07:20:08 -05:00
|
|
|
let(:old_issue) do
|
2018-10-29 05:05:47 -04:00
|
|
|
create(:issue, title: title, description: description, project: old_project, author: author)
|
2016-02-24 07:20:08 -05:00
|
|
|
end
|
|
|
|
|
2018-06-20 10:41:23 -04:00
|
|
|
subject(:move_service) do
|
2016-03-20 04:28:06 -04:00
|
|
|
described_class.new(old_project, user)
|
2016-02-22 06:41:33 -05:00
|
|
|
end
|
2016-02-15 08:41:40 -05:00
|
|
|
|
2016-02-22 06:41:33 -05:00
|
|
|
shared_context 'user can move issue' do
|
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
old_project.add_reporter(user)
|
|
|
|
new_project.add_reporter(user)
|
2016-10-24 04:05:21 -04:00
|
|
|
end
|
2016-02-22 06:41:33 -05:00
|
|
|
end
|
2016-03-15 10:01:26 -04:00
|
|
|
|
2016-03-18 09:48:55 -04:00
|
|
|
describe '#execute' do
|
|
|
|
shared_context 'issue move executed' do
|
2016-06-01 12:33:49 -04:00
|
|
|
let!(:award_emoji) { create(:award_emoji, awardable: old_issue) }
|
2016-04-28 04:52:23 -04:00
|
|
|
|
2016-03-18 09:48:55 -04:00
|
|
|
let!(:new_issue) { move_service.execute(old_issue, new_project) }
|
2016-02-15 08:41:40 -05:00
|
|
|
end
|
|
|
|
|
2016-03-18 09:48:55 -04:00
|
|
|
context 'issue movable' do
|
|
|
|
include_context 'user can move issue'
|
2016-02-17 09:59:25 -05:00
|
|
|
|
2016-02-22 05:00:40 -05:00
|
|
|
context 'generic issue' do
|
|
|
|
include_context 'issue move executed'
|
|
|
|
|
|
|
|
it 'creates a new issue in a new project' do
|
|
|
|
expect(new_issue.project).to eq new_project
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'rewrites issue title' do
|
|
|
|
expect(new_issue.title).to eq title
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'rewrites issue description' do
|
2016-03-15 06:35:40 -04:00
|
|
|
expect(new_issue.description).to eq description
|
2016-02-22 05:00:40 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds system note to old issue at the end' do
|
2016-11-23 01:55:23 -05:00
|
|
|
expect(old_issue.notes.last.note).to start_with 'moved to'
|
2016-02-22 05:00:40 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds system note to new issue at the end' do
|
2016-11-23 01:55:23 -05:00
|
|
|
expect(new_issue.notes.last.note).to start_with 'moved from'
|
2016-02-22 05:00:40 -05:00
|
|
|
end
|
2016-02-22 09:18:39 -05:00
|
|
|
|
|
|
|
it 'closes old issue' do
|
|
|
|
expect(old_issue.closed?).to be true
|
|
|
|
end
|
|
|
|
|
2016-02-23 08:18:54 -05:00
|
|
|
it 'persists new issue' do
|
|
|
|
expect(new_issue.persisted?).to be true
|
2016-02-22 09:18:39 -05:00
|
|
|
end
|
2016-02-24 06:18:46 -05:00
|
|
|
|
2016-03-14 03:25:37 -04:00
|
|
|
it 'persists all changes' do
|
2016-02-24 06:18:46 -05:00
|
|
|
expect(old_issue.changed?).to be false
|
2016-03-15 05:14:39 -04:00
|
|
|
expect(new_issue.changed?).to be false
|
2016-02-24 06:18:46 -05:00
|
|
|
end
|
2016-02-24 07:20:08 -05:00
|
|
|
|
2016-03-14 03:25:37 -04:00
|
|
|
it 'preserves author' do
|
|
|
|
expect(new_issue.author).to eq author
|
2016-02-24 07:20:08 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a new internal id for issue' do
|
|
|
|
expect(new_issue.iid).to be 1
|
|
|
|
end
|
2016-03-17 06:11:22 -04:00
|
|
|
|
|
|
|
it 'marks issue as moved' do
|
|
|
|
expect(old_issue.moved?).to eq true
|
|
|
|
expect(old_issue.moved_to).to eq new_issue
|
|
|
|
end
|
2016-03-23 07:41:53 -04:00
|
|
|
|
|
|
|
it 'preserves create time' do
|
|
|
|
expect(old_issue.created_at).to eq new_issue.created_at
|
|
|
|
end
|
2016-06-01 12:33:49 -04:00
|
|
|
|
|
|
|
it 'moves the award emoji' do
|
|
|
|
expect(old_issue.award_emoji.first.name).to eq new_issue.reload.award_emoji.first.name
|
|
|
|
end
|
2016-02-17 09:59:25 -05:00
|
|
|
end
|
2016-02-15 09:14:57 -05:00
|
|
|
|
2018-10-29 05:05:47 -04:00
|
|
|
context 'issue with assignee' do
|
|
|
|
let(:assignee) { create(:user) }
|
2016-03-23 07:41:53 -04:00
|
|
|
|
2018-10-29 05:05:47 -04:00
|
|
|
before do
|
|
|
|
old_issue.assignees = [assignee]
|
2016-03-24 07:28:43 -04:00
|
|
|
end
|
2016-02-23 08:18:54 -05:00
|
|
|
|
2018-10-29 05:05:47 -04:00
|
|
|
it 'preserves assignee with access to the new issue' do
|
|
|
|
new_project.add_reporter(assignee)
|
2016-02-23 08:18:54 -05:00
|
|
|
|
2018-10-29 05:05:47 -04:00
|
|
|
new_issue = move_service.execute(old_issue, new_project)
|
2016-02-23 08:18:54 -05:00
|
|
|
|
2018-10-29 05:05:47 -04:00
|
|
|
expect(new_issue.assignees).to eq([assignee])
|
2016-02-23 08:18:54 -05:00
|
|
|
end
|
2016-10-25 01:33:49 -04:00
|
|
|
|
2018-10-29 05:05:47 -04:00
|
|
|
it 'ignores assignee without access to the new issue' do
|
|
|
|
new_issue = move_service.execute(old_issue, new_project)
|
2016-10-25 01:33:49 -04:00
|
|
|
|
2018-10-29 05:05:47 -04:00
|
|
|
expect(new_issue.assignees).to be_empty
|
2016-10-25 01:33:49 -04:00
|
|
|
end
|
2016-02-23 08:18:54 -05:00
|
|
|
end
|
2016-02-22 06:41:33 -05:00
|
|
|
|
2016-03-18 09:48:55 -04:00
|
|
|
context 'moving to same project' do
|
|
|
|
let(:new_project) { old_project }
|
2016-02-22 06:41:33 -05:00
|
|
|
|
2016-03-18 09:48:55 -04:00
|
|
|
it 'raises error' do
|
|
|
|
expect { move_service.execute(old_issue, new_project) }
|
|
|
|
.to raise_error(StandardError, /Cannot move issue/)
|
|
|
|
end
|
2016-02-22 06:41:33 -05:00
|
|
|
end
|
2017-12-22 05:38:35 -05:00
|
|
|
|
|
|
|
context 'project issue hooks' do
|
2018-01-24 09:09:59 -05:00
|
|
|
let!(:hook) { create(:project_hook, project: old_project, issues_events: true) }
|
2017-12-22 05:38:35 -05:00
|
|
|
|
|
|
|
it 'executes project issue hooks' do
|
2018-01-24 09:09:59 -05:00
|
|
|
allow_any_instance_of(WebHookService).to receive(:execute)
|
|
|
|
|
2017-12-22 05:38:35 -05:00
|
|
|
# Ideally, we'd test that `WebHookWorker.jobs.size` increased by 1,
|
|
|
|
# but since the entire spec run takes place in a transaction, we never
|
|
|
|
# actually get to the `after_commit` hook that queues these jobs.
|
|
|
|
expect { move_service.execute(old_issue, new_project) }
|
|
|
|
.not_to raise_error # Sidekiq::Worker::EnqueueFromTransactionError
|
|
|
|
end
|
|
|
|
end
|
2016-02-22 06:41:33 -05:00
|
|
|
end
|
|
|
|
|
2016-03-18 09:48:55 -04:00
|
|
|
describe 'move permissions' do
|
|
|
|
let(:move) { move_service.execute(old_issue, new_project) }
|
2016-02-22 06:41:33 -05:00
|
|
|
|
2016-03-14 03:30:37 -04:00
|
|
|
context 'user is reporter in both projects' do
|
2016-02-22 06:41:33 -05:00
|
|
|
include_context 'user can move issue'
|
2016-05-23 19:37:59 -04:00
|
|
|
it { expect { move }.not_to raise_error }
|
2016-02-22 06:41:33 -05:00
|
|
|
end
|
|
|
|
|
2016-03-14 03:30:37 -04:00
|
|
|
context 'user is reporter only in new project' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
new_project.add_reporter(user)
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
|
|
|
|
2016-03-18 09:48:55 -04:00
|
|
|
it { expect { move }.to raise_error(StandardError, /permissions/) }
|
2016-02-22 06:41:33 -05:00
|
|
|
end
|
|
|
|
|
2016-03-14 03:30:37 -04:00
|
|
|
context 'user is reporter only in old project' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
old_project.add_reporter(user)
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
|
|
|
|
2016-03-18 09:48:55 -04:00
|
|
|
it { expect { move }.to raise_error(StandardError, /permissions/) }
|
2016-02-22 06:41:33 -05:00
|
|
|
end
|
|
|
|
|
2016-03-14 03:30:37 -04:00
|
|
|
context 'user is reporter in one project and guest in another' do
|
2016-02-22 06:41:33 -05:00
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
new_project.add_guest(user)
|
|
|
|
old_project.add_reporter(user)
|
2016-02-22 06:41:33 -05:00
|
|
|
end
|
2016-02-16 05:47:00 -05:00
|
|
|
|
2016-03-18 09:48:55 -04:00
|
|
|
it { expect { move }.to raise_error(StandardError, /permissions/) }
|
2016-02-17 09:59:25 -05:00
|
|
|
end
|
2016-03-17 06:11:22 -04:00
|
|
|
|
|
|
|
context 'issue has already been moved' do
|
|
|
|
include_context 'user can move issue'
|
|
|
|
|
|
|
|
let(:moved_to_issue) { create(:issue) }
|
|
|
|
|
|
|
|
let(:old_issue) do
|
|
|
|
create(:issue, project: old_project, author: author,
|
|
|
|
moved_to: moved_to_issue)
|
|
|
|
end
|
|
|
|
|
2016-03-18 09:48:55 -04:00
|
|
|
it { expect { move }.to raise_error(StandardError, /permissions/) }
|
2016-03-17 06:11:22 -04:00
|
|
|
end
|
2016-03-23 04:39:37 -04:00
|
|
|
|
|
|
|
context 'issue is not persisted' do
|
|
|
|
include_context 'user can move issue'
|
|
|
|
let(:old_issue) { build(:issue, project: old_project, author: author) }
|
|
|
|
it { expect { move }.to raise_error(StandardError, /permissions/) }
|
|
|
|
end
|
2016-02-15 09:14:57 -05:00
|
|
|
end
|
2016-02-15 08:41:40 -05:00
|
|
|
end
|
|
|
|
end
|