Commit 1540a877 authored by Sean McGivern's avatar Sean McGivern

Merge branch '36443-do-not-create-notes-if-issue-was-not-successfully-related' into 'master'

Create system notes only if issue was successfully related to another

Closes gitlab-ce#36443

See merge request !2684
parents fe907d77 adc70d57
...@@ -21,8 +21,9 @@ module IssueLinks ...@@ -21,8 +21,9 @@ module IssueLinks
end end
end end
# Returns a Boolean indicating if the Issue was related.
def relate_issues(referenced_issue) def relate_issues(referenced_issue)
IssueLink.create(source: @issue, target: referenced_issue) IssueLink.new(source: @issue, target: referenced_issue).save
end end
def create_notes(referenced_issue) def create_notes(referenced_issue)
......
---
title: Create system notes only if issue was successfully related
merge_request:
author:
type: fixed
...@@ -60,6 +60,22 @@ describe IssueLinks::CreateService do ...@@ -60,6 +60,22 @@ describe IssueLinks::CreateService do
end end
end end
context 'source and target are the same issue' do
let(:params) do
{ issue_references: [issue.to_reference] }
end
it 'does not create notes' do
expect(SystemNoteService).not_to receive(:relate_issue)
subject
end
it 'no relationship is created' do
expect { subject }.not_to change(IssueLink, :count)
end
end
context 'when there is an issue to relate' do context 'when there is an issue to relate' do
let(:issue_a) { create :issue, project: project } let(:issue_a) { create :issue, project: project }
let(:another_project) { create :project, namespace: project.namespace } let(:another_project) { create :project, namespace: project.namespace }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment