From 6b04a5f9108c640f638afa8055e2a5b60f926d5a Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Tue, 6 May 2014 19:51:56 +0200 Subject: Add support for Jira ticket mentions in format JIRA-123. Signed-off-by: Dmitriy Zaporozhets Conflicts: CHANGELOG-EE --- spec/helpers/gitlab_markdown_helper_spec.rb | 46 +++++++++++++++++++++++++++++ spec/lib/gitlab/reference_extractor_spec.rb | 6 ++++ 2 files changed, 52 insertions(+) (limited to 'spec') diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb index 5bd16d1c16c..8c33ceeff26 100644 --- a/spec/helpers/gitlab_markdown_helper_spec.rb +++ b/spec/helpers/gitlab_markdown_helper_spec.rb @@ -181,6 +181,52 @@ describe GitlabMarkdownHelper do include_examples 'referenced object' end + describe "referencing a Jira issue" do + let(:actual) { "Reference to JIRA-#{issue.iid}" } + let(:expected) { "http://jira.example/browse/JIRA-#{issue.iid}" } + let(:reference) { "JIRA-#{issue.iid}" } + + before do + hash = { "jira" => { "title" => "JIRA tracker", "issues_url" => "http://jira.example/browse/:id" } } + Gitlab.config.stub(:issues_tracker).and_return(hash) + @project.stub(:issues_tracker).and_return("jira") + @project.stub(:issues_tracker_id).and_return("JIRA") + end + + it "should link using a valid id" do + gfm(actual).should match(expected) + end + + it "should link with adjacent text" do + # Wrap the reference in parenthesis + gfm(actual.gsub(reference, "(#{reference})")).should match(expected) + + # Append some text to the end of the reference + gfm(actual.gsub(reference, "#{reference}, right?")).should match(expected) + end + + it "should keep whitespace intact" do + actual = "Referenced #{reference} already." + expected = /Referenced [^\s]+<\/a> already/ + gfm(actual).should match(expected) + end + + it "should not link with an invalid id" do + # Modify the reference string so it's still parsed, but is invalid + invalid_reference = actual.gsub(/(\d+)$/, "r45") + gfm(invalid_reference).should == invalid_reference + end + + it "should include a title attribute" do + title = "Issue in JIRA tracker" + gfm(actual).should match(/title="#{title}"/) + end + + it "should include standard gfm classes" do + gfm(actual).should match(/class="\s?gfm gfm-issue\s?"/) + end + end + describe "referencing a merge request" do let(:object) { merge_request } let(:reference) { "!#{merge_request.iid}" } diff --git a/spec/lib/gitlab/reference_extractor_spec.rb b/spec/lib/gitlab/reference_extractor_spec.rb index 19259a8b79c..99fed27c796 100644 --- a/spec/lib/gitlab/reference_extractor_spec.rb +++ b/spec/lib/gitlab/reference_extractor_spec.rb @@ -11,6 +11,12 @@ describe Gitlab::ReferenceExtractor do subject.issues.should == ["1234"] end + it 'extracts JIRA issue references' do + Gitlab.config.gitlab.stub(:issues_tracker).and_return("jira") + subject.analyze "this one talks about issue JIRA-1234" + subject.issues.should == ["JIRA-1234"] + end + it 'extracts merge request references' do subject.analyze "and here's !43, a merge request" subject.merge_requests.should == ["43"] -- cgit v1.2.1