From 05e0f504530a162d4bcb886adf504c12cffd5934 Mon Sep 17 00:00:00 2001 From: Toon Claes Date: Thu, 6 Apr 2017 16:47:52 +0200 Subject: Cache the rendered README, but post-process on show Because the post-processing of the rendered README is dependent on the context (i.e. the current user), do the post-processing when the README is being displayed. --- spec/helpers/markup_helper_spec.rb | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'spec/helpers/markup_helper_spec.rb') diff --git a/spec/helpers/markup_helper_spec.rb b/spec/helpers/markup_helper_spec.rb index 617cfed5bee..59ae6570ae7 100644 --- a/spec/helpers/markup_helper_spec.rb +++ b/spec/helpers/markup_helper_spec.rb @@ -126,15 +126,16 @@ describe MarkupHelper do it "uses Wiki pipeline for markdown files" do allow(@wiki).to receive(:format).and_return(:markdown) - expect(helper).to receive(:markdown).with('wiki content', pipeline: :wiki, project_wiki: @wiki, page_slug: "nested/page") + expect(helper).to receive(:markdown_render).with('wiki content', pipeline: :wiki, project_wiki: @wiki, page_slug: "nested/page") helper.render_wiki_content(@wiki) end it "uses Asciidoctor for asciidoc files" do + allow_any_instance_of(ApplicationSetting).to receive(:current).and_return(::ApplicationSetting.create_from_defaults) allow(@wiki).to receive(:format).and_return(:asciidoc) - expect(helper).to receive(:asciidoc).with('wiki content') + expect(helper).to receive(:asciidoc_render).with('wiki content') helper.render_wiki_content(@wiki) end @@ -149,6 +150,29 @@ describe MarkupHelper do end end + describe 'render_markup' do + let(:content) { 'Noël' } + + it 'preserves encoding' do + expect(content.encoding.name).to eq('UTF-8') + expect(helper.render_markup('foo.rst', content).encoding.name).to eq('UTF-8') + end + + it "delegates to #markdown_render when file name corresponds to Markdown" do + expect(helper).to receive(:gitlab_markdown?).with('foo.md').and_return(true) + expect(helper).to receive(:markdown_render).and_return('NOEL') + + expect(helper.render_markup('foo.md', content)).to eq('NOEL') + end + + it "delegates to #asciidoc_render when file name corresponds to AsciiDoc" do + expect(helper).to receive(:asciidoc?).with('foo.adoc').and_return(true) + expect(helper).to receive(:asciidoc_render).and_return('NOEL') + + expect(helper.render_markup('foo.adoc', content)).to eq('NOEL') + end + end + describe '#first_line_in_markdown' do it 'truncates Markdown properly' do text = "@#{user.username}, can you look at this?\nHello world\n" -- cgit v1.2.1