Add more tests for cross-project references
This commit is contained in:
parent
34f1dbb143
commit
3a0b4340aa
|
|
@ -90,10 +90,8 @@ module Gitlab::Markdown
|
|||
let(:commit2) { project.repository.commit("HEAD~2") }
|
||||
let(:reference) { "#{project2.path_with_namespace}@#{commit1.id}...#{commit2.id}" }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(described_class).
|
||||
to receive(:user_can_reference_project?).and_return(true)
|
||||
end
|
||||
context 'when user can access reference' do
|
||||
before { allow_cross_reference! }
|
||||
|
||||
it 'links to a valid reference' do
|
||||
doc = filter("See #{reference}")
|
||||
|
|
@ -115,5 +113,16 @@ module Gitlab::Markdown
|
|||
expect(filter(act).to_html).to eq exp
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user cannot access reference' do
|
||||
before { disallow_cross_reference! }
|
||||
|
||||
it 'ignores valid references' do
|
||||
exp = act = "See #{reference}"
|
||||
|
||||
expect(filter(act).to_html).to eq exp
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -83,10 +83,8 @@ module Gitlab::Markdown
|
|||
let(:commit) { project.repository.commit }
|
||||
let(:reference) { "#{project2.path_with_namespace}@#{commit.id}" }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(described_class).
|
||||
to receive(:user_can_reference_project?).and_return(true)
|
||||
end
|
||||
context 'when user can access reference' do
|
||||
before { allow_cross_reference! }
|
||||
|
||||
it 'links to a valid reference' do
|
||||
doc = filter("See #{reference}")
|
||||
|
|
@ -105,5 +103,16 @@ module Gitlab::Markdown
|
|||
expect(filter(act).to_html).to eq exp
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user cannot access reference' do
|
||||
before { disallow_cross_reference! }
|
||||
|
||||
it 'ignores valid references' do
|
||||
exp = act = "See #{reference}"
|
||||
|
||||
expect(filter(act).to_html).to eq exp
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -89,10 +89,8 @@ module Gitlab::Markdown
|
|||
let(:issue) { create(:issue, project: project2) }
|
||||
let(:reference) { "#{project2.path_with_namespace}##{issue.iid}" }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(described_class).
|
||||
to receive(:user_can_reference_project?).and_return(true)
|
||||
end
|
||||
context 'when user can access reference' do
|
||||
before { allow_cross_reference! }
|
||||
|
||||
it 'ignores valid references when cross-reference project uses external tracker' do
|
||||
expect_any_instance_of(Project).to receive(:issue_exists?).
|
||||
|
|
@ -120,5 +118,16 @@ module Gitlab::Markdown
|
|||
expect(filter(act).to_html).to eq exp
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user cannot access reference' do
|
||||
before { disallow_cross_reference! }
|
||||
|
||||
it 'ignores valid references' do
|
||||
exp = act = "See #{reference}"
|
||||
|
||||
expect(filter(act).to_html).to eq exp
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -77,10 +77,8 @@ module Gitlab::Markdown
|
|||
let(:merge) { create(:merge_request, source_project: project2) }
|
||||
let(:reference) { "#{project2.path_with_namespace}!#{merge.iid}" }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(described_class).
|
||||
to receive(:user_can_reference_project?).and_return(true)
|
||||
end
|
||||
context 'when user can access reference' do
|
||||
before { allow_cross_reference! }
|
||||
|
||||
it 'links to a valid reference' do
|
||||
doc = filter("See #{reference}")
|
||||
|
|
@ -101,5 +99,16 @@ module Gitlab::Markdown
|
|||
expect(filter(act).to_html).to eq exp
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user cannot access reference' do
|
||||
before { disallow_cross_reference! }
|
||||
|
||||
it 'ignores valid references' do
|
||||
exp = act = "See #{reference}"
|
||||
|
||||
expect(filter(act).to_html).to eq exp
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -76,10 +76,8 @@ module Gitlab::Markdown
|
|||
let(:snippet) { create(:project_snippet, project: project2) }
|
||||
let(:reference) { "#{project2.path_with_namespace}$#{snippet.id}" }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(described_class).
|
||||
to receive(:user_can_reference_project?).and_return(true)
|
||||
end
|
||||
context 'when user can access reference' do
|
||||
before { allow_cross_reference! }
|
||||
|
||||
it 'links to a valid reference' do
|
||||
doc = filter("See #{reference}")
|
||||
|
|
@ -99,5 +97,16 @@ module Gitlab::Markdown
|
|||
expect(filter(act).to_html).to eq exp
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user cannot access reference' do
|
||||
before { disallow_cross_reference! }
|
||||
|
||||
it 'ignores valid references' do
|
||||
exp = act = "See #{reference}"
|
||||
|
||||
expect(filter(act).to_html).to eq exp
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -34,4 +34,14 @@ module ReferenceFilterSpecHelper
|
|||
contexts.reverse_merge!(project: project)
|
||||
described_class.call(html, contexts)
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue