summaryrefslogtreecommitdiff
path: root/spec/lib/banzai
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/banzai')
-rw-r--r--spec/lib/banzai/filter/relative_link_filter_spec.rb12
-rw-r--r--spec/lib/banzai/reference_parser/issue_parser_spec.rb1
-rw-r--r--spec/lib/banzai/reference_parser/snippet_parser_spec.rb1
-rw-r--r--spec/lib/banzai/reference_redactor_spec.rb1
4 files changed, 14 insertions, 1 deletions
diff --git a/spec/lib/banzai/filter/relative_link_filter_spec.rb b/spec/lib/banzai/filter/relative_link_filter_spec.rb
index 371c7a2347c..a17a645d4d0 100644
--- a/spec/lib/banzai/filter/relative_link_filter_spec.rb
+++ b/spec/lib/banzai/filter/relative_link_filter_spec.rb
@@ -96,21 +96,25 @@ describe Banzai::Filter::RelativeLinkFilter do
context 'with a project_wiki' do
let(:project_wiki) { double('ProjectWiki') }
+
include_examples :preserve_unchanged
end
context 'without a repository' do
let(:project) { create(:project) }
+
include_examples :preserve_unchanged
end
context 'with an empty repository' do
let(:project) { create(:project_empty_repo) }
+
include_examples :preserve_unchanged
end
context 'without project repository access' do
let(:project) { create(:project, :repository, repository_access_level: ProjectFeature::PRIVATE) }
+
include_examples :preserve_unchanged
end
@@ -269,6 +273,7 @@ describe Banzai::Filter::RelativeLinkFilter do
context 'when requested path is a file in the repo' do
let(:requested_path) { 'doc/api/README.md' }
+
it 'rebuilds URL relative to the containing directory' do
doc = filter(link('users.md'))
expect(doc.at_css('a')['href']).to eq "/#{project_path}/blob/#{Addressable::URI.escape(ref)}/doc/api/users.md"
@@ -277,6 +282,7 @@ describe Banzai::Filter::RelativeLinkFilter do
context 'when requested path is a directory in the repo' do
let(:requested_path) { 'doc/api/' }
+
it 'rebuilds URL relative to the directory' do
doc = filter(link('users.md'))
expect(doc.at_css('a')['href']).to eq "/#{project_path}/blob/#{Addressable::URI.escape(ref)}/doc/api/users.md"
@@ -287,6 +293,7 @@ describe Banzai::Filter::RelativeLinkFilter do
let(:ref) { '100%branch' }
let(:commit) { project.commit('1b12f15a11fc6e62177bef08f47bc7b5ce50b141') }
let(:requested_path) { 'foo/bar/' }
+
it 'correctly escapes the ref' do
doc = filter(link('.gitkeep'))
expect(doc.at_css('a')['href']).to eq "/#{project_path}/blob/#{Addressable::URI.escape(ref)}/foo/bar/.gitkeep"
@@ -316,6 +323,7 @@ describe Banzai::Filter::RelativeLinkFilter do
let(:ref) { 'master' }
let(:commit) { project.commit('38008cb17ce1466d8fec2dfa6f6ab8dcfe5cf49e') }
let(:requested_path) { 'with space/' }
+
it 'does not escape the space twice' do
doc = filter(link('README.md'))
expect(doc.at_css('a')['href']).to eq "/#{project_path}/blob/#{Addressable::URI.escape(ref)}/with%20space/README.md"
@@ -328,7 +336,9 @@ describe Banzai::Filter::RelativeLinkFilter do
end
context 'with a valid ref' do
- let(:commit) { nil } # force filter to use ref instead of commit
+ # force filter to use ref instead of commit
+ let(:commit) { nil }
+
include_examples :valid_repository
end
diff --git a/spec/lib/banzai/reference_parser/issue_parser_spec.rb b/spec/lib/banzai/reference_parser/issue_parser_spec.rb
index a925d294b1b..ac321aca5e9 100644
--- a/spec/lib/banzai/reference_parser/issue_parser_spec.rb
+++ b/spec/lib/banzai/reference_parser/issue_parser_spec.rb
@@ -9,6 +9,7 @@ describe Banzai::ReferenceParser::IssueParser do
let(:user) { create(:user) }
let(:issue) { create(:issue, project: project) }
let(:link) { empty_html_link }
+
subject { described_class.new(Banzai::RenderContext.new(project, user)) }
describe '#nodes_visible_to_user' do
diff --git a/spec/lib/banzai/reference_parser/snippet_parser_spec.rb b/spec/lib/banzai/reference_parser/snippet_parser_spec.rb
index 05dc1cb4d2d..6581ed0d7c3 100644
--- a/spec/lib/banzai/reference_parser/snippet_parser_spec.rb
+++ b/spec/lib/banzai/reference_parser/snippet_parser_spec.rb
@@ -200,6 +200,7 @@ describe Banzai::ReferenceParser::SnippetParser do
describe '#referenced_by' do
let(:snippet) { create(:snippet, project: project) }
+
describe 'when the link has a data-snippet attribute' do
context 'using an existing snippet ID' do
it 'returns an Array of snippets' do
diff --git a/spec/lib/banzai/reference_redactor_spec.rb b/spec/lib/banzai/reference_redactor_spec.rb
index 9e1a389d2db..0dec6395fb3 100644
--- a/spec/lib/banzai/reference_redactor_spec.rb
+++ b/spec/lib/banzai/reference_redactor_spec.rb
@@ -36,6 +36,7 @@ describe Banzai::ReferenceRedactor do
context 'when data-original attribute provided' do
let(:original_content) { '<code>foo</code>' }
+
it 'replaces redacted reference with original content' do
doc = Nokogiri::HTML.fragment("<a class='gfm' href='https://www.gitlab.com' data-reference-type='issue' data-original='#{original_content}'>bar</a>")
redactor.redact([doc])