Commit 5b6c1a21 authored by Robert Speicher's avatar Robert Speicher
Browse files

Fix Issue and ExternalIssue reference specs

parent 0c26537c9a5d
module Gitlab
module Markdown
# HTML filter that replaces external issue tracker references with links.
# References are ignored if the project doesn't use an external issue
# tracker.
class ExternalIssueReferenceFilter < ReferenceFilter
# Public: Find `JIRA-123` issue references in text
#
......@@ -23,6 +25,8 @@ def self.references_in(text)
ISSUE_PATTERN = /(?<issue>([A-Z\-]+-)\d+)/
def call
return doc if project.default_issues_tracker?
replace_text_nodes_matching(ISSUE_PATTERN) do |content|
issue_link_filter(content)
end
......
......@@ -16,13 +16,6 @@ def helper
to raise_error(ArgumentError, /:project/)
end
it 'ignores valid references when using non-default tracker' do
expect(project).to receive(:default_issues_tracker?).and_return(false)
exp = act = "Issue ##{issue.iid}"
expect(filter(act).to_html).to eq exp
end
%w(pre code a style).each do |elem|
it "ignores valid references contained inside '#{elem}' element" do
exp = act = "<#{elem}>Issue ##{issue.iid}</#{elem}>"
......@@ -33,6 +26,13 @@ def helper
context 'internal reference' do
let(:reference) { "##{issue.iid}" }
it 'ignores valid references when using non-default tracker' do
expect(project).to receive(:issue_exists?).with(issue.iid).and_return(false)
exp = act = "Issue ##{issue.iid}"
expect(filter(act).to_html).to eq exp
end
it 'links to a valid reference' do
doc = filter("See #{reference}")
......@@ -87,6 +87,14 @@ def helper
to receive(:user_can_reference_project?).and_return(true)
end
it 'ignores valid references when cross-reference project uses external tracker' do
expect_any_instance_of(Project).to receive(:issue_exists?).
with(issue.iid).and_return(false)
exp = act = "Issue ##{issue.iid}"
expect(filter(act).to_html).to eq exp
end
it 'links to a valid reference' do
doc = filter("See #{reference}")
......
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