summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2017-07-20 15:42:33 +0100
committerSean McGivern <sean@gitlab.com>2017-07-21 12:53:56 +0100
commit1df696f5a6836e03a6bf8d5139c2c7ce6d96e727 (patch)
treeecd7c4c0ad0d3233884617d1db3afacb776ad66d /spec
parent3498e825d08adb0311d0431d9d15e450f95bfc86 (diff)
downloadgitlab-ce-1df696f5a6836e03a6bf8d5139c2c7ce6d96e727.tar.gz
Move duplicate issue management to a servicearchytaus/gitlab-ce-26372-duplicate-issue-slash-command
Diffstat (limited to 'spec')
-rw-r--r--spec/services/issues/duplicate_service_spec.rb80
-rw-r--r--spec/services/issues/update_service_spec.rb41
-rw-r--r--spec/services/quick_actions/interpret_service_spec.rb11
-rw-r--r--spec/services/system_note_service_spec.rb35
4 files changed, 123 insertions, 44 deletions
diff --git a/spec/services/issues/duplicate_service_spec.rb b/spec/services/issues/duplicate_service_spec.rb
new file mode 100644
index 00000000000..82daf53b173
--- /dev/null
+++ b/spec/services/issues/duplicate_service_spec.rb
@@ -0,0 +1,80 @@
+require 'spec_helper'
+
+describe Issues::DuplicateService, services: true do
+ let(:user) { create(:user) }
+ let(:canonical_project) { create(:empty_project) }
+ let(:duplicate_project) { create(:empty_project) }
+
+ let(:canonical_issue) { create(:issue, project: canonical_project) }
+ let(:duplicate_issue) { create(:issue, project: duplicate_project) }
+
+ subject { described_class.new(duplicate_project, user, {}) }
+
+ describe '#execute' do
+ context 'when the issues passed are the same' do
+ it 'does nothing' do
+ expect(subject).not_to receive(:close_service)
+ expect(SystemNoteService).not_to receive(:mark_duplicate_issue)
+ expect(SystemNoteService).not_to receive(:mark_canonical_issue_of_duplicate)
+
+ subject.execute(duplicate_issue, duplicate_issue)
+ end
+ end
+
+ context 'when the user cannot update the duplicate issue' do
+ before do
+ canonical_project.add_reporter(user)
+ end
+
+ it 'does nothing' do
+ expect(subject).not_to receive(:close_service)
+ expect(SystemNoteService).not_to receive(:mark_duplicate_issue)
+ expect(SystemNoteService).not_to receive(:mark_canonical_issue_of_duplicate)
+
+ subject.execute(duplicate_issue, canonical_issue)
+ end
+ end
+
+ context 'when the user cannot comment on the canonical issue' do
+ before do
+ duplicate_project.add_reporter(user)
+ end
+
+ it 'does nothing' do
+ expect(subject).not_to receive(:close_service)
+ expect(SystemNoteService).not_to receive(:mark_duplicate_issue)
+ expect(SystemNoteService).not_to receive(:mark_canonical_issue_of_duplicate)
+
+ subject.execute(duplicate_issue, canonical_issue)
+ end
+ end
+
+ context 'when the user can mark the issue as a duplicate' do
+ before do
+ canonical_project.add_reporter(user)
+ duplicate_project.add_reporter(user)
+ end
+
+ it 'closes the duplicate issue' do
+ subject.execute(duplicate_issue, canonical_issue)
+
+ expect(duplicate_issue.reload).to be_closed
+ expect(canonical_issue.reload).to be_open
+ end
+
+ it 'adds a system note to the duplicate issue' do
+ expect(SystemNoteService)
+ .to receive(:mark_duplicate_issue).with(duplicate_issue, duplicate_project, user, canonical_issue)
+
+ subject.execute(duplicate_issue, canonical_issue)
+ end
+
+ it 'adds a system note to the canonical issue' do
+ expect(SystemNoteService)
+ .to receive(:mark_canonical_issue_of_duplicate).with(canonical_issue, canonical_project, user, duplicate_issue)
+
+ subject.execute(duplicate_issue, canonical_issue)
+ end
+ end
+ end
+end
diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb
index e7f3ab93395..064be940a1c 100644
--- a/spec/services/issues/update_service_spec.rb
+++ b/spec/services/issues/update_service_spec.rb
@@ -492,43 +492,22 @@ describe Issues::UpdateService, services: true do
end
context 'duplicate issue' do
- let(:original_issue) { create(:issue, project: project) }
+ let(:canonical_issue) { create(:issue, project: project) }
- context 'invalid original_issue_id' do
- before do
- update_issue(original_issue_id: 123456789)
- end
-
- it 'does not close the issue' do
- expect(issue.reload).not_to be_closed
- end
+ context 'invalid canonical_issue_id' do
+ it 'does not call the duplicate service' do
+ expect(Issues::DuplicateService).not_to receive(:new)
- it 'does not create a system note' do
- note = find_note("marked this issue as a duplicate of #{original_issue.to_reference}")
- expect(note).to be_nil
- end
-
- it 'does not upvote the issue on behalf of the author' do
- expect(original_issue).not_to be_awarded_emoji(AwardEmoji::UPVOTE_NAME, issue.author)
+ update_issue(canonical_issue_id: 123456789)
end
end
- context 'valid original_issue_id' do
- before do
- update_issue(original_issue_id: original_issue.id)
- end
-
- it 'closes the issue' do
- expect(issue.reload).to be_closed
- end
-
- it 'creates a system note that this issue is a duplicate' do
- note = find_note("marked this issue as a duplicate of #{original_issue.to_reference}")
- expect(note).not_to be_nil
- end
+ context 'valid canonical_issue_id' do
+ it 'calls the duplicate service with both issues' do
+ expect_any_instance_of(Issues::DuplicateService)
+ .to receive(:execute).with(issue, canonical_issue)
- it 'upvotes the issue on behalf of the author' do
- expect(original_issue).to be_awarded_emoji(AwardEmoji::UPVOTE_NAME, issue.author)
+ update_issue(canonical_issue_id: canonical_issue.id)
end
end
end
diff --git a/spec/services/quick_actions/interpret_service_spec.rb b/spec/services/quick_actions/interpret_service_spec.rb
index 1d60b74e566..2a2a5c38e4b 100644
--- a/spec/services/quick_actions/interpret_service_spec.rb
+++ b/spec/services/quick_actions/interpret_service_spec.rb
@@ -262,11 +262,11 @@ describe QuickActions::InterpretService, services: true do
end
shared_examples 'duplicate command' do
- it 'fetches issue and populates original_issue_id if content contains /duplicate issue_reference' do
+ it 'fetches issue and populates canonical_issue_id if content contains /duplicate issue_reference' do
issue_duplicate # populate the issue
_, updates = service.execute(content, issuable)
- expect(updates).to eq(original_issue_id: issue_duplicate.id)
+ expect(updates).to eq(canonical_issue_id: issue_duplicate.id)
end
end
@@ -661,11 +661,6 @@ describe QuickActions::InterpretService, services: true do
end
it_behaves_like 'empty command' do
- let(:content) { "/duplicate #{issue.to_reference}" }
- let(:issuable) { issue }
- end
-
- it_behaves_like 'empty command' do
let(:content) { '/duplicate' }
let(:issuable) { issue }
end
@@ -679,7 +674,7 @@ describe QuickActions::InterpretService, services: true do
end
it_behaves_like 'empty command' do
- let(:content) { '/duplicate imaginary#1234' }
+ let(:content) { "/duplicate imaginary#1234" }
let(:issuable) { issue }
end
diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb
index db120889119..681b419aedf 100644
--- a/spec/services/system_note_service_spec.rb
+++ b/spec/services/system_note_service_spec.rb
@@ -1103,27 +1103,52 @@ describe SystemNoteService, services: true do
end
describe '.mark_duplicate_issue' do
- subject { described_class.mark_duplicate_issue(noteable, project, author, original_issue) }
+ subject { described_class.mark_duplicate_issue(noteable, project, author, canonical_issue) }
context 'within the same project' do
- let(:original_issue) { create(:issue, project: project) }
+ let(:canonical_issue) { create(:issue, project: project) }
it_behaves_like 'a system note' do
let(:action) { 'duplicate' }
end
- it { expect(subject.note).to eq "marked this issue as a duplicate of #{original_issue.to_reference}" }
+ it { expect(subject.note).to eq "marked this issue as a duplicate of #{canonical_issue.to_reference}" }
end
context 'across different projects' do
let(:other_project) { create(:empty_project) }
- let(:original_issue) { create(:issue, project: other_project) }
+ let(:canonical_issue) { create(:issue, project: other_project) }
it_behaves_like 'a system note' do
let(:action) { 'duplicate' }
end
- it { expect(subject.note).to eq "marked this issue as a duplicate of #{original_issue.to_reference(project)}" }
+ it { expect(subject.note).to eq "marked this issue as a duplicate of #{canonical_issue.to_reference(project)}" }
+ end
+ end
+
+ describe '.mark_canonical_issue_of_duplicate' do
+ subject { described_class.mark_canonical_issue_of_duplicate(noteable, project, author, duplicate_issue) }
+
+ context 'within the same project' do
+ let(:duplicate_issue) { create(:issue, project: project) }
+
+ it_behaves_like 'a system note' do
+ let(:action) { 'duplicate' }
+ end
+
+ it { expect(subject.note).to eq "marked #{duplicate_issue.to_reference} as a duplicate of this issue" }
+ end
+
+ context 'across different projects' do
+ let(:other_project) { create(:empty_project) }
+ let(:duplicate_issue) { create(:issue, project: other_project) }
+
+ it_behaves_like 'a system note' do
+ let(:action) { 'duplicate' }
+ end
+
+ it { expect(subject.note).to eq "marked #{duplicate_issue.to_reference(project)} as a duplicate of this issue" }
end
end
end