diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-03-06 19:07:09 +0300 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-03-06 19:07:09 +0300 |
commit | eb7b03af2c8fe759c6e1e94222a19413ff5f21bf (patch) | |
tree | 3bc9462b9e5dd7521d8515f7bcef7dd78d851657 | |
parent | 5fce538b076f0fb48aa3b3c77ea0914a00c964fb (diff) | |
parent | 5ce3845f17c2c6e168cf2bd1b3c5093f10db1953 (diff) |
Merge branch 'fix-mentioned-issues-for-external-trackers' into 'master'
Fix issues mentioned but not closed for JIRA
Closes #26028
See merge request !9687
-rw-r--r-- | app/models/external_issue.rb | 5 | ||||
-rw-r--r-- | changelogs/unreleased/fix-mentioned-issues-for-external-trackers.yml | 4 | ||||
-rw-r--r-- | spec/factories/projects.rb | 23 | ||||
-rw-r--r-- | spec/factories/services.rb | 9 | ||||
-rw-r--r-- | spec/models/external_issue_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/merge_request_spec.rb | 17 |
6 files changed, 45 insertions, 21 deletions
diff --git a/app/models/external_issue.rb b/app/models/external_issue.rb index b973bbcd8da..e63f89a9f85 100644 --- a/app/models/external_issue.rb +++ b/app/models/external_issue.rb @@ -24,6 +24,11 @@ class ExternalIssue def ==(other) other.is_a?(self.class) && (to_s == other.to_s) end + alias_method :eql?, :== + + def hash + [self.class, to_s].hash + end def project @project diff --git a/changelogs/unreleased/fix-mentioned-issues-for-external-trackers.yml b/changelogs/unreleased/fix-mentioned-issues-for-external-trackers.yml new file mode 100644 index 00000000000..ee827b7c939 --- /dev/null +++ b/changelogs/unreleased/fix-mentioned-issues-for-external-trackers.yml @@ -0,0 +1,4 @@ +--- +title: Fix issues mentioned but not closed for external issue trackers +merge_request: +author: diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb index 04de3512125..70c65bc693a 100644 --- a/spec/factories/projects.rb +++ b/spec/factories/projects.rb @@ -189,29 +189,10 @@ FactoryGirl.define do factory :jira_project, parent: :project do has_external_issue_tracker true - - after :create do |project| - project.create_jira_service( - active: true, - properties: { - title: 'JIRA tracker', - url: 'http://jira.example.net', - project_key: 'JIRA' - } - ) - end + jira_service end factory :kubernetes_project, parent: :empty_project do - after :create do |project| - project.create_kubernetes_service( - active: true, - properties: { - namespace: project.path, - api_url: 'https://kubernetes.example.com', - token: 'a' * 40, - } - ) - end + kubernetes_service end end diff --git a/spec/factories/services.rb b/spec/factories/services.rb index 51335bdcf1d..88f6c265505 100644 --- a/spec/factories/services.rb +++ b/spec/factories/services.rb @@ -12,4 +12,13 @@ FactoryGirl.define do token: 'a' * 40, }) end + + factory :jira_service do + project factory: :empty_project + active true + properties( + url: 'https://jira.example.com', + project_key: 'jira-key' + ) + end end diff --git a/spec/models/external_issue_spec.rb b/spec/models/external_issue_spec.rb index 2debe1289a3..cd50bda8996 100644 --- a/spec/models/external_issue_spec.rb +++ b/spec/models/external_issue_spec.rb @@ -42,4 +42,12 @@ describe ExternalIssue, models: true do expect(issue.project_id).to eq(project.id) end end + + describe '#hash' do + it 'returns the hash of its [class, to_s] pair' do + issue_2 = described_class.new(issue.to_s, project) + + expect(issue.hash).to eq(issue_2.hash) + end + end end diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index e000d0d38b3..fcaf4c71182 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -346,6 +346,23 @@ describe MergeRequest, models: true do expect(subject.issues_mentioned_but_not_closing(subject.author)).to match_array([mentioned_issue]) end + + context 'when the project has an external issue tracker' do + before do + subject.project.team << [subject.author, :developer] + commit = double(:commit, safe_message: 'Fixes TEST-3') + + create(:jira_service, project: subject.project) + + allow(subject).to receive(:commits).and_return([commit]) + allow(subject).to receive(:description).and_return('Is related to TEST-2 and TEST-3') + allow(subject.project).to receive(:default_branch).and_return(subject.target_branch) + end + + it 'detects issues mentioned in description but not closed' do + expect(subject.issues_mentioned_but_not_closing(subject.author).map(&:to_s)).to match_array(['TEST-2']) + end + end end describe "#work_in_progress?" do |