Commit 5a9c5520 authored by Robert Speicher's avatar Robert Speicher

Make use of to_reference in more specs

parent 68f74aa8
...@@ -8,7 +8,7 @@ module Gitlab ...@@ -8,7 +8,7 @@ module Gitlab
def closed_by_message(message) def closed_by_message(message)
return [] if message.nil? return [] if message.nil?
closing_statements = message.scan(ISSUE_CLOSING_REGEX). closing_statements = message.scan(ISSUE_CLOSING_REGEX).
map { |ref| ref[0] }.join(" ") map { |ref| ref[0] }.join(" ")
......
...@@ -48,7 +48,7 @@ module Gitlab ...@@ -48,7 +48,7 @@ module Gitlab
%(<a href="#{url}" %(<a href="#{url}"
title="#{title}" title="#{title}"
class="#{klass}">#{issue}</a>) class="#{klass}">#{match}</a>)
end end
end end
......
...@@ -52,7 +52,7 @@ module Gitlab ...@@ -52,7 +52,7 @@ module Gitlab
%(<a href="#{url}" %(<a href="#{url}"
title="#{title}" title="#{title}"
class="#{klass}">#{project_ref}##{id}</a>) class="#{klass}">#{match}</a>)
else else
match match
end end
......
...@@ -52,7 +52,7 @@ module Gitlab ...@@ -52,7 +52,7 @@ module Gitlab
%(<a href="#{url}" %(<a href="#{url}"
title="#{title}" title="#{title}"
class="#{klass}">#{project_ref}!#{id}</a>) class="#{klass}">#{match}</a>)
else else
match match
end end
......
...@@ -52,7 +52,7 @@ module Gitlab ...@@ -52,7 +52,7 @@ module Gitlab
%(<a href="#{url}" %(<a href="#{url}"
title="#{title}" title="#{title}"
class="#{klass}">#{project_ref}$#{id}</a>) class="#{klass}">#{match}</a>)
else else
match match
end end
......
...@@ -65,7 +65,8 @@ module Gitlab ...@@ -65,7 +65,8 @@ module Gitlab
url = urls.namespace_project_url(project.namespace, project, url = urls.namespace_project_url(project.namespace, project,
only_path: context[:only_path]) only_path: context[:only_path])
%(<a href="#{url}" class="#{link_class}">@all</a>) text = User.reference_prefix + 'all'
%(<a href="#{url}" class="#{link_class}">#{text}</a>)
end end
def link_to_namespace(namespace) def link_to_namespace(namespace)
...@@ -83,7 +84,8 @@ module Gitlab ...@@ -83,7 +84,8 @@ module Gitlab
url = urls.group_url(group, only_path: context[:only_path]) url = urls.group_url(group, only_path: context[:only_path])
%(<a href="#{url}" class="#{link_class}">@#{group}</a>) text = Group.reference_prefix + group
%(<a href="#{url}" class="#{link_class}">#{text}</a>)
end end
def link_to_user(user, namespace) def link_to_user(user, namespace)
...@@ -91,7 +93,8 @@ module Gitlab ...@@ -91,7 +93,8 @@ module Gitlab
url = urls.user_url(user, only_path: context[:only_path]) url = urls.user_url(user, only_path: context[:only_path])
%(<a href="#{url}" class="#{link_class}">@#{user}</a>) text = User.reference_prefix + user
%(<a href="#{url}" class="#{link_class}">#{text}</a>)
end end
def user_can_reference_group?(group) def user_can_reference_group?(group)
......
...@@ -11,7 +11,7 @@ describe "GitLab Flavored Markdown", feature: true do ...@@ -11,7 +11,7 @@ describe "GitLab Flavored Markdown", feature: true do
end end
before do before do
Commit.any_instance.stub(title: "fix ##{issue.iid}\n\nask @#{fred.username} for details") Commit.any_instance.stub(title: "fix #{issue.to_reference}\n\nask #{fred.to_reference} for details")
end end
let(:commit) { project.commit } let(:commit) { project.commit }
...@@ -25,25 +25,25 @@ describe "GitLab Flavored Markdown", feature: true do ...@@ -25,25 +25,25 @@ describe "GitLab Flavored Markdown", feature: true do
it "should render title in commits#index" do it "should render title in commits#index" do
visit namespace_project_commits_path(project.namespace, project, 'master', limit: 1) visit namespace_project_commits_path(project.namespace, project, 'master', limit: 1)
expect(page).to have_link("##{issue.iid}") expect(page).to have_link(issue.to_reference)
end end
it "should render title in commits#show" do it "should render title in commits#show" do
visit namespace_project_commit_path(project.namespace, project, commit) visit namespace_project_commit_path(project.namespace, project, commit)
expect(page).to have_link("##{issue.iid}") expect(page).to have_link(issue.to_reference)
end end
it "should render description in commits#show" do it "should render description in commits#show" do
visit namespace_project_commit_path(project.namespace, project, commit) visit namespace_project_commit_path(project.namespace, project, commit)
expect(page).to have_link("@#{fred.username}") expect(page).to have_link(fred.to_reference)
end end
it "should render title in repositories#branches" do it "should render title in repositories#branches" do
visit namespace_project_branches_path(project.namespace, project) visit namespace_project_branches_path(project.namespace, project)
expect(page).to have_link("##{issue.iid}") expect(page).to have_link(issue.to_reference)
end end
end end
...@@ -57,20 +57,20 @@ describe "GitLab Flavored Markdown", feature: true do ...@@ -57,20 +57,20 @@ describe "GitLab Flavored Markdown", feature: true do
author: @user, author: @user,
assignee: @user, assignee: @user,
project: project, project: project,
title: "fix ##{@other_issue.iid}", title: "fix #{@other_issue.to_reference}",
description: "ask @#{fred.username} for details") description: "ask #{fred.to_reference} for details")
end end
it "should render subject in issues#index" do it "should render subject in issues#index" do
visit namespace_project_issues_path(project.namespace, project) visit namespace_project_issues_path(project.namespace, project)
expect(page).to have_link("##{@other_issue.iid}") expect(page).to have_link(@other_issue.to_reference)
end end
it "should render subject in issues#show" do it "should render subject in issues#show" do
visit namespace_project_issue_path(project.namespace, project, @issue) visit namespace_project_issue_path(project.namespace, project, @issue)
expect(page).to have_link("##{@other_issue.iid}") expect(page).to have_link(@other_issue.to_reference)
end end
it "should render details in issues#show" do it "should render details in issues#show" do
...@@ -83,19 +83,19 @@ describe "GitLab Flavored Markdown", feature: true do ...@@ -83,19 +83,19 @@ describe "GitLab Flavored Markdown", feature: true do
describe "for merge requests" do describe "for merge requests" do
before do before do
@merge_request = create(:merge_request, source_project: project, target_project: project, title: "fix ##{issue.iid}") @merge_request = create(:merge_request, source_project: project, target_project: project, title: "fix #{issue.to_reference}")
end end
it "should render title in merge_requests#index" do it "should render title in merge_requests#index" do
visit namespace_project_merge_requests_path(project.namespace, project) visit namespace_project_merge_requests_path(project.namespace, project)
expect(page).to have_link("##{issue.iid}") expect(page).to have_link(issue.to_reference)
end end
it "should render title in merge_requests#show" do it "should render title in merge_requests#show" do
visit namespace_project_merge_request_path(project.namespace, project, @merge_request) visit namespace_project_merge_request_path(project.namespace, project, @merge_request)
expect(page).to have_link("##{issue.iid}") expect(page).to have_link(issue.to_reference)
end end
end end
...@@ -104,26 +104,26 @@ describe "GitLab Flavored Markdown", feature: true do ...@@ -104,26 +104,26 @@ describe "GitLab Flavored Markdown", feature: true do
before do before do
@milestone = create(:milestone, @milestone = create(:milestone,
project: project, project: project,
title: "fix ##{issue.iid}", title: "fix #{issue.to_reference}",
description: "ask @#{fred.username} for details") description: "ask #{fred.to_reference} for details")
end end
it "should render title in milestones#index" do it "should render title in milestones#index" do
visit namespace_project_milestones_path(project.namespace, project) visit namespace_project_milestones_path(project.namespace, project)
expect(page).to have_link("##{issue.iid}") expect(page).to have_link(issue.to_reference)
end end
it "should render title in milestones#show" do it "should render title in milestones#show" do
visit namespace_project_milestone_path(project.namespace, project, @milestone) visit namespace_project_milestone_path(project.namespace, project, @milestone)
expect(page).to have_link("##{issue.iid}") expect(page).to have_link(issue.to_reference)
end end
it "should render description in milestones#show" do it "should render description in milestones#show" do
visit namespace_project_milestone_path(project.namespace, project, @milestone) visit namespace_project_milestone_path(project.namespace, project, @milestone)
expect(page).to have_link("@#{fred.username}") expect(page).to have_link(fred.to_reference)
end end
end end
end end
...@@ -26,7 +26,7 @@ describe GitlabMarkdownHelper do ...@@ -26,7 +26,7 @@ describe GitlabMarkdownHelper do
end end
describe "referencing multiple objects" do describe "referencing multiple objects" do
let(:actual) { "!#{merge_request.iid} -> #{commit.id} -> ##{issue.iid}" } let(:actual) { "#{merge_request.to_reference} -> #{commit.to_reference} -> #{issue.to_reference}" }
it "should link to the merge request" do it "should link to the merge request" do
expected = namespace_project_merge_request_path(project.namespace, project, merge_request) expected = namespace_project_merge_request_path(project.namespace, project, merge_request)
...@@ -50,7 +50,7 @@ describe GitlabMarkdownHelper do ...@@ -50,7 +50,7 @@ describe GitlabMarkdownHelper do
let(:issues) { create_list(:issue, 2, project: project) } let(:issues) { create_list(:issue, 2, project: project) }
it 'should handle references nested in links with all the text' do it 'should handle references nested in links with all the text' do
actual = link_to_gfm("This should finally fix ##{issues[0].iid} and ##{issues[1].iid} for real", commit_path) actual = link_to_gfm("This should finally fix #{issues[0].to_reference} and #{issues[1].to_reference} for real", commit_path)
doc = Nokogiri::HTML.parse(actual) doc = Nokogiri::HTML.parse(actual)
# Make sure we didn't create invalid markup # Make sure we didn't create invalid markup
...@@ -63,7 +63,7 @@ describe GitlabMarkdownHelper do ...@@ -63,7 +63,7 @@ describe GitlabMarkdownHelper do
# First issue link # First issue link
expect(doc.css('a')[1].attr('href')). expect(doc.css('a')[1].attr('href')).
to eq namespace_project_issue_path(project.namespace, project, issues[0]) to eq namespace_project_issue_path(project.namespace, project, issues[0])
expect(doc.css('a')[1].text).to eq "##{issues[0].iid}" expect(doc.css('a')[1].text).to eq issues[0].to_reference
# Internal commit link # Internal commit link
expect(doc.css('a')[2].attr('href')).to eq commit_path expect(doc.css('a')[2].attr('href')).to eq commit_path
...@@ -72,7 +72,7 @@ describe GitlabMarkdownHelper do ...@@ -72,7 +72,7 @@ describe GitlabMarkdownHelper do
# Second issue link # Second issue link
expect(doc.css('a')[3].attr('href')). expect(doc.css('a')[3].attr('href')).
to eq namespace_project_issue_path(project.namespace, project, issues[1]) to eq namespace_project_issue_path(project.namespace, project, issues[1])
expect(doc.css('a')[3].text).to eq "##{issues[1].iid}" expect(doc.css('a')[3].text).to eq issues[1].to_reference
# Trailing commit link # Trailing commit link
expect(doc.css('a')[4].attr('href')).to eq commit_path expect(doc.css('a')[4].attr('href')).to eq commit_path
...@@ -90,7 +90,7 @@ describe GitlabMarkdownHelper do ...@@ -90,7 +90,7 @@ describe GitlabMarkdownHelper do
end end
it "escapes HTML passed in as the body" do it "escapes HTML passed in as the body" do
actual = "This is a <h1>test</h1> - see ##{issues[0].iid}" actual = "This is a <h1>test</h1> - see #{issues[0].to_reference}"
expect(link_to_gfm(actual, commit_path)). expect(link_to_gfm(actual, commit_path)).
to match('&lt;h1&gt;test&lt;/h1&gt;') to match('&lt;h1&gt;test&lt;/h1&gt;')
end end
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::ClosingIssueExtractor do describe Gitlab::ClosingIssueExtractor do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:issue) { create(:issue, project: project) } let(:issue) { create(:issue, project: project) }
let(:iid1) { issue.iid } let(:reference) { issue.to_reference }
subject { described_class.new(project, project.creator) } subject { described_class.new(project, project.creator) }
describe "#closed_by_message" do describe "#closed_by_message" do
context 'with a single reference' do context 'with a single reference' do
it do it do
message = "Awesome commit (Closes ##{iid1})" message = "Awesome commit (Closes #{reference})"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
it do it do
message = "Awesome commit (closes ##{iid1})" message = "Awesome commit (closes #{reference})"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
it do it do
message = "Closed ##{iid1}" message = "Closed #{reference}"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
it do it do
message = "closed ##{iid1}" message = "closed #{reference}"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
it do it do
message = "Closing ##{iid1}" message = "Closing #{reference}"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
it do it do
message = "closing ##{iid1}" message = "closing #{reference}"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
it do it do
message = "Close ##{iid1}" message = "Close #{reference}"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
it do it do
message = "close ##{iid1}" message = "close #{reference}"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
it do it do
message = "Awesome commit (Fixes ##{iid1})" message = "Awesome commit (Fixes #{reference})"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
it do it do
message = "Awesome commit (fixes ##{iid1})" message = "Awesome commit (fixes #{reference})"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
it do it do
message = "Fixed ##{iid1}" message = "Fixed #{reference}"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
it do it do
message = "fixed ##{iid1}" message = "fixed #{reference}"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
it do it do
message = "Fixing ##{iid1}" message = "Fixing #{reference}"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
it do it do
message = "fixing ##{iid1}" message = "fixing #{reference}"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
it do it do
message = "Fix ##{iid1}" message = "Fix #{reference}"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
it do it do
message = "fix ##{iid1}" message = "fix #{reference}"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
it do it do
message = "Awesome commit (Resolves ##{iid1})" message = "Awesome commit (Resolves #{reference})"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
it do it do
message = "Awesome commit (resolves ##{iid1})" message = "Awesome commit (resolves #{reference})"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
it do it do
message = "Resolved ##{iid1}" message = "Resolved #{reference}"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
it do it do
message = "resolved ##{iid1}" message = "resolved #{reference}"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
it do it do
message = "Resolving ##{iid1}" message = "Resolving #{reference}"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
it do it do
message = "resolving ##{iid1}" message = "resolving #{reference}"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
it do it do
message = "Resolve ##{iid1}" message = "Resolve #{reference}"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
it do it do
message = "resolve ##{iid1}" message = "resolve #{reference}"
expect(subject.closed_by_message(message)).to eq([issue]) expect(subject.closed_by_message(message)).to eq([issue])
end end
end end
...@@ -133,40 +133,40 @@ describe Gitlab::ClosingIssueExtractor do ...@@ -133,40 +133,40 @@ describe Gitlab::ClosingIssueExtractor do
context 'with multiple references' do context 'with multiple references' do
let(:other_issue) { create(:issue, project: project) } let(:other_issue) { create(:issue, project: project) }
let(:third_issue) { create(:issue, project: project) } let(:third_issue) { create(:issue, project: project) }
let(:iid2) { other_issue.iid } let(:reference2) { other_issue.to_reference }
let(:iid3) { third_issue.iid } let(:reference3) { third_issue.to_reference }
it 'fetches issues in single line message' do it 'fetches issues in single line message' do
message = "Closes ##{iid1} and fix ##{iid2}" message = "Closes #{reference} and fix ##{reference2}"
expect(subject.closed_by_message(message)). expect(subject.closed_by_message(message)).
to eq([issue, other_issue]) to eq([issue, other_issue])
end end
it 'fetches comma-separated issues references in single line message' do it 'fetches comma-separated issues references in single line message' do
message = "Closes ##{iid1}, closes ##{iid2}" message = "Closes #{reference}, closes ##{reference2}"
expect(subject.closed_by_message(message)). expect(subject.closed_by_message(message)).
to eq([issue, other_issue]) to eq([issue, other_issue])
end end
it 'fetches comma-separated issues numbers in single line message' do it 'fetches comma-separated issues numbers in single line message' do
message = "Closes ##{iid1}, ##{iid2} and ##{iid3}" message = "Closes #{reference}, ##{reference2} and ##{reference3}"
expect(subject.closed_by_message(message)). expect(subject.closed_by_message(message)).
to eq([issue, other_issue, third_issue]) to eq([issue, other_issue, third_issue])
end end
it 'fetches issues in multi-line message' do it 'fetches issues in multi-line message' do
message = "Awesome commit (closes ##{iid1})\nAlso fixes ##{iid2}" message = "Awesome commit (closes #{reference})\nAlso fixes ##{reference2}"
expect(subject.closed_by_message(message)). expect(subject.closed_by_message(message)).
to eq([issue, other_issue]) to eq([issue, other_issue])
end end
it 'fetches issues in hybrid message' do it 'fetches issues in hybrid message' do
message = "Awesome commit (closes ##{iid1})\n"\ message = "Awesome commit (closes #{reference})\n"\
"Also fixing issues ##{iid2}, ##{iid3} and #4" "Also fixing issues ##{reference2}, ##{reference3} and #4"
expect(subject.closed_by_message(message)). expect(subject.closed_by_message(message)).
to eq([issue, other_issue, third_issue]) to eq([issue, other_issue, third_issue])
......
...@@ -20,7 +20,7 @@ describe Gitlab::ReferenceExtractor do ...@@ -20,7 +20,7 @@ describe Gitlab::ReferenceExtractor do
@i0 = create(:issue, project: project) @i0 = create(:issue, project: project)
@i1 = create(:issue, project: project) @i1 = create(:issue, project: project)
subject.analyze("##{@i0.iid}, ##{@i1.iid}, and #999.") subject.analyze("#{@i0.to_reference}, #{@i1.to_reference}, and #{Issue.reference_prefix}999.")
expect(subject.issues).to eq([@i0, @i1]) expect(subject.issues).to eq([@i0, @i1])
end end
...@@ -82,7 +82,7 @@ describe Gitlab::ReferenceExtractor do ...@@ -82,7 +82,7 @@ describe Gitlab::ReferenceExtractor do
end end
it 'handles project issue references' do it 'handles project issue references' do
subject.analyze("this refers issue #{other_project.path_with_namespace}##{issue.iid}") subject.analyze("this refers issue #{issue.to_reference(project)}")
extracted = subject.issues extracted = subject.issues
expect(extracted.size).to eq(1) expect(extracted.size).to eq(1)
expect(extracted).to eq([issue]) expect(extracted).to eq([issue])
......
...@@ -129,7 +129,7 @@ describe MergeRequest do ...@@ -129,7 +129,7 @@ describe MergeRequest do
it 'detects issues mentioned in the description' do it 'detects issues mentioned in the description' do
issue2 = create(:issue, project: subject.project) issue2 = create(:issue, project: subject.project)
subject.description = "Closes ##{issue2.iid}" subject.description = "Closes #{issue2.to_reference}"
subject.project.stub(default_branch: subject.target_branch) subject.project.stub(default_branch: subject.target_branch)
expect(subject.closes_issues).to include(issue2) expect(subject.closes_issues).to include(issue2)
......
...@@ -238,13 +238,13 @@ describe SystemNoteService do ...@@ -238,13 +238,13 @@ describe SystemNoteService do
let(:mentioner) { project2.repository.commit } let(:mentioner) { project2.repository.commit }
it 'references the mentioning commit' do it 'references the mentioning commit' do
expect(subject.note).to eq "mentioned in commit #{project2.path_with_namespace}@#{mentioner.id}" expect(subject.note).to eq "mentioned in commit #{mentioner.to_reference(project)}"
end end
end end
context 'from non-Commit' do context 'from non-Commit' do
it 'references the mentioning object' do it 'references the mentioning object' do
expect(subject.note).to eq "mentioned in issue #{project2.path_with_namespace}##{mentioner.iid}" expect(subject.note).to eq "mentioned in issue #{mentioner.to_reference(project)}"
end end
end end
end end
...@@ -254,13 +254,13 @@ describe SystemNoteService do ...@@ -254,13 +254,13 @@ describe SystemNoteService do
let(:mentioner) { project.repository.commit } let(:mentioner) { project.repository.commit }
it 'references the mentioning commit' do it 'references the mentioning commit' do
expect(subject.note).to eq "mentioned in commit #{mentioner.id}" expect(subject.note).to eq "mentioned in commit #{mentioner.to_reference}"
end end
end end
context 'from non-Commit' do context 'from non-Commit' do
it 'references the mentioning object' do it 'references the mentioning object' do
expect(subject.note).to eq "mentioned in issue ##{mentioner.iid}" expect(subject.note).to eq "mentioned in issue #{mentioner.to_reference}"
end end
end end
end end
...@@ -270,7 +270,7 @@ describe SystemNoteService do ...@@ -270,7 +270,7 @@ describe SystemNoteService do
describe '.cross_reference?' do describe '.cross_reference?' do
it 'is truthy when text begins with expected text' do it 'is truthy when text begins with expected text' do
expect(described_class.cross_reference?('mentioned in issue #1')).to be_truthy expect(described_class.cross_reference?('mentioned in something')).to be_truthy
end end
it 'is falsey when text does not begin with expected text' do it 'is falsey when text does not begin with expected text' do
......
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