2015-05-12 19:07:48 -04:00
|
|
|
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
|
2015-06-23 01:24:39 -04:00
|
|
|
expected_asciidoc_opts = {
|
|
|
|
safe: :secure,
|
|
|
|
backend: :html5,
|
|
|
|
attributes: described_class::DEFAULT_ADOC_ATTRS
|
|
|
|
}
|
2015-05-12 19:07:48 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2015-06-22 14:41:00 -04:00
|
|
|
let(:asciidoc_opts) { { safe: :safe, attributes: ['foo'] } }
|
2015-05-12 19:07:48 -04:00
|
|
|
|
|
|
|
it "should merge the options with default ones" do
|
2015-06-23 01:24:39 -04:00
|
|
|
expected_asciidoc_opts = {
|
|
|
|
safe: :safe,
|
|
|
|
backend: :html5,
|
|
|
|
attributes: described_class::DEFAULT_ADOC_ATTRS + ['foo']
|
|
|
|
}
|
2015-05-12 19:07:48 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2015-06-22 14:41:00 -04:00
|
|
|
let(:context) { { project: create(:project) } }
|
2015-05-12 19:07:48 -04:00
|
|
|
|
|
|
|
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
|