summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-04-16 14:05:13 -0400
committerRobert Speicher <rspeicher@gmail.com>2015-04-20 13:01:46 -0400
commit3a0b4340aae05510671f9110bb46d356c5bc497b (patch)
tree058c7e8be27000001f663485d98df2cc86fea7d9 /spec/lib
parent34f1dbb143f5b3ddfb8b8fdd73f5991638f8bb7c (diff)
downloadgitlab-ce-3a0b4340aae05510671f9110bb46d356c5bc497b.tar.gz
Add more tests for cross-project references
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb43
-rw-r--r--spec/lib/gitlab/markdown/commit_reference_filter_spec.rb39
-rw-r--r--spec/lib/gitlab/markdown/issue_reference_filter_spec.rb51
-rw-r--r--spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb41
-rw-r--r--spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb39
5 files changed, 129 insertions, 84 deletions
diff --git a/spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb b/spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
index 16597ff6859..5ebdc8926e2 100644
--- a/spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
@@ -90,29 +90,38 @@ 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}")
+ 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
+ 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>\.\)/)
+ 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
- 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
+ context 'when user cannot access reference' do
+ before { disallow_cross_reference! }
- exp = act = "Fixed #{project2.path_with_namespace}##{commit1.id}...#{commit2.id.reverse}"
- expect(filter(act).to_html).to eq exp
+ it 'ignores valid references' do
+ exp = act = "See #{reference}"
+
+ expect(filter(act).to_html).to eq exp
+ end
end
end
end
diff --git a/spec/lib/gitlab/markdown/commit_reference_filter_spec.rb b/spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
index 55256fa3a90..71fd2db2c58 100644
--- a/spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
@@ -83,26 +83,35 @@ 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}")
+ 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
+ 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>\.\)/)
+ 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
- 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
+ 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
diff --git a/spec/lib/gitlab/markdown/issue_reference_filter_spec.rb b/spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
index 892e530527e..f95b37d6954 100644
--- a/spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
@@ -89,35 +89,44 @@ 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?).
- with(issue.iid).and_return(false)
+ 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
+ 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}")
+ 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
+ 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>\.\)/)
+ 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
- it 'ignores invalid issue IDs on the referenced project' do
- exp = act = "Fixed #{project2.path_with_namespace}##{issue.iid + 1}"
+ context 'when user cannot access reference' do
+ before { disallow_cross_reference! }
- expect(filter(act).to_html).to eq exp
+ it 'ignores valid references' do
+ exp = act = "See #{reference}"
+
+ expect(filter(act).to_html).to eq exp
+ end
end
end
end
diff --git a/spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb b/spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb
index c9be5d5deae..0f66442269b 100644
--- a/spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb
@@ -77,28 +77,37 @@ 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}")
+ 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
+ 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>\.\)/)
+ 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
- it 'ignores invalid merge IDs on the referenced project' do
- exp = act = "Merge #{project2.path_with_namespace}!#{merge.iid + 1}"
+ context 'when user cannot access reference' do
+ before { disallow_cross_reference! }
- expect(filter(act).to_html).to eq exp
+ it 'ignores valid references' do
+ exp = act = "See #{reference}"
+
+ expect(filter(act).to_html).to eq exp
+ end
end
end
end
diff --git a/spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb b/spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb
index 285d6dc8547..79533a90b55 100644
--- a/spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb
@@ -76,27 +76,36 @@ 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}")
+ 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
+ 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>\.\)/)
+ 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
- it 'ignores invalid snippet IDs on the referenced project' do
- exp = act = "See #{project2.path_with_namespace}$#{snippet.id + 1}"
+ context 'when user cannot access reference' do
+ before { disallow_cross_reference! }
- expect(filter(act).to_html).to eq exp
+ it 'ignores valid references' do
+ exp = act = "See #{reference}"
+
+ expect(filter(act).to_html).to eq exp
+ end
end
end
end