summaryrefslogtreecommitdiff
path: root/spec/lib/banzai
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-31 21:06:28 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-31 21:06:28 +0000
commit8f210aebe1d740e8ee194f171f1f33a6e1fba313 (patch)
treef43c545801bb96fd0737f18493fb30ab92972627 /spec/lib/banzai
parent996f700997805b3590da8d8afdd19d193989078a (diff)
downloadgitlab-ce-8f210aebe1d740e8ee194f171f1f33a6e1fba313.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/banzai')
-rw-r--r--spec/lib/banzai/filter/wiki_link_filter_spec.rb13
-rw-r--r--spec/lib/banzai/pipeline/wiki_pipeline_spec.rb209
2 files changed, 94 insertions, 128 deletions
diff --git a/spec/lib/banzai/filter/wiki_link_filter_spec.rb b/spec/lib/banzai/filter/wiki_link_filter_spec.rb
index 7a83dc3ec1d..4587bd85939 100644
--- a/spec/lib/banzai/filter/wiki_link_filter_spec.rb
+++ b/spec/lib/banzai/filter/wiki_link_filter_spec.rb
@@ -11,10 +11,6 @@ describe Banzai::Filter::WikiLinkFilter do
let(:wiki) { ProjectWiki.new(project, user) }
let(:repository_upload_folder) { Wikis::CreateAttachmentService::ATTACHMENT_PATH }
- def upload_href(file_name)
- ::File.join(wiki.wiki_page_path, repository_upload_folder, file_name)
- end
-
it "doesn't rewrite absolute links" do
filtered_link = filter("<a href='http://example.com:8000/'>Link</a>", project_wiki: wiki).children[0]
@@ -32,12 +28,12 @@ describe Banzai::Filter::WikiLinkFilter do
it 'rewrites links' do
filtered_link = filter("<a href='#{repository_upload_folder}/a.test'>Link</a>", project_wiki: wiki).children[0]
- expect(filtered_link.attribute('href').value).to eq(upload_href "a.test")
+ expect(filtered_link.attribute('href').value).to eq("#{wiki.wiki_base_path}/#{repository_upload_folder}/a.test")
end
end
context 'with "img" html tag' do
- let(:path) { upload_href "a.jpg" }
+ let(:path) { "#{wiki.wiki_base_path}/#{repository_upload_folder}/a.jpg" }
context 'inside an "a" html tag' do
it 'rewrites links' do
@@ -61,7 +57,7 @@ describe Banzai::Filter::WikiLinkFilter do
it 'rewrites links' do
filtered_link = filter("<video src='#{repository_upload_folder}/a.mp4'></video>", project_wiki: wiki).children[0]
- expect(filtered_link.attribute('src').value).to eq(upload_href "a.mp4")
+ expect(filtered_link.attribute('src').value).to eq("#{wiki.wiki_base_path}/#{repository_upload_folder}/a.mp4")
end
end
@@ -69,8 +65,7 @@ describe Banzai::Filter::WikiLinkFilter do
it 'rewrites links' do
filtered_link = filter("<audio src='#{repository_upload_folder}/a.wav'></audio>", project_wiki: wiki).children[0]
- # expect(filtered_link.attribute('src').value).to eq("#{wiki.wiki_base_path}/#{repository_upload_folder}/a.wav")
- expect(filtered_link.attribute('src').value).to eq(upload_href "a.wav")
+ expect(filtered_link.attribute('src').value).to eq("#{wiki.wiki_base_path}/#{repository_upload_folder}/a.wav")
end
end
end
diff --git a/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb b/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb
index 7f60106cdca..26f2b0b0acf 100644
--- a/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb
+++ b/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb
@@ -3,12 +3,6 @@
require 'spec_helper'
describe Banzai::Pipeline::WikiPipeline do
- let_it_be(:namespace) { create(:namespace, name: "wiki_link_ns") }
- let_it_be(:project) { create(:project, :public, name: "wiki_link_project", namespace: namespace) }
- let_it_be(:project_wiki) { ProjectWiki.new(project, double(:user)) }
- let_it_be(:page) { build(:wiki_page, wiki: project_wiki, page: OpenStruct.new(url_path: 'nested/twice/start-page')) }
- let(:prefix) { project_wiki.wiki_page_path }
-
describe 'TableOfContents' do
it 'replaces the tag with the TableOfContentsFilter result' do
markdown = <<-MD.strip_heredoc
@@ -60,138 +54,132 @@ describe Banzai::Pipeline::WikiPipeline do
end
describe "Links" do
- shared_examples 'a correct link rewrite' do
- it 'rewrites links correctly' do
- output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug)
-
- expect(output).to include("href=\"#{page_href}\"")
- end
- end
-
- shared_examples 'link examples' do |test_name|
- let(:page_href) { "#{prefix}/#{expected_page_path}" }
-
- context "when GitLab is hosted at a #{test_name} URL" do
+ let(:namespace) { create(:namespace, name: "wiki_link_ns") }
+ let(:project) { create(:project, :public, name: "wiki_link_project", namespace: namespace) }
+ let(:project_wiki) { ProjectWiki.new(project, double(:user)) }
+ let(:page) { build(:wiki_page, wiki: project_wiki, page: OpenStruct.new(url_path: 'nested/twice/start-page')) }
+
+ { "when GitLab is hosted at a root URL" => '/',
+ "when GitLab is hosted at a relative URL" => '/nested/relative/gitlab' }.each do |test_name, relative_url_root|
+ context test_name do
before do
allow(Gitlab.config.gitlab).to receive(:relative_url_root).and_return(relative_url_root)
end
describe "linking to pages within the wiki" do
- let(:markdown) { "[Page](#{nesting}page#{extension})" }
-
context "when creating hierarchical links to the current directory" do
- let(:nesting) { './' }
- context 'non file links' do
- let(:extension) { '' }
- let(:expected_page_path) { 'nested/twice/page' }
- it_behaves_like 'a correct link rewrite'
+ it "rewrites non-file links to be at the scope of the current directory" do
+ markdown = "[Page](./page)"
+ output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug)
+
+ expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/nested/twice/page\"")
end
- context 'file-like links' do
- let(:extension) { '.md' }
- let(:expected_page_path) { 'nested/twice/page.md' }
- it_behaves_like 'a correct link rewrite'
+ it "rewrites file links to be at the scope of the current directory" do
+ markdown = "[Link to Page](./page.md)"
+ output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug)
+
+ expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/nested/twice/page.md\"")
end
end
context "when creating hierarchical links to the parent directory" do
- let(:nesting) { '../' }
- context "non file links" do
- let(:extension) { '' }
- let(:expected_page_path) { 'nested/page' }
- it_behaves_like 'a correct link rewrite'
+ it "rewrites non-file links to be at the scope of the parent directory" do
+ markdown = "[Link to Page](../page)"
+ output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug)
+
+ expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/nested/page\"")
end
- context "file-like links" do
- let(:extension) { '.md' }
- let(:expected_page_path) { 'nested/page.md' }
- it_behaves_like 'a correct link rewrite'
+ it "rewrites file links to be at the scope of the parent directory" do
+ markdown = "[Link to Page](../page.md)"
+ output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug)
+
+ expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/nested/page.md\"")
end
end
context "when creating hierarchical links to a sub-directory" do
- let(:nesting) { './subdirectory/' }
+ it "rewrites non-file links to be at the scope of the sub-directory" do
+ markdown = "[Link to Page](./subdirectory/page)"
+ output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug)
- context "non file links" do
- let(:extension) { '' }
- let(:expected_page_path) { 'nested/twice/subdirectory/page' }
- it_behaves_like 'a correct link rewrite'
+ expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/nested/twice/subdirectory/page\"")
end
- context 'file-like links' do
- let(:extension) { '.md' }
- let(:expected_page_path) { 'nested/twice/subdirectory/page.md' }
- it_behaves_like 'a correct link rewrite'
+ it "rewrites file links to be at the scope of the sub-directory" do
+ markdown = "[Link to Page](./subdirectory/page.md)"
+ output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug)
+
+ expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/nested/twice/subdirectory/page.md\"")
end
end
describe "when creating non-hierarchical links" do
- let(:nesting) { '' }
+ it 'rewrites non-file links to be at the scope of the wiki root' do
+ markdown = "[Link to Page](page)"
+ output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug)
- context 'non-file links' do
- let(:extension) { '' }
- let(:expected_page_path) { 'page' }
- it_behaves_like 'a correct link rewrite'
+ expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/page\"")
end
- context 'non-file links (with spaces)' do
- let(:extension) { ' slug' }
- let(:expected_page_path) { 'page%20slug' }
- it_behaves_like 'a correct link rewrite'
+ it 'rewrites non-file links (with spaces) to be at the scope of the wiki root' do
+ markdown = "[Link to Page](page slug)"
+ output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug)
+
+ expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/page%20slug\"")
end
- context "file links" do
- let(:extension) { '.md' }
- let(:expected_page_path) { 'nested/twice/page.md' }
- it_behaves_like 'a correct link rewrite'
+ it "rewrites file links to be at the scope of the current directory" do
+ markdown = "[Link to Page](page.md)"
+ output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug)
+
+ expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/nested/twice/page.md\"")
end
- context 'links with anchor' do
- let(:extension) { '#title' }
- let(:expected_page_path) { 'page#title' }
- it_behaves_like 'a correct link rewrite'
+ it 'rewrites links with anchor' do
+ markdown = '[Link to Header](start-page#title)'
+ output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug)
+
+ expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/start-page#title\"")
end
- context 'links (with spaces) with anchor' do
- let(:extension) { ' two#title' }
- let(:expected_page_path) { 'page%20two#title' }
- it_behaves_like 'a correct link rewrite'
+ it 'rewrites links (with spaces) with anchor' do
+ markdown = '[Link to Header](start page#title)'
+ output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug)
+
+ expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/start%20page#title\"")
end
end
describe "when creating root links" do
- let(:nesting) { '/' }
+ it 'rewrites non-file links to be at the scope of the wiki root' do
+ markdown = "[Link to Page](/page)"
+ output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug)
- context 'non-file links' do
- let(:extension) { '' }
- let(:expected_page_path) { 'page' }
- it_behaves_like 'a correct link rewrite'
+ expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/page\"")
end
- context 'file links' do
- let(:extension) { '.md' }
- let(:expected_page_path) { 'page.md' }
- it_behaves_like 'a correct link rewrite'
+ it 'rewrites file links to be at the scope of the wiki root' do
+ markdown = "[Link to Page](/page.md)"
+ output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug)
+
+ expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/page.md\"")
end
end
end
describe "linking to pages outside the wiki (absolute)" do
- let(:markdown) { "[Link to Page](http://example.com/page)" }
- let(:page_href) { 'http://example.com/page' }
- it_behaves_like 'a correct link rewrite'
+ it "doesn't rewrite links" do
+ markdown = "[Link to Page](http://example.com/page)"
+ output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug)
+
+ expect(output).to include('href="http://example.com/page"')
+ end
end
end
end
- include_examples 'link examples', :root do
- let(:relative_url_root) { '/' }
- end
-
- include_examples 'link examples', :relative do
- let(:relative_url_root) { '/nested/relative/gitlab' }
- end
-
describe "checking slug validity when assembling links" do
context "with a valid slug" do
let(:valid_slug) { "http://example.com" }
@@ -273,54 +261,37 @@ describe Banzai::Pipeline::WikiPipeline do
end
describe 'videos and audio' do
- def src(file_name)
- "#{prefix}/nested/twice/#{file_name}"
- end
-
- shared_examples 'correct video rewrite' do
- let(:markdown) { "![video_file](#{file_name})" }
- let(:video_fragment) { "<video src=\"#{prefix}/#{expected_file_path}\"" }
- let(:options) do
- {
- project: project,
- project_wiki: project_wiki,
- page_slug: page.slug
- }
- end
+ let_it_be(:namespace) { create(:namespace, name: "wiki_link_ns") }
+ let_it_be(:project) { create(:project, :public, name: "wiki_link_project", namespace: namespace) }
+ let_it_be(:project_wiki) { ProjectWiki.new(project, double(:user)) }
+ let_it_be(:page) { build(:wiki_page, wiki: project_wiki, page: OpenStruct.new(url_path: 'nested/twice/start-page')) }
- it 'generates video html structure' do
- output = described_class.to_html(markdown, options)
+ it 'generates video html structure' do
+ markdown = "![video_file](video_file_name.mp4)"
+ output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug)
- expect(output).to include(video_fragment)
- end
+ expect(output).to include('<video src="/wiki_link_ns/wiki_link_project/wikis/nested/twice/video_file_name.mp4"')
end
- context 'underscores' do
- let(:file_name) { 'video_file_name.mp4' }
- let(:expected_file_path) { 'nested/twice/video_file_name.mp4' }
- it_behaves_like 'correct video rewrite'
- end
+ it 'rewrites and replaces video links names with white spaces to %20' do
+ markdown = "![video file](video file name.mp4)"
+ output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug)
- context 'spaces' do
- let(:file_name) { 'video file name.mp4' }
- let(:expected_file_path) { 'nested/twice/video%20file%20name.mp4' }
- it_behaves_like 'correct video rewrite'
+ expect(output).to include('<video src="/wiki_link_ns/wiki_link_project/wikis/nested/twice/video%20file%20name.mp4"')
end
it 'generates audio html structure' do
markdown = "![audio_file](audio_file_name.wav)"
- safe_name = "audio_file_name.wav"
output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug)
- expect(output).to include(%Q'<audio src="#{src(safe_name)}"')
+ expect(output).to include('<audio src="/wiki_link_ns/wiki_link_project/wikis/nested/twice/audio_file_name.wav"')
end
it 'rewrites and replaces audio links names with white spaces to %20' do
markdown = "![audio file](audio file name.wav)"
- safe_name = "audio%20file%20name.wav"
output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug)
- expect(output).to include(%Q'<audio src="#{src(safe_name)}"')
+ expect(output).to include('<audio src="/wiki_link_ns/wiki_link_project/wikis/nested/twice/audio%20file%20name.wav"')
end
end
end