Commit 10cab5dc authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'group-wikis-markdown' into 'master'

Use wiki instead of project_wiki in Banzai

See merge request gitlab-org/gitlab!32675
parents ca7d8a03 b9c25013
...@@ -32,7 +32,7 @@ module PreviewMarkdown ...@@ -32,7 +32,7 @@ module PreviewMarkdown
def markdown_context_params def markdown_context_params
case controller_name case controller_name
when 'wikis' then { pipeline: :wiki, project_wiki: @project_wiki, page_slug: params[:id] } when 'wikis' then { pipeline: :wiki, wiki: @project_wiki, page_slug: params[:id] }
when 'snippets' then { skip_project_check: true } when 'snippets' then { skip_project_check: true }
when 'groups' then { group: group } when 'groups' then { group: group }
when 'projects' then projects_filter_params when 'projects' then projects_filter_params
......
...@@ -129,7 +129,7 @@ module MarkupHelper ...@@ -129,7 +129,7 @@ module MarkupHelper
context.merge!( context.merge!(
pipeline: :wiki, pipeline: :wiki,
project: @project, project: @project,
project_wiki: @project_wiki, wiki: @project_wiki,
repository: @project_wiki.repository, repository: @project_wiki.repository,
page_slug: wiki_page.slug, page_slug: wiki_page.slug,
issuable_state_filter_enabled: true issuable_state_filter_enabled: true
......
...@@ -30,7 +30,7 @@ module Banzai ...@@ -30,7 +30,7 @@ module Banzai
# Note: the table of contents tag is now handled by TableOfContentsTagFilter # Note: the table of contents tag is now handled by TableOfContentsTagFilter
# #
# Context options: # Context options:
# :project_wiki (required) - Current project wiki. # :wiki [Wiki] (required) - Current wiki instance.
# #
class GollumTagsFilter < HTML::Pipeline::Filter class GollumTagsFilter < HTML::Pipeline::Filter
include ActionView::Helpers::TagHelper include ActionView::Helpers::TagHelper
...@@ -100,8 +100,8 @@ module Banzai ...@@ -100,8 +100,8 @@ module Banzai
if url?(content) if url?(content)
path = content path = content
elsif file = project_wiki.find_file(content) elsif file = wiki.find_file(content)
path = ::File.join project_wiki_base_path, file.path path = ::File.join(wiki_base_path, file.path)
end end
if path if path
...@@ -134,25 +134,25 @@ module Banzai ...@@ -134,25 +134,25 @@ module Banzai
if url?(reference) if url?(reference)
reference reference
else else
::File.join(project_wiki_base_path, reference) ::File.join(wiki_base_path, reference)
end end
content_tag(:a, name || reference, href: href, class: 'gfm') content_tag(:a, name || reference, href: href, class: 'gfm')
end end
def project_wiki def wiki
context[:project_wiki] context[:wiki]
end end
def project_wiki_base_path def wiki_base_path
project_wiki && project_wiki.wiki_base_path wiki&.wiki_base_path
end end
# Ensure that a :project_wiki key exists in context # Ensure that a :wiki key exists in context
# #
# Note that while the key might exist, its value could be nil! # Note that while the key might exist, its value could be nil!
def validate def validate
needs :project_wiki needs :wiki
end end
end end
end end
......
...@@ -10,7 +10,7 @@ module Banzai ...@@ -10,7 +10,7 @@ module Banzai
# :commit # :commit
# :current_user # :current_user
# :project # :project
# :project_wiki # :wiki
# :ref # :ref
# :requested_path # :requested_path
# :system_note # :system_note
...@@ -53,7 +53,7 @@ module Banzai ...@@ -53,7 +53,7 @@ module Banzai
def linkable_files? def linkable_files?
strong_memoize(:linkable_files) do strong_memoize(:linkable_files) do
context[:project_wiki].nil? && repository.try(:exists?) && !repository.empty? context[:wiki].nil? && repository.try(:exists?) && !repository.empty?
end end
end end
......
...@@ -6,12 +6,12 @@ module Banzai ...@@ -6,12 +6,12 @@ module Banzai
# Rewrite rules are documented in the `WikiPipeline` spec. # Rewrite rules are documented in the `WikiPipeline` spec.
# #
# Context options: # Context options:
# :project_wiki # :wiki
class WikiLinkFilter < HTML::Pipeline::Filter class WikiLinkFilter < HTML::Pipeline::Filter
include Gitlab::Utils::SanitizeNodeLink include Gitlab::Utils::SanitizeNodeLink
def call def call
return doc unless project_wiki? return doc unless wiki?
doc.search('a:not(.gfm)').each { |el| process_link(el.attribute('href'), el) } doc.search('a:not(.gfm)').each { |el| process_link(el.attribute('href'), el) }
...@@ -33,8 +33,8 @@ module Banzai ...@@ -33,8 +33,8 @@ module Banzai
remove_unsafe_links({ node: node }, remove_invalid_links: false) remove_unsafe_links({ node: node }, remove_invalid_links: false)
end end
def project_wiki? def wiki?
!context[:project_wiki].nil? !context[:wiki].nil?
end end
def process_link_attr(html_attr) def process_link_attr(html_attr)
...@@ -46,7 +46,7 @@ module Banzai ...@@ -46,7 +46,7 @@ module Banzai
end end
def apply_rewrite_rules(link_string) def apply_rewrite_rules(link_string)
Rewriter.new(link_string, wiki: context[:project_wiki], slug: context[:page_slug]).apply_rules Rewriter.new(link_string, wiki: context[:wiki], slug: context[:page_slug]).apply_rules
end end
end end
end end
......
...@@ -157,7 +157,7 @@ describe 'Copy as GFM', :js do ...@@ -157,7 +157,7 @@ describe 'Copy as GFM', :js do
GFM GFM
pipeline: :wiki, pipeline: :wiki,
project_wiki: @project.wiki wiki: @project.wiki
) )
verify( verify(
......
...@@ -269,15 +269,15 @@ describe 'GitLab Markdown', :aggregate_failures do ...@@ -269,15 +269,15 @@ describe 'GitLab Markdown', :aggregate_failures do
context 'wiki pipeline' do context 'wiki pipeline' do
before do before do
@project_wiki = @feat.project_wiki @wiki = @feat.wiki
@project_wiki_page = @feat.project_wiki_page @wiki_page = @feat.wiki_page
path = 'images/example.jpg' path = 'images/example.jpg'
gitaly_wiki_file = Gitlab::GitalyClient::WikiFile.new(path: path) gitaly_wiki_file = Gitlab::GitalyClient::WikiFile.new(path: path)
expect(@project_wiki).to receive(:find_file).with(path).and_return(Gitlab::Git::WikiFile.new(gitaly_wiki_file)) expect(@wiki).to receive(:find_file).with(path).and_return(Gitlab::Git::WikiFile.new(gitaly_wiki_file))
allow(@project_wiki).to receive(:wiki_base_path) { '/namespace1/gitlabhq/wikis' } allow(@wiki).to receive(:wiki_base_path) { '/namespace1/gitlabhq/wikis' }
@html = markdown(@feat.raw_markdown, { pipeline: :wiki, project_wiki: @project_wiki, page_slug: @project_wiki_page.slug }) @html = markdown(@feat.raw_markdown, { pipeline: :wiki, wiki: @wiki, page_slug: @wiki_page.slug })
end end
it_behaves_like 'all pipelines' it_behaves_like 'all pipelines'
......
...@@ -317,7 +317,7 @@ describe MarkupHelper do ...@@ -317,7 +317,7 @@ describe MarkupHelper do
let(:wiki_repository) { double('Repository') } let(:wiki_repository) { double('Repository') }
let(:context) do let(:context) do
{ {
pipeline: :wiki, project: project, project_wiki: wiki, pipeline: :wiki, project: project, wiki: wiki,
page_slug: 'nested/page', issuable_state_filter_enabled: true, page_slug: 'nested/page', issuable_state_filter_enabled: true,
repository: wiki_repository repository: wiki_repository
} }
......
...@@ -7,11 +7,11 @@ describe Banzai::Filter::GollumTagsFilter do ...@@ -7,11 +7,11 @@ describe Banzai::Filter::GollumTagsFilter do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:user) { double } let(:user) { double }
let(:project_wiki) { ProjectWiki.new(project, user) } let(:wiki) { ProjectWiki.new(project, user) }
describe 'validation' do describe 'validation' do
it 'ensure that a :project_wiki key exists in context' do it 'ensure that a :wiki key exists in context' do
expect { filter("See [[images/image.jpg]]", {}) }.to raise_error ArgumentError, "Missing context keys for Banzai::Filter::GollumTagsFilter: :project_wiki" expect { filter("See [[images/image.jpg]]", {}) }.to raise_error ArgumentError, "Missing context keys for Banzai::Filter::GollumTagsFilter: :wiki"
end end
end end
...@@ -23,19 +23,19 @@ describe Banzai::Filter::GollumTagsFilter do ...@@ -23,19 +23,19 @@ describe Banzai::Filter::GollumTagsFilter do
path: 'images/image.jpg', path: 'images/image.jpg',
raw_data: '') raw_data: '')
wiki_file = Gitlab::Git::WikiFile.new(gollum_file_double) wiki_file = Gitlab::Git::WikiFile.new(gollum_file_double)
expect(project_wiki).to receive(:find_file).with('images/image.jpg').and_return(wiki_file) expect(wiki).to receive(:find_file).with('images/image.jpg').and_return(wiki_file)
tag = '[[images/image.jpg]]' tag = '[[images/image.jpg]]'
doc = filter("See #{tag}", project_wiki: project_wiki) doc = filter("See #{tag}", wiki: wiki)
expect(doc.at_css('img')['data-src']).to eq "#{project_wiki.wiki_base_path}/images/image.jpg" expect(doc.at_css('img')['data-src']).to eq "#{wiki.wiki_base_path}/images/image.jpg"
end end
it 'does not creates img tag if image does not exist' do it 'does not creates img tag if image does not exist' do
expect(project_wiki).to receive(:find_file).with('images/image.jpg').and_return(nil) expect(wiki).to receive(:find_file).with('images/image.jpg').and_return(nil)
tag = '[[images/image.jpg]]' tag = '[[images/image.jpg]]'
doc = filter("See #{tag}", project_wiki: project_wiki) doc = filter("See #{tag}", wiki: wiki)
expect(doc.css('img').size).to eq 0 expect(doc.css('img').size).to eq 0
end end
...@@ -44,14 +44,14 @@ describe Banzai::Filter::GollumTagsFilter do ...@@ -44,14 +44,14 @@ describe Banzai::Filter::GollumTagsFilter do
context 'linking external images' do context 'linking external images' do
it 'creates img tag for valid URL' do it 'creates img tag for valid URL' do
tag = '[[http://example.com/image.jpg]]' tag = '[[http://example.com/image.jpg]]'
doc = filter("See #{tag}", project_wiki: project_wiki) doc = filter("See #{tag}", wiki: wiki)
expect(doc.at_css('img')['data-src']).to eq "http://example.com/image.jpg" expect(doc.at_css('img')['data-src']).to eq "http://example.com/image.jpg"
end end
it 'does not creates img tag for invalid URL' do it 'does not creates img tag for invalid URL' do
tag = '[[http://example.com/image.pdf]]' tag = '[[http://example.com/image.pdf]]'
doc = filter("See #{tag}", project_wiki: project_wiki) doc = filter("See #{tag}", wiki: wiki)
expect(doc.css('img').size).to eq 0 expect(doc.css('img').size).to eq 0
end end
...@@ -60,7 +60,7 @@ describe Banzai::Filter::GollumTagsFilter do ...@@ -60,7 +60,7 @@ describe Banzai::Filter::GollumTagsFilter do
context 'linking external resources' do context 'linking external resources' do
it "the created link's text will be equal to the resource's text" do it "the created link's text will be equal to the resource's text" do
tag = '[[http://example.com]]' tag = '[[http://example.com]]'
doc = filter("See #{tag}", project_wiki: project_wiki) doc = filter("See #{tag}", wiki: wiki)
expect(doc.at_css('a').text).to eq 'http://example.com' expect(doc.at_css('a').text).to eq 'http://example.com'
expect(doc.at_css('a')['href']).to eq 'http://example.com' expect(doc.at_css('a')['href']).to eq 'http://example.com'
...@@ -68,7 +68,7 @@ describe Banzai::Filter::GollumTagsFilter do ...@@ -68,7 +68,7 @@ describe Banzai::Filter::GollumTagsFilter do
it "the created link's text will be link-text" do it "the created link's text will be link-text" do
tag = '[[link-text|http://example.com/pdfs/gollum.pdf]]' tag = '[[link-text|http://example.com/pdfs/gollum.pdf]]'
doc = filter("See #{tag}", project_wiki: project_wiki) doc = filter("See #{tag}", wiki: wiki)
expect(doc.at_css('a').text).to eq 'link-text' expect(doc.at_css('a').text).to eq 'link-text'
expect(doc.at_css('a')['href']).to eq 'http://example.com/pdfs/gollum.pdf' expect(doc.at_css('a')['href']).to eq 'http://example.com/pdfs/gollum.pdf'
...@@ -78,8 +78,8 @@ describe Banzai::Filter::GollumTagsFilter do ...@@ -78,8 +78,8 @@ describe Banzai::Filter::GollumTagsFilter do
context 'linking internal resources' do context 'linking internal resources' do
it "the created link's text includes the resource's text and wiki base path" do it "the created link's text includes the resource's text and wiki base path" do
tag = '[[wiki-slug]]' tag = '[[wiki-slug]]'
doc = filter("See #{tag}", project_wiki: project_wiki) doc = filter("See #{tag}", wiki: wiki)
expected_path = ::File.join(project_wiki.wiki_base_path, 'wiki-slug') expected_path = ::File.join(wiki.wiki_base_path, 'wiki-slug')
expect(doc.at_css('a').text).to eq 'wiki-slug' expect(doc.at_css('a').text).to eq 'wiki-slug'
expect(doc.at_css('a')['href']).to eq expected_path expect(doc.at_css('a')['href']).to eq expected_path
...@@ -87,15 +87,15 @@ describe Banzai::Filter::GollumTagsFilter do ...@@ -87,15 +87,15 @@ describe Banzai::Filter::GollumTagsFilter do
it "the created link's text will be link-text" do it "the created link's text will be link-text" do
tag = '[[link-text|wiki-slug]]' tag = '[[link-text|wiki-slug]]'
doc = filter("See #{tag}", project_wiki: project_wiki) doc = filter("See #{tag}", wiki: wiki)
expected_path = ::File.join(project_wiki.wiki_base_path, 'wiki-slug') expected_path = ::File.join(wiki.wiki_base_path, 'wiki-slug')
expect(doc.at_css('a').text).to eq 'link-text' expect(doc.at_css('a').text).to eq 'link-text'
expect(doc.at_css('a')['href']).to eq expected_path expect(doc.at_css('a')['href']).to eq expected_path
end end
it "inside back ticks will be exempt from linkification" do it "inside back ticks will be exempt from linkification" do
doc = filter('<code>[[link-in-backticks]]</code>', project_wiki: project_wiki) doc = filter('<code>[[link-in-backticks]]</code>', wiki: wiki)
expect(doc.at_css('code').text).to eq '[[link-in-backticks]]' expect(doc.at_css('code').text).to eq '[[link-in-backticks]]'
end end
......
...@@ -12,7 +12,7 @@ describe Banzai::Filter::RepositoryLinkFilter do ...@@ -12,7 +12,7 @@ describe Banzai::Filter::RepositoryLinkFilter do
project: project, project: project,
current_user: user, current_user: user,
group: group, group: group,
project_wiki: project_wiki, wiki: wiki,
ref: ref, ref: ref,
requested_path: requested_path, requested_path: requested_path,
only_path: only_path only_path: only_path
...@@ -53,7 +53,7 @@ describe Banzai::Filter::RepositoryLinkFilter do ...@@ -53,7 +53,7 @@ describe Banzai::Filter::RepositoryLinkFilter do
let(:project_path) { project.full_path } let(:project_path) { project.full_path }
let(:ref) { 'markdown' } let(:ref) { 'markdown' }
let(:commit) { project.commit(ref) } let(:commit) { project.commit(ref) }
let(:project_wiki) { nil } let(:wiki) { nil }
let(:requested_path) { '/' } let(:requested_path) { '/' }
let(:only_path) { true } let(:only_path) { true }
...@@ -94,8 +94,8 @@ describe Banzai::Filter::RepositoryLinkFilter do ...@@ -94,8 +94,8 @@ describe Banzai::Filter::RepositoryLinkFilter do
end end
end end
context 'with a project_wiki' do context 'with a wiki' do
let(:project_wiki) { double('ProjectWiki') } let(:wiki) { double('ProjectWiki') }
include_examples :preserve_unchanged include_examples :preserve_unchanged
end end
......
...@@ -12,13 +12,13 @@ describe Banzai::Filter::WikiLinkFilter do ...@@ -12,13 +12,13 @@ describe Banzai::Filter::WikiLinkFilter do
let(:repository_upload_folder) { Wikis::CreateAttachmentService::ATTACHMENT_PATH } let(:repository_upload_folder) { Wikis::CreateAttachmentService::ATTACHMENT_PATH }
it "doesn't rewrite absolute links" do it "doesn't rewrite absolute links" do
filtered_link = filter("<a href='http://example.com:8000/'>Link</a>", project_wiki: wiki).children[0] filtered_link = filter("<a href='http://example.com:8000/'>Link</a>", wiki: wiki).children[0]
expect(filtered_link.attribute('href').value).to eq('http://example.com:8000/') expect(filtered_link.attribute('href').value).to eq('http://example.com:8000/')
end end
it "doesn't rewrite links to project uploads" do it "doesn't rewrite links to project uploads" do
filtered_link = filter("<a href='/uploads/a.test'>Link</a>", project_wiki: wiki).children[0] filtered_link = filter("<a href='/uploads/a.test'>Link</a>", wiki: wiki).children[0]
expect(filtered_link.attribute('href').value).to eq('/uploads/a.test') expect(filtered_link.attribute('href').value).to eq('/uploads/a.test')
end end
...@@ -26,7 +26,7 @@ describe Banzai::Filter::WikiLinkFilter do ...@@ -26,7 +26,7 @@ describe Banzai::Filter::WikiLinkFilter do
describe "when links point to the #{Wikis::CreateAttachmentService::ATTACHMENT_PATH} folder" do describe "when links point to the #{Wikis::CreateAttachmentService::ATTACHMENT_PATH} folder" do
context 'with an "a" html tag' do context 'with an "a" html tag' do
it 'rewrites links' do it 'rewrites links' do
filtered_link = filter("<a href='#{repository_upload_folder}/a.test'>Link</a>", project_wiki: wiki).children[0] filtered_link = filter("<a href='#{repository_upload_folder}/a.test'>Link</a>", wiki: wiki).children[0]
expect(filtered_link.attribute('href').value).to eq("#{wiki.wiki_base_path}/#{repository_upload_folder}/a.test") expect(filtered_link.attribute('href').value).to eq("#{wiki.wiki_base_path}/#{repository_upload_folder}/a.test")
end end
...@@ -37,7 +37,7 @@ describe Banzai::Filter::WikiLinkFilter do ...@@ -37,7 +37,7 @@ describe Banzai::Filter::WikiLinkFilter do
context 'inside an "a" html tag' do context 'inside an "a" html tag' do
it 'rewrites links' do it 'rewrites links' do
filtered_elements = filter("<a href='#{repository_upload_folder}/a.jpg'><img src='#{repository_upload_folder}/a.jpg'>example</img></a>", project_wiki: wiki) filtered_elements = filter("<a href='#{repository_upload_folder}/a.jpg'><img src='#{repository_upload_folder}/a.jpg'>example</img></a>", wiki: wiki)
expect(filtered_elements.search('img').first.attribute('src').value).to eq(path) expect(filtered_elements.search('img').first.attribute('src').value).to eq(path)
expect(filtered_elements.search('a').first.attribute('href').value).to eq(path) expect(filtered_elements.search('a').first.attribute('href').value).to eq(path)
...@@ -46,7 +46,7 @@ describe Banzai::Filter::WikiLinkFilter do ...@@ -46,7 +46,7 @@ describe Banzai::Filter::WikiLinkFilter do
context 'outside an "a" html tag' do context 'outside an "a" html tag' do
it 'rewrites links' do it 'rewrites links' do
filtered_link = filter("<img src='#{repository_upload_folder}/a.jpg'>example</img>", project_wiki: wiki).children[0] filtered_link = filter("<img src='#{repository_upload_folder}/a.jpg'>example</img>", wiki: wiki).children[0]
expect(filtered_link.attribute('src').value).to eq(path) expect(filtered_link.attribute('src').value).to eq(path)
end end
...@@ -55,7 +55,7 @@ describe Banzai::Filter::WikiLinkFilter do ...@@ -55,7 +55,7 @@ describe Banzai::Filter::WikiLinkFilter do
context 'with "video" html tag' do context 'with "video" html tag' do
it 'rewrites links' do it 'rewrites links' do
filtered_link = filter("<video src='#{repository_upload_folder}/a.mp4'></video>", project_wiki: wiki).children[0] filtered_link = filter("<video src='#{repository_upload_folder}/a.mp4'></video>", wiki: wiki).children[0]
expect(filtered_link.attribute('src').value).to eq("#{wiki.wiki_base_path}/#{repository_upload_folder}/a.mp4") expect(filtered_link.attribute('src').value).to eq("#{wiki.wiki_base_path}/#{repository_upload_folder}/a.mp4")
end end
...@@ -63,7 +63,7 @@ describe Banzai::Filter::WikiLinkFilter do ...@@ -63,7 +63,7 @@ describe Banzai::Filter::WikiLinkFilter do
context 'with "audio" html tag' do context 'with "audio" html tag' do
it 'rewrites links' do it 'rewrites links' do
filtered_link = filter("<audio src='#{repository_upload_folder}/a.wav'></audio>", project_wiki: wiki).children[0] filtered_link = filter("<audio src='#{repository_upload_folder}/a.wav'></audio>", 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("#{wiki.wiki_base_path}/#{repository_upload_folder}/a.wav")
end end
...@@ -75,7 +75,7 @@ describe Banzai::Filter::WikiLinkFilter do ...@@ -75,7 +75,7 @@ describe Banzai::Filter::WikiLinkFilter do
invalid_links.each do |invalid_link| invalid_links.each do |invalid_link|
it "doesn't rewrite invalid invalid_links like #{invalid_link}" do it "doesn't rewrite invalid invalid_links like #{invalid_link}" do
filtered_link = filter("<a href='#{invalid_link}'>Link</a>", project_wiki: wiki).children[0] filtered_link = filter("<a href='#{invalid_link}'>Link</a>", wiki: wiki).children[0]
expect(filtered_link.attribute('href').value).to eq(invalid_link) expect(filtered_link.attribute('href').value).to eq(invalid_link)
end end
......
...@@ -13,7 +13,7 @@ describe Banzai::Pipeline::WikiPipeline do ...@@ -13,7 +13,7 @@ describe Banzai::Pipeline::WikiPipeline do
Foo Foo
MD MD
result = described_class.call(markdown, project: spy, project_wiki: spy) result = described_class.call(markdown, project: spy, wiki: spy)
aggregate_failures do aggregate_failures do
expect(result[:output].text).not_to include '[[' expect(result[:output].text).not_to include '[['
...@@ -31,7 +31,7 @@ describe Banzai::Pipeline::WikiPipeline do ...@@ -31,7 +31,7 @@ describe Banzai::Pipeline::WikiPipeline do
Foo Foo
MD MD
output = described_class.to_html(markdown, project: spy, project_wiki: spy) output = described_class.to_html(markdown, project: spy, wiki: spy)
expect(output).to include('[[<em>toc</em>]]') expect(output).to include('[[<em>toc</em>]]')
end end
...@@ -44,7 +44,7 @@ describe Banzai::Pipeline::WikiPipeline do ...@@ -44,7 +44,7 @@ describe Banzai::Pipeline::WikiPipeline do
Foo Foo
MD MD
output = described_class.to_html(markdown, project: spy, project_wiki: spy) output = described_class.to_html(markdown, project: spy, wiki: spy)
aggregate_failures do aggregate_failures do
expect(output).not_to include('<ul>') expect(output).not_to include('<ul>')
...@@ -56,8 +56,8 @@ describe Banzai::Pipeline::WikiPipeline do ...@@ -56,8 +56,8 @@ describe Banzai::Pipeline::WikiPipeline do
describe "Links" do describe "Links" do
let(:namespace) { create(:namespace, name: "wiki_link_ns") } let(:namespace) { create(:namespace, name: "wiki_link_ns") }
let(:project) { create(:project, :public, name: "wiki_link_project", namespace: namespace) } let(:project) { create(:project, :public, name: "wiki_link_project", namespace: namespace) }
let(:project_wiki) { ProjectWiki.new(project, double(:user)) } let(:wiki) { ProjectWiki.new(project, double(:user)) }
let(:page) { build(:wiki_page, wiki: project_wiki, title: 'nested/twice/start-page') } let(:page) { build(:wiki_page, wiki: wiki, title: 'nested/twice/start-page') }
{ 'when GitLab is hosted at a root URL' => '', { '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| 'when GitLab is hosted at a relative URL' => '/nested/relative/gitlab' }.each do |test_name, relative_url_root|
...@@ -70,14 +70,14 @@ describe Banzai::Pipeline::WikiPipeline do ...@@ -70,14 +70,14 @@ describe Banzai::Pipeline::WikiPipeline do
context "when creating hierarchical links to the current directory" do context "when creating hierarchical links to the current directory" do
it "rewrites non-file links to be at the scope of the current directory" do it "rewrites non-file links to be at the scope of the current directory" do
markdown = "[Page](./page)" markdown = "[Page](./page)"
output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/page\"") expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/page\"")
end end
it "rewrites file links to be at the scope of the current directory" do it "rewrites file links to be at the scope of the current directory" do
markdown = "[Link to Page](./page.md)" markdown = "[Link to Page](./page.md)"
output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/page.md\"") expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/page.md\"")
end end
...@@ -86,14 +86,14 @@ describe Banzai::Pipeline::WikiPipeline do ...@@ -86,14 +86,14 @@ describe Banzai::Pipeline::WikiPipeline do
context "when creating hierarchical links to the parent directory" do context "when creating hierarchical links to the parent directory" do
it "rewrites non-file links to be at the scope of the parent directory" do it "rewrites non-file links to be at the scope of the parent directory" do
markdown = "[Link to Page](../page)" markdown = "[Link to Page](../page)"
output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/page\"") expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/page\"")
end end
it "rewrites file links to be at the scope of the parent directory" do it "rewrites file links to be at the scope of the parent directory" do
markdown = "[Link to Page](../page.md)" markdown = "[Link to Page](../page.md)"
output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/page.md\"") expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/page.md\"")
end end
...@@ -102,14 +102,14 @@ describe Banzai::Pipeline::WikiPipeline do ...@@ -102,14 +102,14 @@ describe Banzai::Pipeline::WikiPipeline do
context "when creating hierarchical links to a sub-directory" do context "when creating hierarchical links to a sub-directory" do
it "rewrites non-file links to be at the scope of the sub-directory" do it "rewrites non-file links to be at the scope of the sub-directory" do
markdown = "[Link to Page](./subdirectory/page)" markdown = "[Link to Page](./subdirectory/page)"
output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/subdirectory/page\"") expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/subdirectory/page\"")
end end
it "rewrites file links to be at the scope of the sub-directory" do it "rewrites file links to be at the scope of the sub-directory" do
markdown = "[Link to Page](./subdirectory/page.md)" markdown = "[Link to Page](./subdirectory/page.md)"
output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) output = described_class.to_html(markdown, project: project, wiki: 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\"") expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/subdirectory/page.md\"")
end end
...@@ -118,35 +118,35 @@ describe Banzai::Pipeline::WikiPipeline do ...@@ -118,35 +118,35 @@ describe Banzai::Pipeline::WikiPipeline do
describe "when creating non-hierarchical links" do describe "when creating non-hierarchical links" do
it 'rewrites non-file links to be at the scope of the wiki root' do it 'rewrites non-file links to be at the scope of the wiki root' do
markdown = "[Link to Page](page)" markdown = "[Link to Page](page)"
output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/page\"") expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/page\"")
end end
it 'rewrites non-file links (with spaces) to be at the scope of the wiki root' do it 'rewrites non-file links (with spaces) to be at the scope of the wiki root' do
markdown = "[Link to Page](page slug)" markdown = "[Link to Page](page slug)"
output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/page%20slug\"") expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/page%20slug\"")
end end
it "rewrites file links to be at the scope of the current directory" do it "rewrites file links to be at the scope of the current directory" do
markdown = "[Link to Page](page.md)" markdown = "[Link to Page](page.md)"
output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/page.md\"") expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/page.md\"")
end end
it 'rewrites links with anchor' do it 'rewrites links with anchor' do
markdown = '[Link to Header](start-page#title)' markdown = '[Link to Header](start-page#title)'
output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/start-page#title\"") expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/start-page#title\"")
end end
it 'rewrites links (with spaces) with anchor' do it 'rewrites links (with spaces) with anchor' do
markdown = '[Link to Header](start page#title)' markdown = '[Link to Header](start page#title)'
output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/start%20page#title\"") expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/start%20page#title\"")
end end
...@@ -155,14 +155,14 @@ describe Banzai::Pipeline::WikiPipeline do ...@@ -155,14 +155,14 @@ describe Banzai::Pipeline::WikiPipeline do
describe "when creating root links" do describe "when creating root links" do
it 'rewrites non-file links to be at the scope of the wiki root' do it 'rewrites non-file links to be at the scope of the wiki root' do
markdown = "[Link to Page](/page)" markdown = "[Link to Page](/page)"
output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/page\"") expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/page\"")
end end
it 'rewrites file links to be at the scope of the wiki root' do it 'rewrites file links to be at the scope of the wiki root' do
markdown = "[Link to Page](/page.md)" markdown = "[Link to Page](/page.md)"
output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/page.md\"") expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/page.md\"")
end end
...@@ -172,7 +172,7 @@ describe Banzai::Pipeline::WikiPipeline do ...@@ -172,7 +172,7 @@ describe Banzai::Pipeline::WikiPipeline do
describe "linking to pages outside the wiki (absolute)" do describe "linking to pages outside the wiki (absolute)" do
it "doesn't rewrite links" do it "doesn't rewrite links" do
markdown = "[Link to Page](http://example.com/page)" markdown = "[Link to Page](http://example.com/page)"
output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
expect(output).to include('href="http://example.com/page"') expect(output).to include('href="http://example.com/page"')
end end
...@@ -188,7 +188,7 @@ describe Banzai::Pipeline::WikiPipeline do ...@@ -188,7 +188,7 @@ describe Banzai::Pipeline::WikiPipeline do
output = described_class.to_html( output = described_class.to_html(
"[Link](./alert(1);)", "[Link](./alert(1);)",
project: project, project: project,
project_wiki: project_wiki, wiki: wiki,
page_slug: valid_slug page_slug: valid_slug
) )
...@@ -199,7 +199,7 @@ describe Banzai::Pipeline::WikiPipeline do ...@@ -199,7 +199,7 @@ describe Banzai::Pipeline::WikiPipeline do
output = described_class.to_html( output = described_class.to_html(
"[Link](../alert(1);)", "[Link](../alert(1);)",
project: project, project: project,
project_wiki: project_wiki, wiki: wiki,
page_slug: valid_slug page_slug: valid_slug
) )
...@@ -236,7 +236,7 @@ describe Banzai::Pipeline::WikiPipeline do ...@@ -236,7 +236,7 @@ describe Banzai::Pipeline::WikiPipeline do
output = described_class.to_html( output = described_class.to_html(
"[Link](./#{link})", "[Link](./#{link})",
project: project, project: project,
project_wiki: project_wiki, wiki: wiki,
page_slug: slug page_slug: slug
) )
...@@ -247,7 +247,7 @@ describe Banzai::Pipeline::WikiPipeline do ...@@ -247,7 +247,7 @@ describe Banzai::Pipeline::WikiPipeline do
output = described_class.to_html( output = described_class.to_html(
"[Link](../#{link})", "[Link](../#{link})",
project: project, project: project,
project_wiki: project_wiki, wiki: wiki,
page_slug: slug page_slug: slug
) )
...@@ -263,33 +263,33 @@ describe Banzai::Pipeline::WikiPipeline do ...@@ -263,33 +263,33 @@ describe Banzai::Pipeline::WikiPipeline do
describe 'videos and audio' do describe 'videos and audio' do
let_it_be(:namespace) { create(:namespace, name: "wiki_link_ns") } 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) { create(:project, :public, name: "wiki_link_project", namespace: namespace) }
let_it_be(:project_wiki) { ProjectWiki.new(project, double(:user)) } let_it_be(:wiki) { ProjectWiki.new(project, double(:user)) }
let_it_be(:page) { build(:wiki_page, wiki: project_wiki, title: 'nested/twice/start-page') } let_it_be(:page) { build(:wiki_page, wiki: wiki, title: 'nested/twice/start-page') }
it 'generates video html structure' do it 'generates video html structure' do
markdown = "![video_file](video_file_name.mp4)" markdown = "![video_file](video_file_name.mp4)"
output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
expect(output).to include('<video src="/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/video_file_name.mp4"') expect(output).to include('<video src="/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/video_file_name.mp4"')
end end
it 'rewrites and replaces video links names with white spaces to %20' do it 'rewrites and replaces video links names with white spaces to %20' do
markdown = "![video file](video file name.mp4)" markdown = "![video file](video file name.mp4)"
output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
expect(output).to include('<video src="/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/video%20file%20name.mp4"') expect(output).to include('<video src="/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/video%20file%20name.mp4"')
end end
it 'generates audio html structure' do it 'generates audio html structure' do
markdown = "![audio_file](audio_file_name.wav)" markdown = "![audio_file](audio_file_name.wav)"
output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
expect(output).to include('<audio src="/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/audio_file_name.wav"') expect(output).to include('<audio src="/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/audio_file_name.wav"')
end end
it 'rewrites and replaces audio links names with white spaces to %20' do it 'rewrites and replaces audio links names with white spaces to %20' do
markdown = "![audio file](audio file name.wav)" markdown = "![audio file](audio file name.wav)"
output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
expect(output).to include('<audio src="/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/audio%20file%20name.wav"') expect(output).to include('<audio src="/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/audio%20file%20name.wav"')
end end
......
...@@ -36,12 +36,12 @@ class MarkdownFeature ...@@ -36,12 +36,12 @@ class MarkdownFeature
end end
end end
def project_wiki def wiki
@project_wiki ||= ProjectWiki.new(project, user) @wiki ||= ProjectWiki.new(project, user)
end end
def project_wiki_page def wiki_page
@project_wiki_page ||= build(:wiki_page, wiki: project_wiki) @wiki_page ||= build(:wiki_page, wiki: wiki)
end end
def issue def issue
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment