Commit b9c25013 authored by Markus Koller's avatar Markus Koller

Use wiki instead of project_wiki in Banzai

This is in preparation for group wikis, we need to remove the coupling
between wikis and projects.

In this step we only change the name inside the Banzai filters and
pipelines, once we port the controllers we can also switch the
controller instance variable from `@project_wiki` to `@wiki`.
parent e437426b
......@@ -32,7 +32,7 @@ module PreviewMarkdown
def markdown_context_params
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 'groups' then { group: group }
when 'projects' then projects_filter_params
......
......@@ -129,7 +129,7 @@ module MarkupHelper
context.merge!(
pipeline: :wiki,
project: @project,
project_wiki: @project_wiki,
wiki: @project_wiki,
repository: @project_wiki.repository,
page_slug: wiki_page.slug,
issuable_state_filter_enabled: true
......
......@@ -30,7 +30,7 @@ module Banzai
# Note: the table of contents tag is now handled by TableOfContentsTagFilter
#
# Context options:
# :project_wiki (required) - Current project wiki.
# :wiki [Wiki] (required) - Current wiki instance.
#
class GollumTagsFilter < HTML::Pipeline::Filter
include ActionView::Helpers::TagHelper
......@@ -100,8 +100,8 @@ module Banzai
if url?(content)
path = content
elsif file = project_wiki.find_file(content)
path = ::File.join project_wiki_base_path, file.path
elsif file = wiki.find_file(content)
path = ::File.join(wiki_base_path, file.path)
end
if path
......@@ -134,25 +134,25 @@ module Banzai
if url?(reference)
reference
else
::File.join(project_wiki_base_path, reference)
::File.join(wiki_base_path, reference)
end
content_tag(:a, name || reference, href: href, class: 'gfm')
end
def project_wiki
context[:project_wiki]
def wiki
context[:wiki]
end
def project_wiki_base_path
project_wiki && project_wiki.wiki_base_path
def wiki_base_path
wiki&.wiki_base_path
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!
def validate
needs :project_wiki
needs :wiki
end
end
end
......
......@@ -10,7 +10,7 @@ module Banzai
# :commit
# :current_user
# :project
# :project_wiki
# :wiki
# :ref
# :requested_path
# :system_note
......@@ -53,7 +53,7 @@ module Banzai
def linkable_files?
strong_memoize(:linkable_files) do
context[:project_wiki].nil? && repository.try(:exists?) && !repository.empty?
context[:wiki].nil? && repository.try(:exists?) && !repository.empty?
end
end
......
......@@ -6,12 +6,12 @@ module Banzai
# Rewrite rules are documented in the `WikiPipeline` spec.
#
# Context options:
# :project_wiki
# :wiki
class WikiLinkFilter < HTML::Pipeline::Filter
include Gitlab::Utils::SanitizeNodeLink
def call
return doc unless project_wiki?
return doc unless wiki?
doc.search('a:not(.gfm)').each { |el| process_link(el.attribute('href'), el) }
......@@ -33,8 +33,8 @@ module Banzai
remove_unsafe_links({ node: node }, remove_invalid_links: false)
end
def project_wiki?
!context[:project_wiki].nil?
def wiki?
!context[:wiki].nil?
end
def process_link_attr(html_attr)
......@@ -46,7 +46,7 @@ module Banzai
end
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
......
......@@ -157,7 +157,7 @@ describe 'Copy as GFM', :js do
GFM
pipeline: :wiki,
project_wiki: @project.wiki
wiki: @project.wiki
)
verify(
......
......@@ -269,15 +269,15 @@ describe 'GitLab Markdown', :aggregate_failures do
context 'wiki pipeline' do
before do
@project_wiki = @feat.project_wiki
@project_wiki_page = @feat.project_wiki_page
@wiki = @feat.wiki
@wiki_page = @feat.wiki_page
path = 'images/example.jpg'
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))
allow(@project_wiki).to receive(:wiki_base_path) { '/namespace1/gitlabhq/wikis' }
expect(@wiki).to receive(:find_file).with(path).and_return(Gitlab::Git::WikiFile.new(gitaly_wiki_file))
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
it_behaves_like 'all pipelines'
......
......@@ -317,7 +317,7 @@ describe MarkupHelper do
let(:wiki_repository) { double('Repository') }
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,
repository: wiki_repository
}
......
......@@ -7,11 +7,11 @@ describe Banzai::Filter::GollumTagsFilter do
let(:project) { create(:project) }
let(:user) { double }
let(:project_wiki) { ProjectWiki.new(project, user) }
let(:wiki) { ProjectWiki.new(project, user) }
describe 'validation' do
it 'ensure that a :project_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"
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: :wiki"
end
end
......@@ -23,19 +23,19 @@ describe Banzai::Filter::GollumTagsFilter do
path: 'images/image.jpg',
raw_data: '')
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]]'
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
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]]'
doc = filter("See #{tag}", project_wiki: project_wiki)
doc = filter("See #{tag}", wiki: wiki)
expect(doc.css('img').size).to eq 0
end
......@@ -44,14 +44,14 @@ describe Banzai::Filter::GollumTagsFilter do
context 'linking external images' do
it 'creates img tag for valid URL' do
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"
end
it 'does not creates img tag for invalid URL' do
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
end
......@@ -60,7 +60,7 @@ describe Banzai::Filter::GollumTagsFilter do
context 'linking external resources' do
it "the created link's text will be equal to the resource's text" do
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')['href']).to eq 'http://example.com'
......@@ -68,7 +68,7 @@ describe Banzai::Filter::GollumTagsFilter do
it "the created link's text will be link-text" do
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')['href']).to eq 'http://example.com/pdfs/gollum.pdf'
......@@ -78,8 +78,8 @@ describe Banzai::Filter::GollumTagsFilter do
context 'linking internal resources' do
it "the created link's text includes the resource's text and wiki base path" do
tag = '[[wiki-slug]]'
doc = filter("See #{tag}", project_wiki: project_wiki)
expected_path = ::File.join(project_wiki.wiki_base_path, 'wiki-slug')
doc = filter("See #{tag}", wiki: wiki)
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')['href']).to eq expected_path
......@@ -87,15 +87,15 @@ describe Banzai::Filter::GollumTagsFilter do
it "the created link's text will be link-text" do
tag = '[[link-text|wiki-slug]]'
doc = filter("See #{tag}", project_wiki: project_wiki)
expected_path = ::File.join(project_wiki.wiki_base_path, 'wiki-slug')
doc = filter("See #{tag}", wiki: wiki)
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')['href']).to eq expected_path
end
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]]'
end
......
......@@ -12,7 +12,7 @@ describe Banzai::Filter::RepositoryLinkFilter do
project: project,
current_user: user,
group: group,
project_wiki: project_wiki,
wiki: wiki,
ref: ref,
requested_path: requested_path,
only_path: only_path
......@@ -53,7 +53,7 @@ describe Banzai::Filter::RepositoryLinkFilter do
let(:project_path) { project.full_path }
let(:ref) { 'markdown' }
let(:commit) { project.commit(ref) }
let(:project_wiki) { nil }
let(:wiki) { nil }
let(:requested_path) { '/' }
let(:only_path) { true }
......@@ -94,8 +94,8 @@ describe Banzai::Filter::RepositoryLinkFilter do
end
end
context 'with a project_wiki' do
let(:project_wiki) { double('ProjectWiki') }
context 'with a wiki' do
let(:wiki) { double('ProjectWiki') }
include_examples :preserve_unchanged
end
......
......@@ -12,13 +12,13 @@ describe Banzai::Filter::WikiLinkFilter do
let(:repository_upload_folder) { Wikis::CreateAttachmentService::ATTACHMENT_PATH }
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/')
end
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')
end
......@@ -26,7 +26,7 @@ describe Banzai::Filter::WikiLinkFilter do
describe "when links point to the #{Wikis::CreateAttachmentService::ATTACHMENT_PATH} folder" do
context 'with an "a" html tag' 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")
end
......@@ -37,7 +37,7 @@ describe Banzai::Filter::WikiLinkFilter do
context 'inside an "a" html tag' 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('a').first.attribute('href').value).to eq(path)
......@@ -46,7 +46,7 @@ describe Banzai::Filter::WikiLinkFilter do
context 'outside an "a" html tag' 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)
end
......@@ -55,7 +55,7 @@ describe Banzai::Filter::WikiLinkFilter do
context 'with "video" html tag' 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")
end
......@@ -63,7 +63,7 @@ describe Banzai::Filter::WikiLinkFilter do
context 'with "audio" html tag' 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")
end
......@@ -75,7 +75,7 @@ describe Banzai::Filter::WikiLinkFilter do
invalid_links.each do |invalid_link|
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)
end
......
......@@ -13,7 +13,7 @@ describe Banzai::Pipeline::WikiPipeline do
Foo
MD
result = described_class.call(markdown, project: spy, project_wiki: spy)
result = described_class.call(markdown, project: spy, wiki: spy)
aggregate_failures do
expect(result[:output].text).not_to include '[['
......@@ -31,7 +31,7 @@ describe Banzai::Pipeline::WikiPipeline do
Foo
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>]]')
end
......@@ -44,7 +44,7 @@ describe Banzai::Pipeline::WikiPipeline do
Foo
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
expect(output).not_to include('<ul>')
......@@ -56,8 +56,8 @@ describe Banzai::Pipeline::WikiPipeline do
describe "Links" 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, title: 'nested/twice/start-page') }
let(:wiki) { ProjectWiki.new(project, double(:user)) }
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 relative URL' => '/nested/relative/gitlab' }.each do |test_name, relative_url_root|
......@@ -70,14 +70,14 @@ describe Banzai::Pipeline::WikiPipeline 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
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\"")
end
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)
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\"")
end
......@@ -86,14 +86,14 @@ describe Banzai::Pipeline::WikiPipeline 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
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\"")
end
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)
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\"")
end
......@@ -102,14 +102,14 @@ describe Banzai::Pipeline::WikiPipeline 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
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\"")
end
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)
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\"")
end
......@@ -118,35 +118,35 @@ describe Banzai::Pipeline::WikiPipeline do
describe "when creating non-hierarchical links" do
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)
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\"")
end
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)
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\"")
end
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)
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\"")
end
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)
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\"")
end
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)
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\"")
end
......@@ -155,14 +155,14 @@ describe Banzai::Pipeline::WikiPipeline do
describe "when creating root links" do
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)
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\"")
end
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)
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\"")
end
......@@ -172,7 +172,7 @@ describe Banzai::Pipeline::WikiPipeline do
describe "linking to pages outside the wiki (absolute)" do
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)
output = described_class.to_html(markdown, project: project, wiki: wiki, page_slug: page.slug)
expect(output).to include('href="http://example.com/page"')
end
......@@ -188,7 +188,7 @@ describe Banzai::Pipeline::WikiPipeline do
output = described_class.to_html(
"[Link](./alert(1);)",
project: project,
project_wiki: project_wiki,
wiki: wiki,
page_slug: valid_slug
)
......@@ -199,7 +199,7 @@ describe Banzai::Pipeline::WikiPipeline do
output = described_class.to_html(
"[Link](../alert(1);)",
project: project,
project_wiki: project_wiki,
wiki: wiki,
page_slug: valid_slug
)
......@@ -236,7 +236,7 @@ describe Banzai::Pipeline::WikiPipeline do
output = described_class.to_html(
"[Link](./#{link})",
project: project,
project_wiki: project_wiki,
wiki: wiki,
page_slug: slug
)
......@@ -247,7 +247,7 @@ describe Banzai::Pipeline::WikiPipeline do
output = described_class.to_html(
"[Link](../#{link})",
project: project,
project_wiki: project_wiki,
wiki: wiki,
page_slug: slug
)
......@@ -263,33 +263,33 @@ describe Banzai::Pipeline::WikiPipeline do
describe 'videos and audio' 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, title: 'nested/twice/start-page') }
let_it_be(:wiki) { ProjectWiki.new(project, double(:user)) }
let_it_be(:page) { build(:wiki_page, wiki: wiki, title: 'nested/twice/start-page') }
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)
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"')
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)
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"')
end
it 'generates audio html structure' do
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"')
end
it 'rewrites and replaces audio links names with white spaces to %20' do
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"')
end
......
......@@ -36,12 +36,12 @@ class MarkdownFeature
end
end
def project_wiki
@project_wiki ||= ProjectWiki.new(project, user)
def wiki
@wiki ||= ProjectWiki.new(project, user)
end
def project_wiki_page
@project_wiki_page ||= build(:wiki_page, wiki: project_wiki)
def wiki_page
@wiki_page ||= build(:wiki_page, wiki: wiki)
end
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