From 288b276077987bc77f191d2cb93eb2f764c5c1ef Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Wed, 20 Dec 2017 14:48:09 +0100 Subject: Copy Mermaid graphs as GFM --- spec/lib/banzai/filter/mermaid_filter_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/lib/banzai') diff --git a/spec/lib/banzai/filter/mermaid_filter_spec.rb b/spec/lib/banzai/filter/mermaid_filter_spec.rb index 532d25e121d..f6474c8936d 100644 --- a/spec/lib/banzai/filter/mermaid_filter_spec.rb +++ b/spec/lib/banzai/filter/mermaid_filter_spec.rb @@ -3,9 +3,9 @@ require 'spec_helper' describe Banzai::Filter::MermaidFilter do include FilterSpecHelper - it 'adds `js-render-mermaid` class to the `pre` tag' do + it 'adds `js-render-mermaid` class to the `code` tag' do doc = filter("
graph TD;\n  A-->B;\n
") - result = doc.xpath('descendant-or-self::pre').first + result = doc.css('code').first expect(result[:class]).to include('js-render-mermaid') end -- cgit v1.2.3 From d2f83a10ea52a4fcbf380ddf01685bbc6ad7ee7a Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Wed, 10 Jan 2018 18:10:42 +0000 Subject: Ensure that emails contain absolute, rather than relative, links to user uploads --- .../lib/banzai/filter/relative_link_filter_spec.rb | 48 ++++++++++++++++------ 1 file changed, 35 insertions(+), 13 deletions(-) (limited to 'spec/lib/banzai') diff --git a/spec/lib/banzai/filter/relative_link_filter_spec.rb b/spec/lib/banzai/filter/relative_link_filter_spec.rb index f38f0776303..7e17457ce70 100644 --- a/spec/lib/banzai/filter/relative_link_filter_spec.rb +++ b/spec/lib/banzai/filter/relative_link_filter_spec.rb @@ -8,7 +8,8 @@ describe Banzai::Filter::RelativeLinkFilter do group: group, project_wiki: project_wiki, ref: ref, - requested_path: requested_path + requested_path: requested_path, + only_path: only_path }) described_class.call(doc, contexts) @@ -37,6 +38,7 @@ describe Banzai::Filter::RelativeLinkFilter do let(:commit) { project.commit(ref) } let(:project_wiki) { nil } let(:requested_path) { '/' } + let(:only_path) { true } shared_examples :preserve_unchanged do it 'does not modify any relative URL in anchor' do @@ -240,26 +242,35 @@ describe Banzai::Filter::RelativeLinkFilter do let(:commit) { nil } let(:ref) { nil } let(:requested_path) { nil } + let(:upload_path) { '/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg' } + let(:relative_path) { "/#{project.full_path}#{upload_path}" } context 'to a project upload' do + context 'with an absolute URL' do + let(:absolute_path) { Gitlab.config.gitlab.url + relative_path } + let(:only_path) { false } + + it 'rewrites the link correctly' do + doc = filter(link(upload_path)) + + expect(doc.at_css('a')['href']).to eq(absolute_path) + end + end + it 'rebuilds relative URL for a link' do - doc = filter(link('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')) - expect(doc.at_css('a')['href']) - .to eq "/#{project.full_path}/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg" + doc = filter(link(upload_path)) + expect(doc.at_css('a')['href']).to eq(relative_path) - doc = filter(nested(link('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg'))) - expect(doc.at_css('a')['href']) - .to eq "/#{project.full_path}/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg" + doc = filter(nested(link(upload_path))) + expect(doc.at_css('a')['href']).to eq(relative_path) end it 'rebuilds relative URL for an image' do - doc = filter(image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')) - expect(doc.at_css('img')['src']) - .to eq "/#{project.full_path}/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg" + doc = filter(image(upload_path)) + expect(doc.at_css('img')['src']).to eq(relative_path) - doc = filter(nested(image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg'))) - expect(doc.at_css('img')['src']) - .to eq "/#{project.full_path}/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg" + doc = filter(nested(image(upload_path))) + expect(doc.at_css('img')['src']).to eq(relative_path) end it 'does not modify absolute URL' do @@ -288,6 +299,17 @@ describe Banzai::Filter::RelativeLinkFilter do let(:project) { nil } let(:relative_path) { "/groups/#{group.full_path}/-/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg" } + context 'with an absolute URL' do + let(:absolute_path) { Gitlab.config.gitlab.url + relative_path } + let(:only_path) { false } + + it 'rewrites the link correctly' do + doc = filter(upload_link) + + expect(doc.at_css('a')['href']).to eq(absolute_path) + end + end + it 'rewrites the link correctly' do doc = filter(upload_link) -- cgit v1.2.3