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
def closed_by_message(message)
return [] if message.nil?
closing_statements = message.scan(ISSUE_CLOSING_REGEX).
map { |ref| ref[0] }.join(" ")
......
......@@ -48,7 +48,7 @@ module Gitlab
%(<a href="#{url}"
title="#{title}"
class="#{klass}">#{issue}</a>)
class="#{klass}">#{match}</a>)
end
end
......
......@@ -52,7 +52,7 @@ module Gitlab
%(<a href="#{url}"
title="#{title}"
class="#{klass}">#{project_ref}##{id}</a>)
class="#{klass}">#{match}</a>)
else
match
end
......
......@@ -52,7 +52,7 @@ module Gitlab
%(<a href="#{url}"
title="#{title}"
class="#{klass}">#{project_ref}!#{id}</a>)
class="#{klass}">#{match}</a>)
else
match
end
......
......@@ -52,7 +52,7 @@ module Gitlab
%(<a href="#{url}"
title="#{title}"
class="#{klass}">#{project_ref}$#{id}</a>)
class="#{klass}">#{match}</a>)
else
match
end
......
......@@ -65,7 +65,8 @@ module Gitlab
url = urls.namespace_project_url(project.namespace, project,
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
def link_to_namespace(namespace)
......@@ -83,7 +84,8 @@ module Gitlab
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
def link_to_user(user, namespace)
......@@ -91,7 +93,8 @@ module Gitlab
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
def user_can_reference_group?(group)
......
......@@ -11,7 +11,7 @@ describe "GitLab Flavored Markdown", feature: true do
end
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
let(:commit) { project.commit }
......@@ -25,25 +25,25 @@ describe "GitLab Flavored Markdown", feature: true do
it "should render title in commits#index" do
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
it "should render title in commits#show" do
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
it "should render description in commits#show" do
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
it "should render title in repositories#branches" do
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
......@@ -57,20 +57,20 @@ describe "GitLab Flavored Markdown", feature: true do
author: @user,
assignee: @user,
project: project,
title: "fix ##{@other_issue.iid}",
description: "ask @#{fred.username} for details")
title: "fix #{@other_issue.to_reference}",
description: "ask #{fred.to_reference} for details")
end
it "should render subject in issues#index" do
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
it "should render subject in issues#show" do
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
it "should render details in issues#show" do
......@@ -83,19 +83,19 @@ describe "GitLab Flavored Markdown", feature: true do
describe "for merge requests" 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
it "should render title in merge_requests#index" do
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
it "should render title in merge_requests#show" do
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
......@@ -104,26 +104,26 @@ describe "GitLab Flavored Markdown", feature: true do
before do
@milestone = create(:milestone,
project: project,
title: "fix ##{issue.iid}",
description: "ask @#{fred.username} for details")
title: "fix #{issue.to_reference}",
description: "ask #{fred.to_reference} for details")
end
it "should render title in milestones#index" do
visit namespace_project_milestones_path(project.namespace, project)
expect(page).to have_link("##{issue.iid}")
expect(page).to have_link(issue.to_reference)
end
it "should render title in milestones#show" do
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
it "should render description in milestones#show" do
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
......@@ -26,7 +26,7 @@ describe GitlabMarkdownHelper do
end
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
expected = namespace_project_merge_request_path(project.namespace, project, merge_request)
......@@ -50,7 +50,7 @@ describe GitlabMarkdownHelper do
let(:issues) { create_list(:issue, 2, project: project) }
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)
# Make sure we didn't create invalid markup
......@@ -63,7 +63,7 @@ describe GitlabMarkdownHelper do
# First issue link
expect(doc.css('a')[1].attr('href')).
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
expect(doc.css('a')[2].attr('href')).to eq commit_path
......@@ -72,7 +72,7 @@ describe GitlabMarkdownHelper do
# Second issue link
expect(doc.css('a')[3].attr('href')).
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
expect(doc.css('a')[4].attr('href')).to eq commit_path
......@@ -90,7 +90,7 @@ describe GitlabMarkdownHelper do
end
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)).
to match('&lt;h1&gt;test&lt;/h1&gt;')
end
......
require 'spec_helper'
describe Gitlab::ClosingIssueExtractor do
let(:project) { create(:project) }
let(:issue) { create(:issue, project: project) }
let(:iid1) { issue.iid }
let(:project) { create(:project) }
let(:issue) { create(:issue, project: project) }
let(:reference) { issue.to_reference }
subject { described_class.new(project, project.creator) }
describe "#closed_by_message" do
context 'with a single reference' do
it do
message = "Awesome commit (Closes ##{iid1})"
message = "Awesome commit (Closes #{reference})"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Awesome commit (closes ##{iid1})"
message = "Awesome commit (closes #{reference})"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Closed ##{iid1}"
message = "Closed #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "closed ##{iid1}"
message = "closed #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Closing ##{iid1}"
message = "Closing #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "closing ##{iid1}"
message = "closing #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Close ##{iid1}"
message = "Close #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "close ##{iid1}"
message = "close #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Awesome commit (Fixes ##{iid1})"
message = "Awesome commit (Fixes #{reference})"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Awesome commit (fixes ##{iid1})"
message = "Awesome commit (fixes #{reference})"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Fixed ##{iid1}"
message = "Fixed #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "fixed ##{iid1}"
message = "fixed #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Fixing ##{iid1}"
message = "Fixing #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "fixing ##{iid1}"
message = "fixing #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Fix ##{iid1}"
message = "Fix #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "fix ##{iid1}"
message = "fix #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Awesome commit (Resolves ##{iid1})"
message = "Awesome commit (Resolves #{reference})"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Awesome commit (resolves ##{iid1})"
message = "Awesome commit (resolves #{reference})"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Resolved ##{iid1}"
message = "Resolved #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "resolved ##{iid1}"
message = "resolved #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Resolving ##{iid1}"
message = "Resolving #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "resolving ##{iid1}"
message = "resolving #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "Resolve ##{iid1}"
message = "Resolve #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
it do
message = "resolve ##{iid1}"
message = "resolve #{reference}"
expect(subject.closed_by_message(message)).to eq([issue])
end
end
......@@ -133,40 +133,40 @@ describe Gitlab::ClosingIssueExtractor do
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 }
let(:reference2) { other_issue.to_reference }
let(:reference3) { third_issue.to_reference }
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)).
to eq([issue, other_issue])
end
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)).
to eq([issue, other_issue])
end
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)).
to eq([issue, other_issue, third_issue])
end
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)).
to eq([issue, other_issue])
end
it 'fetches issues in hybrid message' do
message = "Awesome commit (closes ##{iid1})\n"\
"Also fixing issues ##{iid2}, ##{iid3} and #4"
message = "Awesome commit (closes #{reference})\n"\
"Also fixing issues ##{reference2}, ##{reference3} and #4"
expect(subject.closed_by_message(message)).
to eq([issue, other_issue, third_issue])
......
......@@ -20,7 +20,7 @@ describe Gitlab::ReferenceExtractor do
@i0 = 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])
end
......@@ -82,7 +82,7 @@ describe Gitlab::ReferenceExtractor do
end
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
expect(extracted.size).to eq(1)
expect(extracted).to eq([issue])
......
......@@ -129,7 +129,7 @@ describe MergeRequest do
it 'detects issues mentioned in the description' do
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)
expect(subject.closes_issues).to include(issue2)
......
......@@ -238,13 +238,13 @@ describe SystemNoteService do
let(:mentioner) { project2.repository.commit }
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
context 'from non-Commit' 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
......@@ -254,13 +254,13 @@ describe SystemNoteService do
let(:mentioner) { project.repository.commit }
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
context 'from non-Commit' 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
......@@ -270,7 +270,7 @@ describe SystemNoteService do
describe '.cross_reference?' 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
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