summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorJakub Jirutka <jakub@jirutka.cz>2015-05-13 01:07:48 +0200
committerJakub Jirutka <jakub@jirutka.cz>2015-05-18 20:48:03 +0200
commit8dbc4746fe7c723b67f3c90cbf40fd7bf6c29cb7 (patch)
tree268aba3884c8e2e09fdefda9cad7a4c569154cc2 /spec/lib
parentdc348baf18240dc05e209ec781daada2cbcfe16f (diff)
downloadgitlab-ce-8dbc4746fe7c723b67f3c90cbf40fd7bf6c29cb7.tar.gz
Handle AsciiDoc better, reuse HTML pipeline filters (fixes #9263)
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/asciidoc_spec.rb59
-rw-r--r--spec/lib/gitlab/gitlab_markdown_helper_spec.rb14
2 files changed, 72 insertions, 1 deletions
diff --git a/spec/lib/gitlab/asciidoc_spec.rb b/spec/lib/gitlab/asciidoc_spec.rb
new file mode 100644
index 00000000000..23f83339ec5
--- /dev/null
+++ b/spec/lib/gitlab/asciidoc_spec.rb
@@ -0,0 +1,59 @@
+require 'spec_helper'
+require 'nokogiri'
+
+module Gitlab
+ describe Asciidoc do
+
+ let(:input) { '<b>ascii</b>' }
+ let(:context) { {} }
+ let(:html) { 'H<sub>2</sub>O' }
+
+ context "without project" do
+
+ it "should convert the input using Asciidoctor and default options" do
+ expected_asciidoc_opts = { safe: :secure, backend: :html5,
+ attributes: described_class::DEFAULT_ADOC_ATTRS }
+
+ expect(Asciidoctor).to receive(:convert)
+ .with(input, expected_asciidoc_opts).and_return(html)
+
+ expect( render(input, context) ).to eql html
+ end
+
+ context "with asciidoc_opts" do
+
+ let(:asciidoc_opts) { {safe: :safe, attributes: ['foo']} }
+
+ it "should merge the options with default ones" do
+ expected_asciidoc_opts = { safe: :safe, backend: :html5,
+ attributes: described_class::DEFAULT_ADOC_ATTRS + ['foo'] }
+
+ expect(Asciidoctor).to receive(:convert)
+ .with(input, expected_asciidoc_opts).and_return(html)
+
+ render(input, context, asciidoc_opts)
+ end
+ end
+ end
+
+ context "with project in context" do
+
+ let(:context) { {project: create(:project)} }
+
+ it "should filter converted input via HTML pipeline and return result" do
+ filtered_html = '<b>ASCII</b>'
+
+ allow(Asciidoctor).to receive(:convert).and_return(html)
+ expect_any_instance_of(HTML::Pipeline).to receive(:call)
+ .with(html, context)
+ .and_return(output: Nokogiri::HTML.fragment(filtered_html))
+
+ expect( render('foo', context) ).to eql filtered_html
+ end
+ end
+
+ def render(*args)
+ described_class.render(*args)
+ end
+ end
+end
diff --git a/spec/lib/gitlab/gitlab_markdown_helper_spec.rb b/spec/lib/gitlab/gitlab_markdown_helper_spec.rb
index ab613193f41..beaafd56352 100644
--- a/spec/lib/gitlab/gitlab_markdown_helper_spec.rb
+++ b/spec/lib/gitlab/gitlab_markdown_helper_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe Gitlab::MarkdownHelper do
describe '#markup?' do
%w(textile rdoc org creole wiki
- mediawiki rst adoc asciidoc asc).each do |type|
+ mediawiki rst adoc ad asciidoc).each do |type|
it "returns true for #{type} files" do
expect(Gitlab::MarkdownHelper.markup?("README.#{type}")).to be_truthy
end
@@ -25,4 +25,16 @@ describe Gitlab::MarkdownHelper do
expect(Gitlab::MarkdownHelper.gitlab_markdown?('README.rb')).not_to be_truthy
end
end
+
+ describe '#asciidoc?' do
+ %w(adoc ad asciidoc ADOC).each do |type|
+ it "returns true for #{type} files" do
+ expect(Gitlab::MarkdownHelper.asciidoc?("README.#{type}")).to be_truthy
+ end
+ end
+
+ it 'returns false when given a non-asciidoc filename' do
+ expect(Gitlab::MarkdownHelper.asciidoc?('README.rb')).not_to be_truthy
+ end
+ end
end