2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-15 08:41:40 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe Issues::MoveService do
|
2020-09-28 20:09:59 -04:00
|
|
|
include DesignManagementTestHelpers
|
|
|
|
|
2020-08-11 11:10:08 -04:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:author) { create(:user) }
|
|
|
|
let_it_be(:title) { 'Some issue' }
|
|
|
|
let_it_be(:description) { "Some issue description with mention to #{user.to_reference}" }
|
|
|
|
let_it_be(:group) { create(:group, :private) }
|
|
|
|
let_it_be(:sub_group_1) { create(:group, :private, parent: group) }
|
|
|
|
let_it_be(:sub_group_2) { create(:group, :private, parent: group) }
|
|
|
|
let_it_be(:old_project) { create(:project, namespace: sub_group_1) }
|
|
|
|
let_it_be(: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
|
2021-05-11 23:10:21 -04:00
|
|
|
described_class.new(project: old_project, current_user: 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
|
|
|
|
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
|
|
|
|
2021-06-20 20:10:50 -04:00
|
|
|
it 'creates resource state event' do
|
|
|
|
expect { move_service.execute(old_issue, new_project) }.to change(ResourceStateEvent.where(issue_id: old_issue), :count).by(1)
|
|
|
|
end
|
|
|
|
|
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
|
|
|
|
|
2020-08-11 11:10:08 -04:00
|
|
|
it 'copies issue title' do
|
2016-02-22 05:00:40 -05:00
|
|
|
expect(new_issue.title).to eq title
|
|
|
|
end
|
|
|
|
|
2020-08-11 11:10:08 -04:00
|
|
|
it 'copies 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
|
|
|
|
2021-06-20 20:10:50 -04:00
|
|
|
it 'marks issue as closed' do
|
|
|
|
expect(old_issue.closed?).to eq true
|
|
|
|
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
|
2020-08-11 11:10:08 -04:00
|
|
|
end
|
2016-06-01 12:33:49 -04:00
|
|
|
|
2020-08-11 11:10:08 -04:00
|
|
|
context 'issue with award emoji' do
|
|
|
|
let!(:award_emoji) { create(:award_emoji, awardable: old_issue) }
|
2020-02-13 19:09:07 -05:00
|
|
|
|
2020-08-11 11:10:08 -04:00
|
|
|
it 'copies the award emoji' do
|
|
|
|
old_issue.reload
|
|
|
|
new_issue = move_service.execute(old_issue, new_project)
|
|
|
|
|
|
|
|
expect(old_issue.award_emoji.first.name).to eq new_issue.reload.award_emoji.first.name
|
2020-02-13 19:09:07 -05:00
|
|
|
end
|
2016-02-17 09:59:25 -05:00
|
|
|
end
|
2016-02-15 09:14:57 -05:00
|
|
|
|
2020-09-08 17:08:53 -04:00
|
|
|
context 'issue with milestone' do
|
|
|
|
let(:milestone) { create(:milestone, group: sub_group_1) }
|
|
|
|
let(:new_project) { create(:project, namespace: sub_group_1) }
|
|
|
|
|
|
|
|
let(:old_issue) do
|
|
|
|
create(:issue, title: title, description: description, project: old_project, author: author, milestone: milestone)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
create(:resource_milestone_event, issue: old_issue, milestone: milestone, action: :add)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create extra milestone events' do
|
|
|
|
new_issue = move_service.execute(old_issue, new_project)
|
|
|
|
|
|
|
|
expect(new_issue.resource_milestone_events.count).to eq(old_issue.resource_milestone_events.count)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'issue with due date' do
|
|
|
|
let(:old_issue) do
|
|
|
|
create(:issue, title: title, description: description, project: old_project, author: author, due_date: '2020-01-10')
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
SystemNoteService.change_due_date(old_issue, old_project, author, old_issue.due_date)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create extra system notes' do
|
|
|
|
new_issue = move_service.execute(old_issue, new_project)
|
|
|
|
|
|
|
|
expect(new_issue.notes.count).to eq(old_issue.notes.count)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-29 05:05:47 -04:00
|
|
|
context 'issue with assignee' do
|
2020-08-11 11:10:08 -04:00
|
|
|
let_it_be(: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
|
|
|
|
2022-02-09 07:12:04 -05:00
|
|
|
context 'issue with contacts' do
|
|
|
|
let_it_be(:contacts) { create_list(:contact, 2, group: group) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
old_issue.customer_relations_contacts = contacts
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'preserves contacts' do
|
|
|
|
new_issue = move_service.execute(old_issue, new_project)
|
|
|
|
|
|
|
|
expect(new_issue.customer_relations_contacts).to eq(contacts)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when moving to another root group' do
|
|
|
|
let(:another_project) { create(:project, namespace: create(:group)) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
another_project.add_reporter(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not preserve contacts' do
|
|
|
|
new_issue = move_service.execute(old_issue, another_project)
|
|
|
|
|
|
|
|
expect(new_issue.customer_relations_contacts).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
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
|
2019-12-16 07:07:43 -05:00
|
|
|
allow_next_instance_of(WebHookService) do |instance|
|
|
|
|
allow(instance).to receive(:execute)
|
|
|
|
end
|
2018-01-24 09:09:59 -05:00
|
|
|
|
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
|
2020-08-11 11:10:08 -04:00
|
|
|
|
|
|
|
# These tests verify that notes are copied. More thorough tests are in
|
|
|
|
# the unit test for Notes::CopyService.
|
|
|
|
context 'issue with notes' do
|
|
|
|
let!(:notes) do
|
|
|
|
[
|
|
|
|
create(:note, noteable: old_issue, project: old_project, created_at: 2.weeks.ago, updated_at: 1.week.ago),
|
|
|
|
create(:note, noteable: old_issue, project: old_project)
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:copied_notes) { new_issue.notes.limit(notes.size) } # Remove the system note added by the copy itself
|
|
|
|
|
|
|
|
include_context 'issue move executed'
|
|
|
|
|
|
|
|
it 'copies existing notes in order' do
|
|
|
|
expect(copied_notes.order('id ASC').pluck(:note)).to eq(notes.map(&:note))
|
|
|
|
end
|
|
|
|
end
|
2020-09-28 20:09:59 -04:00
|
|
|
|
|
|
|
context 'issue with a design', :clean_gitlab_redis_shared_state do
|
2020-10-12 14:08:31 -04:00
|
|
|
let_it_be(:new_project) { create(:project) }
|
2021-04-12 08:09:15 -04:00
|
|
|
|
2020-09-28 20:09:59 -04:00
|
|
|
let!(:design) { create(:design, :with_lfs_file, issue: old_issue) }
|
|
|
|
let!(:note) { create(:diff_note_on_design, noteable: design, issue: old_issue, project: old_issue.project) }
|
|
|
|
let(:subject) { move_service.execute(old_issue, new_project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
enable_design_management
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'calls CopyDesignCollection::QueueService' do
|
|
|
|
expect(DesignManagement::CopyDesignCollection::QueueService).to receive(:new)
|
|
|
|
.with(user, old_issue, kind_of(Issue))
|
|
|
|
.and_call_original
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'logs if QueueService returns an error', :aggregate_failures do
|
|
|
|
error_message = 'error'
|
|
|
|
|
|
|
|
expect_next_instance_of(DesignManagement::CopyDesignCollection::QueueService) do |service|
|
|
|
|
expect(service).to receive(:execute).and_return(
|
|
|
|
ServiceResponse.error(message: error_message)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
expect(Gitlab::AppLogger).to receive(:error).with(error_message)
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
# Perform a small integration test to ensure the services and worker
|
|
|
|
# can correctly create designs.
|
|
|
|
it 'copies the design and its notes', :sidekiq_inline, :aggregate_failures do
|
|
|
|
new_issue = subject
|
|
|
|
|
|
|
|
expect(new_issue.designs.size).to eq(1)
|
|
|
|
expect(new_issue.designs.first.notes.size).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
2021-03-04 07:11:11 -05:00
|
|
|
|
|
|
|
context 'issue relative position' do
|
|
|
|
let(:subject) { move_service.execute(old_issue, new_project) }
|
|
|
|
|
|
|
|
it_behaves_like 'copy or reset relative position'
|
|
|
|
end
|
2022-01-12 22:13:43 -05:00
|
|
|
|
|
|
|
context 'issue with escalation status' do
|
|
|
|
it 'keeps the escalation status' do
|
|
|
|
escalation_status = create(:incident_management_issuable_escalation_status, issue: old_issue)
|
|
|
|
|
|
|
|
move_service.execute(old_issue, new_project)
|
|
|
|
|
|
|
|
expect(escalation_status.reload.issue).to eq(old_issue)
|
|
|
|
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) }
|
2019-12-12 07:07:33 -05:00
|
|
|
|
2016-03-23 04:39:37 -04:00
|
|
|
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
|
2020-07-13 14:09:16 -04:00
|
|
|
|
2020-08-20 20:10:44 -04:00
|
|
|
describe '#rewrite_related_issues' do
|
|
|
|
include_context 'user can move issue'
|
|
|
|
|
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
let(:authorized_project) { create(:project) }
|
|
|
|
let(:authorized_project2) { create(:project) }
|
|
|
|
let(:unauthorized_project) { create(:project) }
|
|
|
|
|
|
|
|
let(:authorized_issue_b) { create(:issue, project: authorized_project) }
|
|
|
|
let(:authorized_issue_c) { create(:issue, project: authorized_project2) }
|
|
|
|
let(:authorized_issue_d) { create(:issue, project: authorized_project2) }
|
|
|
|
let(:unauthorized_issue) { create(:issue, project: unauthorized_project) }
|
|
|
|
|
|
|
|
let!(:issue_link_a) { create(:issue_link, source: old_issue, target: authorized_issue_b) }
|
|
|
|
let!(:issue_link_b) { create(:issue_link, source: old_issue, target: unauthorized_issue) }
|
|
|
|
let!(:issue_link_c) { create(:issue_link, source: old_issue, target: authorized_issue_c) }
|
|
|
|
let!(:issue_link_d) { create(:issue_link, source: authorized_issue_d, target: old_issue) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
authorized_project.add_developer(user)
|
2020-11-11 07:09:06 -05:00
|
|
|
authorized_project.add_developer(admin)
|
2020-08-20 20:10:44 -04:00
|
|
|
authorized_project2.add_developer(user)
|
2020-11-11 07:09:06 -05:00
|
|
|
authorized_project2.add_developer(admin)
|
2020-08-20 20:10:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'multiple related issues' do
|
2020-11-11 07:09:06 -05:00
|
|
|
context 'when admin mode is enabled', :enable_admin_mode do
|
|
|
|
it 'moves all related issues and retains permissions' do
|
|
|
|
new_issue = move_service.execute(old_issue, new_project)
|
|
|
|
|
|
|
|
expect(new_issue.related_issues(admin))
|
|
|
|
.to match_array([authorized_issue_b, authorized_issue_c, authorized_issue_d, unauthorized_issue])
|
|
|
|
|
|
|
|
expect(new_issue.related_issues(user))
|
|
|
|
.to match_array([authorized_issue_b, authorized_issue_c, authorized_issue_d])
|
|
|
|
|
|
|
|
expect(authorized_issue_d.related_issues(user))
|
|
|
|
.to match_array([new_issue])
|
|
|
|
end
|
|
|
|
end
|
2020-08-20 20:10:44 -04:00
|
|
|
|
2020-11-11 07:09:06 -05:00
|
|
|
context 'when admin mode is disabled' do
|
|
|
|
it 'moves all related issues and retains permissions' do
|
|
|
|
new_issue = move_service.execute(old_issue, new_project)
|
2020-08-20 20:10:44 -04:00
|
|
|
|
2020-11-11 07:09:06 -05:00
|
|
|
expect(new_issue.related_issues(admin))
|
|
|
|
.to match_array([authorized_issue_b, authorized_issue_c, authorized_issue_d])
|
2020-08-20 20:10:44 -04:00
|
|
|
|
2020-11-11 07:09:06 -05:00
|
|
|
expect(new_issue.related_issues(user))
|
|
|
|
.to match_array([authorized_issue_b, authorized_issue_c, authorized_issue_d])
|
|
|
|
|
|
|
|
expect(authorized_issue_d.related_issues(user))
|
|
|
|
.to match_array([new_issue])
|
|
|
|
end
|
2020-08-20 20:10:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-13 14:09:16 -04:00
|
|
|
context 'updating sent notifications' do
|
|
|
|
let!(:old_issue_notification_1) { create(:sent_notification, project: old_issue.project, noteable: old_issue) }
|
|
|
|
let!(:old_issue_notification_2) { create(:sent_notification, project: old_issue.project, noteable: old_issue) }
|
|
|
|
let!(:other_issue_notification) { create(:sent_notification, project: old_issue.project) }
|
|
|
|
|
|
|
|
include_context 'user can move issue'
|
|
|
|
|
|
|
|
context 'when issue is from service desk' do
|
|
|
|
before do
|
|
|
|
allow(old_issue).to receive(:from_service_desk?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates moved issue sent notifications' do
|
|
|
|
new_issue = move_service.execute(old_issue, new_project)
|
|
|
|
|
|
|
|
old_issue_notification_1.reload
|
|
|
|
old_issue_notification_2.reload
|
|
|
|
expect(old_issue_notification_1.project_id).to eq(new_issue.project_id)
|
|
|
|
expect(old_issue_notification_1.noteable_id).to eq(new_issue.id)
|
|
|
|
expect(old_issue_notification_2.project_id).to eq(new_issue.project_id)
|
|
|
|
expect(old_issue_notification_2.noteable_id).to eq(new_issue.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not update other issues sent notifications' do
|
|
|
|
expect do
|
|
|
|
move_service.execute(old_issue, new_project)
|
|
|
|
other_issue_notification.reload
|
|
|
|
end.not_to change { other_issue_notification.noteable_id }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when issue is not from service desk' do
|
|
|
|
it 'does not update sent notifications' do
|
|
|
|
move_service.execute(old_issue, new_project)
|
|
|
|
|
|
|
|
old_issue_notification_1.reload
|
|
|
|
old_issue_notification_2.reload
|
|
|
|
expect(old_issue_notification_1.project_id).to eq(old_issue.project_id)
|
|
|
|
expect(old_issue_notification_1.noteable_id).to eq(old_issue.id)
|
|
|
|
expect(old_issue_notification_2.project_id).to eq(old_issue.project_id)
|
|
|
|
expect(old_issue_notification_2.noteable_id).to eq(old_issue.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-02-15 08:41:40 -05:00
|
|
|
end
|