Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jirutka <jakub@jirutka.cz>2015-05-13 02:07:48 +0300
committerJakub Jirutka <jakub@jirutka.cz>2015-05-18 21:48:03 +0300
commit8dbc4746fe7c723b67f3c90cbf40fd7bf6c29cb7 (patch)
tree268aba3884c8e2e09fdefda9cad7a4c569154cc2 /spec/lib/gitlab/asciidoc_spec.rb
parentdc348baf18240dc05e209ec781daada2cbcfe16f (diff)
Handle AsciiDoc better, reuse HTML pipeline filters (fixes #9263)
Diffstat (limited to 'spec/lib/gitlab/asciidoc_spec.rb')
-rw-r--r--spec/lib/gitlab/asciidoc_spec.rb59
1 files changed, 59 insertions, 0 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