summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorjubianchi <contact@jubianchi.fr>2014-09-17 19:08:35 +0200
committerjubianchi <contact@jubianchi.fr>2015-01-20 10:45:48 +0100
commitb21a2d821a4e16aba1609dfa1e01ba455e8ccd8f (patch)
treebc17b71af51eebc70df294422bc7acebf5e30506 /spec
parent0af2a161fa55a4abd7f8248b25a7361b209ecc4a (diff)
downloadgitlab-ce-b21a2d821a4e16aba1609dfa1e01ba455e8ccd8f.tar.gz
Allow commit messages to close several issues at once (thanks @123Haynes
for his work and help)
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/closing_issue_extractor_spec.rb84
-rw-r--r--spec/models/commit_spec.rb4
2 files changed, 84 insertions, 4 deletions
diff --git a/spec/lib/gitlab/closing_issue_extractor_spec.rb b/spec/lib/gitlab/closing_issue_extractor_spec.rb
new file mode 100644
index 00000000000..867455daf23
--- /dev/null
+++ b/spec/lib/gitlab/closing_issue_extractor_spec.rb
@@ -0,0 +1,84 @@
+require 'spec_helper'
+
+describe Gitlab::ClosingIssueExtractor do
+ let(:project) { create(:project) }
+ let(:issue) { create(:issue, project: project) }
+ let(:iid1) { issue.iid }
+
+ describe :closed_by_message_in_project do
+ context 'with a single reference' do
+ it do
+ message = "Awesome commit (Closes ##{iid1})"
+ subject.closed_by_message_in_project(message, project).should == [issue]
+ end
+
+ it do
+ message = "Awesome commit (closes ##{iid1})"
+ subject.closed_by_message_in_project(message, project).should == [issue]
+ end
+
+ it do
+ message = "Closed ##{iid1}"
+ subject.closed_by_message_in_project(message, project).should == [issue]
+ end
+
+ it do
+ message = "closed ##{iid1}"
+ subject.closed_by_message_in_project(message, project).should == [issue]
+ end
+
+ it do
+ message = "Awesome commit (fixes ##{iid1})"
+ subject.closed_by_message_in_project(message, project).should == [issue]
+ end
+
+ it do
+ message = "Awesome commit (fix ##{iid1})"
+ subject.closed_by_message_in_project(message, project).should == [issue]
+ end
+ end
+
+ context 'with multiple references' do
+ let(:other_issue) { create(:issue, project: project) }
+ let(:third_issue) { create(:issue, project: project) }
+ let(:iid2) { other_issue.iid }
+ let(:iid3) { third_issue.iid }
+
+ it 'fetches issues in single line message' do
+ message = "Closes ##{iid1} and fix ##{iid2}"
+
+ subject.closed_by_message_in_project(message, project).
+ should == [issue, other_issue]
+ end
+
+ it 'fetches comma-separated issues references in single line message' do
+ message = "Closes ##{iid1}, closes ##{iid2}"
+
+ subject.closed_by_message_in_project(message, project).
+ should == [issue, other_issue]
+ end
+
+ it 'fetches comma-separated issues numbers in single line message' do
+ message = "Closes ##{iid1}, ##{iid2} and ##{iid3}"
+
+ subject.closed_by_message_in_project(message, project).
+ should == [issue, other_issue, third_issue]
+ end
+
+ it 'fetches issues in multi-line message' do
+ message = "Awesome commit (closes ##{iid1})\nAlso fixes ##{iid2}"
+
+ subject.closed_by_message_in_project(message, project).
+ should == [issue, other_issue]
+ end
+
+ it 'fetches issues in hybrid message' do
+ message = "Awesome commit (closes ##{iid1})\n"\
+ "Also fixing issues ##{iid2}, ##{iid3} and #4"
+
+ subject.closed_by_message_in_project(message, project).
+ should == [issue, other_issue, third_issue]
+ end
+ end
+ end
+end
diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb
index a6ec44da4be..7a2a7a4ce9b 100644
--- a/spec/models/commit_spec.rb
+++ b/spec/models/commit_spec.rb
@@ -57,16 +57,12 @@ eos
let(:other_issue) { create :issue, project: other_project }
it 'detects issues that this commit is marked as closing' do
- stub_const('Gitlab::ClosingIssueExtractor::ISSUE_CLOSING_REGEX',
- /Fixes #\d+/)
commit.stub(safe_message: "Fixes ##{issue.iid}")
commit.closes_issues(project).should == [issue]
end
it 'does not detect issues from other projects' do
ext_ref = "#{other_project.path_with_namespace}##{other_issue.iid}"
- stub_const('Gitlab::ClosingIssueExtractor::ISSUE_CLOSING_REGEX',
- /^([Cc]loses|[Ff]ixes)/)
commit.stub(safe_message: "Fixes #{ext_ref}")
commit.closes_issues(project).should be_empty
end