gitlab-org--gitlab-foss/spec/lib/gitlab/closing_issue_extractor_spec.rb

369 lines
11 KiB
Ruby
Raw Normal View History

require 'spec_helper'
2015-12-09 05:55:36 -05:00
describe Gitlab::ClosingIssueExtractor, lib: true do
let(:project) { create(:empty_project) }
let(:project2) { create(:empty_project) }
let(:forked_project) { Projects::ForkService.new(project, project.creator).execute }
let(:issue) { create(:issue, project: project) }
let(:issue2) { create(:issue, project: project2) }
2015-05-21 16:35:15 -04:00
let(:reference) { issue.to_reference }
2015-12-02 12:48:39 -05:00
let(:cross_reference) { issue2.to_reference(project) }
let(:fork_cross_reference) { issue.to_reference(forked_project) }
2015-04-03 12:03:34 -04:00
subject { described_class.new(project, project.creator) }
2015-12-02 12:48:39 -05:00
before do
project.team << [project.creator, :developer]
2015-12-02 12:48:39 -05:00
project2.team << [project.creator, :master]
end
2015-04-03 12:03:34 -04:00
describe "#closed_by_message" do
context 'with a single reference' do
it do
2015-05-21 16:35:15 -04:00
message = "Awesome commit (Closes #{reference})"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Awesome commit (Closes: #{reference})"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
2015-05-21 16:35:15 -04:00
message = "Awesome commit (closes #{reference})"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Awesome commit (closes: #{reference})"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
2015-05-21 16:35:15 -04:00
message = "Closed #{reference}"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
2015-05-21 16:35:15 -04:00
message = "closed #{reference}"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "closed: #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
2015-02-05 16:04:49 -05:00
it do
2015-05-21 16:35:15 -04:00
message = "Closing #{reference}"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
2015-02-05 16:04:49 -05:00
end
it do
message = "Closing: #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
2015-02-05 16:04:49 -05:00
it do
2015-05-21 16:35:15 -04:00
message = "closing #{reference}"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
2015-02-05 16:04:49 -05:00
end
it do
message = "closing: #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
2015-02-05 16:04:49 -05:00
it do
2015-05-21 16:35:15 -04:00
message = "Close #{reference}"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
2015-02-05 16:04:49 -05:00
end
it do
message = "Close: #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
2015-02-05 16:04:49 -05:00
it do
2015-05-21 16:35:15 -04:00
message = "close #{reference}"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
2015-02-05 16:04:49 -05:00
end
it do
message = "close: #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
2015-02-05 16:04:49 -05:00
it do
2015-05-21 16:35:15 -04:00
message = "Awesome commit (Fixes #{reference})"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
2015-02-05 16:04:49 -05:00
end
it do
message = "Awesome commit (Fixes: #{reference})"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
2015-05-21 16:35:15 -04:00
message = "Awesome commit (fixes #{reference})"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Awesome commit (Fixes: #{reference})"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
2015-05-21 16:35:15 -04:00
message = "Fixed #{reference}"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
2015-02-05 16:04:49 -05:00
end
it do
message = "Fixed: #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
2015-02-05 16:04:49 -05:00
it do
2015-05-21 16:35:15 -04:00
message = "fixed #{reference}"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
2015-02-05 16:04:49 -05:00
end
it do
message = "fixed: #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
2015-02-05 16:04:49 -05:00
it do
2015-05-21 16:35:15 -04:00
message = "Fixing #{reference}"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
2015-02-05 16:04:49 -05:00
end
it do
message = "Fixing: #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
2015-02-05 16:04:49 -05:00
it do
2015-05-21 16:35:15 -04:00
message = "fixing #{reference}"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
2015-02-05 16:04:49 -05:00
end
it do
message = "fixing: #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
2015-02-05 16:04:49 -05:00
it do
2015-05-21 16:35:15 -04:00
message = "Fix #{reference}"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
2015-02-05 16:04:49 -05:00
end
it do
message = "Fix: #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
2015-02-05 16:04:49 -05:00
it do
2015-05-21 16:35:15 -04:00
message = "fix #{reference}"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
2015-02-05 16:04:49 -05:00
end
it do
message = "fix: #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
2015-02-05 16:04:49 -05:00
it do
2015-05-21 16:35:15 -04:00
message = "Awesome commit (Resolves #{reference})"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
2015-02-05 16:04:49 -05:00
end
it do
message = "Awesome commit (Resolves: #{reference})"
expect(subject.closed_by_message(message)).to eq([issue])
end
2015-02-05 16:04:49 -05:00
it do
2015-05-21 16:35:15 -04:00
message = "Awesome commit (resolves #{reference})"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
2015-02-05 16:04:49 -05:00
end
it do
message = "Awesome commit (resolves: #{reference})"
expect(subject.closed_by_message(message)).to eq([issue])
end
2015-02-05 16:04:49 -05:00
it do
2015-05-21 16:35:15 -04:00
message = "Resolved #{reference}"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
2015-02-05 16:04:49 -05:00
end
it do
message = "Resolved: #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
2015-02-05 16:04:49 -05:00
it do
2015-05-21 16:35:15 -04:00
message = "resolved #{reference}"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
2015-02-05 16:04:49 -05:00
end
it do
message = "resolved: #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
2015-02-05 16:04:49 -05:00
it do
2015-05-21 16:35:15 -04:00
message = "Resolving #{reference}"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
2015-02-05 16:04:49 -05:00
end
it do
message = "Resolving: #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
2015-02-05 16:04:49 -05:00
it do
2015-05-21 16:35:15 -04:00
message = "resolving #{reference}"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
2015-02-05 16:04:49 -05:00
end
it do
message = "resolving: #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
2015-02-05 16:04:49 -05:00
it do
2015-05-21 16:35:15 -04:00
message = "Resolve #{reference}"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
2015-02-05 16:04:49 -05:00
end
it do
message = "Resolve: #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
2015-02-05 16:04:49 -05:00
it do
2015-05-21 16:35:15 -04:00
message = "resolve #{reference}"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "resolve: #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
context 'with an external issue tracker reference' do
it 'extracts the referenced issue' do
jira_project = create(:jira_project, name: 'JIRA_EXT1')
jira_project.team << [jira_project.creator, :master]
jira_issue = ExternalIssue.new("#{jira_project.name}-1", project: jira_project)
closing_issue_extractor = described_class.new(jira_project, jira_project.creator)
message = "Resolve #{jira_issue.to_reference}"
expect(closing_issue_extractor.closed_by_message(message)).to eq([jira_issue])
end
end
end
2015-12-02 12:48:39 -05:00
context "with a cross-project reference" do
it do
message = "Closes #{cross_reference}"
expect(subject.closed_by_message(message)).to eq([issue2])
end
end
context "with a cross-project URL" do
it do
2015-12-03 08:00:00 -05:00
message = "Closes #{urls.namespace_project_issue_url(issue2.project.namespace, issue2.project, issue2)}"
2015-12-02 12:48:39 -05:00
expect(subject.closed_by_message(message)).to eq([issue2])
end
end
context "with a cross-project fork reference" do
subject { described_class.new(forked_project, forked_project.creator) }
it do
message = "Closes #{fork_cross_reference}"
expect(subject.closed_by_message(message)).to be_empty
end
end
2015-12-02 12:48:39 -05:00
context "with an invalid URL" do
it do
2015-12-03 08:00:00 -05:00
message = "Closes https://google.com#{urls.namespace_project_issue_path(issue2.project.namespace, issue2.project, issue2)}"
2015-12-02 12:48:39 -05:00
expect(subject.closed_by_message(message)).to eq([])
end
end
context 'with multiple references' do
let(:other_issue) { create(:issue, project: project) }
let(:third_issue) { create(:issue, project: project) }
2015-05-21 16:35:15 -04:00
let(:reference2) { other_issue.to_reference }
let(:reference3) { third_issue.to_reference }
it 'fetches issues in single line message' do
2015-05-26 15:55:26 -04:00
message = "Closes #{reference} and fix #{reference2}"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).
2015-10-14 07:46:17 -04:00
to match_array([issue, other_issue])
end
it 'fetches comma-separated issues references in single line message' do
2015-05-26 15:55:26 -04:00
message = "Closes #{reference}, closes #{reference2}"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).
2015-10-14 07:46:17 -04:00
to match_array([issue, other_issue])
end
it 'fetches comma-separated issues numbers in single line message' do
2015-05-26 15:55:26 -04:00
message = "Closes #{reference}, #{reference2} and #{reference3}"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).
2015-10-14 07:46:17 -04:00
to match_array([issue, other_issue, third_issue])
end
it 'fetches issues in multi-line message' do
2015-05-26 15:55:26 -04:00
message = "Awesome commit (closes #{reference})\nAlso fixes #{reference2}"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).
2015-10-14 07:46:17 -04:00
to match_array([issue, other_issue])
end
it 'fetches issues in hybrid message' do
2015-05-21 16:35:15 -04:00
message = "Awesome commit (closes #{reference})\n"\
2015-05-26 15:55:26 -04:00
"Also fixing issues #{reference2}, #{reference3} and #4"
2015-04-03 12:03:34 -04:00
expect(subject.closed_by_message(message)).
2015-10-14 07:46:17 -04:00
to match_array([issue, other_issue, third_issue])
end
2015-12-02 12:48:39 -05:00
it "fetches cross-project references" do
message = "Closes #{reference} and #{cross_reference}"
expect(subject.closed_by_message(message)).
to match_array([issue, issue2])
end
it "fetches cross-project URL references" do
2015-12-03 08:00:00 -05:00
message = "Closes #{urls.namespace_project_issue_url(issue2.project.namespace, issue2.project, issue2)} and #{reference}"
2015-12-02 12:48:39 -05:00
expect(subject.closed_by_message(message)).
to match_array([issue, issue2])
end
it "ignores invalid cross-project URL references" do
2015-12-03 08:00:00 -05:00
message = "Closes https://google.com#{urls.namespace_project_issue_path(issue2.project.namespace, issue2.project, issue2)} and #{reference}"
2015-12-02 12:48:39 -05:00
expect(subject.closed_by_message(message)).
to match_array([issue])
end
end
end
2015-12-03 08:00:00 -05:00
def urls
Gitlab::Routing.url_helpers
2015-12-03 08:00:00 -05:00
end
end