Add more tests for cross-project references
This commit is contained in:
parent
34f1dbb143
commit
3a0b4340aa
|
|
@ -90,29 +90,38 @@ module Gitlab::Markdown
|
||||||
let(:commit2) { project.repository.commit("HEAD~2") }
|
let(:commit2) { project.repository.commit("HEAD~2") }
|
||||||
let(:reference) { "#{project2.path_with_namespace}@#{commit1.id}...#{commit2.id}" }
|
let(:reference) { "#{project2.path_with_namespace}@#{commit1.id}...#{commit2.id}" }
|
||||||
|
|
||||||
before do
|
context 'when user can access reference' do
|
||||||
allow_any_instance_of(described_class).
|
before { allow_cross_reference! }
|
||||||
to receive(:user_can_reference_project?).and_return(true)
|
|
||||||
|
it 'links to a valid reference' do
|
||||||
|
doc = filter("See #{reference}")
|
||||||
|
|
||||||
|
expect(doc.css('a').first.attr('href')).
|
||||||
|
to eq urls.namespace_project_compare_url(project2.namespace, project2, from: commit1.id, to: commit2.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'links with adjacent text' do
|
||||||
|
doc = filter("Fixed (#{reference}.)")
|
||||||
|
expect(doc.to_html).to match(/\(<a.+>#{Regexp.escape(reference)}<\/a>\.\)/)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'ignores invalid commit IDs on the referenced project' do
|
||||||
|
exp = act = "Fixed #{project2.path_with_namespace}##{commit1.id.reverse}...#{commit2.id}"
|
||||||
|
expect(filter(act).to_html).to eq exp
|
||||||
|
|
||||||
|
exp = act = "Fixed #{project2.path_with_namespace}##{commit1.id}...#{commit2.id.reverse}"
|
||||||
|
expect(filter(act).to_html).to eq exp
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'links to a valid reference' do
|
context 'when user cannot access reference' do
|
||||||
doc = filter("See #{reference}")
|
before { disallow_cross_reference! }
|
||||||
|
|
||||||
expect(doc.css('a').first.attr('href')).
|
it 'ignores valid references' do
|
||||||
to eq urls.namespace_project_compare_url(project2.namespace, project2, from: commit1.id, to: commit2.id)
|
exp = act = "See #{reference}"
|
||||||
end
|
|
||||||
|
|
||||||
it 'links with adjacent text' do
|
expect(filter(act).to_html).to eq exp
|
||||||
doc = filter("Fixed (#{reference}.)")
|
end
|
||||||
expect(doc.to_html).to match(/\(<a.+>#{Regexp.escape(reference)}<\/a>\.\)/)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'ignores invalid commit IDs on the referenced project' do
|
|
||||||
exp = act = "Fixed #{project2.path_with_namespace}##{commit1.id.reverse}...#{commit2.id}"
|
|
||||||
expect(filter(act).to_html).to eq exp
|
|
||||||
|
|
||||||
exp = act = "Fixed #{project2.path_with_namespace}##{commit1.id}...#{commit2.id.reverse}"
|
|
||||||
expect(filter(act).to_html).to eq exp
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -83,26 +83,35 @@ module Gitlab::Markdown
|
||||||
let(:commit) { project.repository.commit }
|
let(:commit) { project.repository.commit }
|
||||||
let(:reference) { "#{project2.path_with_namespace}@#{commit.id}" }
|
let(:reference) { "#{project2.path_with_namespace}@#{commit.id}" }
|
||||||
|
|
||||||
before do
|
context 'when user can access reference' do
|
||||||
allow_any_instance_of(described_class).
|
before { allow_cross_reference! }
|
||||||
to receive(:user_can_reference_project?).and_return(true)
|
|
||||||
|
it 'links to a valid reference' do
|
||||||
|
doc = filter("See #{reference}")
|
||||||
|
|
||||||
|
expect(doc.css('a').first.attr('href')).
|
||||||
|
to eq urls.namespace_project_commit_url(project2.namespace, project2, commit.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'links with adjacent text' do
|
||||||
|
doc = filter("Fixed (#{reference}.)")
|
||||||
|
expect(doc.to_html).to match(/\(<a.+>#{Regexp.escape(reference)}<\/a>\.\)/)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'ignores invalid commit IDs on the referenced project' do
|
||||||
|
exp = act = "Committed #{project2.path_with_namespace}##{commit.id.reverse}"
|
||||||
|
expect(filter(act).to_html).to eq exp
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'links to a valid reference' do
|
context 'when user cannot access reference' do
|
||||||
doc = filter("See #{reference}")
|
before { disallow_cross_reference! }
|
||||||
|
|
||||||
expect(doc.css('a').first.attr('href')).
|
it 'ignores valid references' do
|
||||||
to eq urls.namespace_project_commit_url(project2.namespace, project2, commit.id)
|
exp = act = "See #{reference}"
|
||||||
end
|
|
||||||
|
|
||||||
it 'links with adjacent text' do
|
expect(filter(act).to_html).to eq exp
|
||||||
doc = filter("Fixed (#{reference}.)")
|
end
|
||||||
expect(doc.to_html).to match(/\(<a.+>#{Regexp.escape(reference)}<\/a>\.\)/)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'ignores invalid commit IDs on the referenced project' do
|
|
||||||
exp = act = "Committed #{project2.path_with_namespace}##{commit.id.reverse}"
|
|
||||||
expect(filter(act).to_html).to eq exp
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -89,35 +89,44 @@ module Gitlab::Markdown
|
||||||
let(:issue) { create(:issue, project: project2) }
|
let(:issue) { create(:issue, project: project2) }
|
||||||
let(:reference) { "#{project2.path_with_namespace}##{issue.iid}" }
|
let(:reference) { "#{project2.path_with_namespace}##{issue.iid}" }
|
||||||
|
|
||||||
before do
|
context 'when user can access reference' do
|
||||||
allow_any_instance_of(described_class).
|
before { allow_cross_reference! }
|
||||||
to receive(:user_can_reference_project?).and_return(true)
|
|
||||||
|
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}")
|
||||||
|
|
||||||
|
expect(doc.css('a').first.attr('href')).
|
||||||
|
to eq helper.url_for_issue(issue.iid, project2)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'links with adjacent text' do
|
||||||
|
doc = filter("Fixed (#{reference}.)")
|
||||||
|
expect(doc.to_html).to match(/\(<a.+>#{Regexp.escape(reference)}<\/a>\.\)/)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'ignores invalid issue IDs on the referenced project' do
|
||||||
|
exp = act = "Fixed #{project2.path_with_namespace}##{issue.iid + 1}"
|
||||||
|
|
||||||
|
expect(filter(act).to_html).to eq exp
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'ignores valid references when cross-reference project uses external tracker' do
|
context 'when user cannot access reference' do
|
||||||
expect_any_instance_of(Project).to receive(:issue_exists?).
|
before { disallow_cross_reference! }
|
||||||
with(issue.iid).and_return(false)
|
|
||||||
|
|
||||||
exp = act = "Issue ##{issue.iid}"
|
it 'ignores valid references' do
|
||||||
expect(filter(act).to_html).to eq exp
|
exp = act = "See #{reference}"
|
||||||
end
|
|
||||||
|
|
||||||
it 'links to a valid reference' do
|
expect(filter(act).to_html).to eq exp
|
||||||
doc = filter("See #{reference}")
|
end
|
||||||
|
|
||||||
expect(doc.css('a').first.attr('href')).
|
|
||||||
to eq helper.url_for_issue(issue.iid, project2)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'links with adjacent text' do
|
|
||||||
doc = filter("Fixed (#{reference}.)")
|
|
||||||
expect(doc.to_html).to match(/\(<a.+>#{Regexp.escape(reference)}<\/a>\.\)/)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'ignores invalid issue IDs on the referenced project' do
|
|
||||||
exp = act = "Fixed #{project2.path_with_namespace}##{issue.iid + 1}"
|
|
||||||
|
|
||||||
expect(filter(act).to_html).to eq exp
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -77,28 +77,37 @@ module Gitlab::Markdown
|
||||||
let(:merge) { create(:merge_request, source_project: project2) }
|
let(:merge) { create(:merge_request, source_project: project2) }
|
||||||
let(:reference) { "#{project2.path_with_namespace}!#{merge.iid}" }
|
let(:reference) { "#{project2.path_with_namespace}!#{merge.iid}" }
|
||||||
|
|
||||||
before do
|
context 'when user can access reference' do
|
||||||
allow_any_instance_of(described_class).
|
before { allow_cross_reference! }
|
||||||
to receive(:user_can_reference_project?).and_return(true)
|
|
||||||
|
it 'links to a valid reference' do
|
||||||
|
doc = filter("See #{reference}")
|
||||||
|
|
||||||
|
expect(doc.css('a').first.attr('href')).
|
||||||
|
to eq urls.namespace_project_merge_request_url(project2.namespace,
|
||||||
|
project, merge)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'links with adjacent text' do
|
||||||
|
doc = filter("Merge (#{reference}.)")
|
||||||
|
expect(doc.to_html).to match(/\(<a.+>#{Regexp.escape(reference)}<\/a>\.\)/)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'ignores invalid merge IDs on the referenced project' do
|
||||||
|
exp = act = "Merge #{project2.path_with_namespace}!#{merge.iid + 1}"
|
||||||
|
|
||||||
|
expect(filter(act).to_html).to eq exp
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'links to a valid reference' do
|
context 'when user cannot access reference' do
|
||||||
doc = filter("See #{reference}")
|
before { disallow_cross_reference! }
|
||||||
|
|
||||||
expect(doc.css('a').first.attr('href')).
|
it 'ignores valid references' do
|
||||||
to eq urls.namespace_project_merge_request_url(project2.namespace,
|
exp = act = "See #{reference}"
|
||||||
project, merge)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'links with adjacent text' do
|
expect(filter(act).to_html).to eq exp
|
||||||
doc = filter("Merge (#{reference}.)")
|
end
|
||||||
expect(doc.to_html).to match(/\(<a.+>#{Regexp.escape(reference)}<\/a>\.\)/)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'ignores invalid merge IDs on the referenced project' do
|
|
||||||
exp = act = "Merge #{project2.path_with_namespace}!#{merge.iid + 1}"
|
|
||||||
|
|
||||||
expect(filter(act).to_html).to eq exp
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -76,27 +76,36 @@ module Gitlab::Markdown
|
||||||
let(:snippet) { create(:project_snippet, project: project2) }
|
let(:snippet) { create(:project_snippet, project: project2) }
|
||||||
let(:reference) { "#{project2.path_with_namespace}$#{snippet.id}" }
|
let(:reference) { "#{project2.path_with_namespace}$#{snippet.id}" }
|
||||||
|
|
||||||
before do
|
context 'when user can access reference' do
|
||||||
allow_any_instance_of(described_class).
|
before { allow_cross_reference! }
|
||||||
to receive(:user_can_reference_project?).and_return(true)
|
|
||||||
|
it 'links to a valid reference' do
|
||||||
|
doc = filter("See #{reference}")
|
||||||
|
|
||||||
|
expect(doc.css('a').first.attr('href')).
|
||||||
|
to eq urls.namespace_project_snippet_url(project2.namespace, project2, snippet)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'links with adjacent text' do
|
||||||
|
doc = filter("See (#{reference}.)")
|
||||||
|
expect(doc.to_html).to match(/\(<a.+>#{Regexp.escape(reference)}<\/a>\.\)/)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'ignores invalid snippet IDs on the referenced project' do
|
||||||
|
exp = act = "See #{project2.path_with_namespace}$#{snippet.id + 1}"
|
||||||
|
|
||||||
|
expect(filter(act).to_html).to eq exp
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'links to a valid reference' do
|
context 'when user cannot access reference' do
|
||||||
doc = filter("See #{reference}")
|
before { disallow_cross_reference! }
|
||||||
|
|
||||||
expect(doc.css('a').first.attr('href')).
|
it 'ignores valid references' do
|
||||||
to eq urls.namespace_project_snippet_url(project2.namespace, project2, snippet)
|
exp = act = "See #{reference}"
|
||||||
end
|
|
||||||
|
|
||||||
it 'links with adjacent text' do
|
expect(filter(act).to_html).to eq exp
|
||||||
doc = filter("See (#{reference}.)")
|
end
|
||||||
expect(doc.to_html).to match(/\(<a.+>#{Regexp.escape(reference)}<\/a>\.\)/)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'ignores invalid snippet IDs on the referenced project' do
|
|
||||||
exp = act = "See #{project2.path_with_namespace}$#{snippet.id + 1}"
|
|
||||||
|
|
||||||
expect(filter(act).to_html).to eq exp
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -34,4 +34,14 @@ module ReferenceFilterSpecHelper
|
||||||
contexts.reverse_merge!(project: project)
|
contexts.reverse_merge!(project: project)
|
||||||
described_class.call(html, contexts)
|
described_class.call(html, contexts)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def allow_cross_reference!
|
||||||
|
allow_any_instance_of(described_class).
|
||||||
|
to receive(:user_can_reference_project?).and_return(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
def disallow_cross_reference!
|
||||||
|
allow_any_instance_of(described_class).
|
||||||
|
to receive(:user_can_reference_project?).and_return(false)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue