2015-05-12 19:07:48 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'nokogiri'
|
|
|
|
|
|
|
|
module Gitlab
|
2015-12-09 05:55:36 -05:00
|
|
|
describe Asciidoc, lib: true do
|
2015-05-12 19:07:48 -04:00
|
|
|
let(:input) { '<b>ascii</b>' }
|
|
|
|
let(:context) { {} }
|
|
|
|
let(:html) { 'H<sub>2</sub>O' }
|
|
|
|
|
|
|
|
context "without project" do
|
2016-11-28 12:41:29 -05:00
|
|
|
before do
|
|
|
|
allow_any_instance_of(ApplicationSetting).to receive(:current).and_return(::ApplicationSetting.create_from_defaults)
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "converts the input using Asciidoctor and default options" do
|
2015-06-23 01:24:39 -04:00
|
|
|
expected_asciidoc_opts = {
|
|
|
|
safe: :secure,
|
2016-12-08 19:15:08 -05:00
|
|
|
backend: :gitlab_html5,
|
2015-06-23 01:24:39 -04:00
|
|
|
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
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it "merges the options with default ones" do
|
2015-06-23 01:24:39 -04:00
|
|
|
expected_asciidoc_opts = {
|
|
|
|
safe: :safe,
|
2016-12-08 19:15:08 -05:00
|
|
|
backend: :gitlab_html5,
|
2015-06-23 01:24:39 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
def render(*args)
|
|
|
|
described_class.render(*args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|