diff options
author | Vasiliy Yakliushin <vyaklushin@gmail.com> | 2019-07-04 16:11:44 +0200 |
---|---|---|
committer | Vasiliy Yakliushin <vyaklushin@gmail.com> | 2019-07-07 11:49:53 +0200 |
commit | 22e2217c955d6d89b26758a17234a285565307a1 (patch) | |
tree | 652bb2405e923659708ff52cb6b4e16c40678063 | |
parent | bd69c9197cefcb31ebabe466df005f1451ac1c46 (diff) | |
download | gitlab-ce-22e2217c955d6d89b26758a17234a285565307a1.tar.gz |
Fix undefined method `simple_format for MarkupHelper:Module
`simple_format` is not defined in ActionView::Helpers::TagHelper, but
it is actually located in ActionView::Helpers::TextHelper.
The solution is to include the correct helper.
I've also added tests for `#markup_unsafe` because they were missing.
-rw-r--r-- | app/helpers/markup_helper.rb | 2 | ||||
-rw-r--r-- | spec/helpers/markup_helper_spec.rb | 73 |
2 files changed, 73 insertions, 2 deletions
diff --git a/app/helpers/markup_helper.rb b/app/helpers/markup_helper.rb index 8ccb39f8444..c2b47098a8d 100644 --- a/app/helpers/markup_helper.rb +++ b/app/helpers/markup_helper.rb @@ -3,7 +3,7 @@ require 'nokogiri' module MarkupHelper - include ActionView::Helpers::TagHelper + include ActionView::Helpers::TextHelper include ::Gitlab::ActionViewOutput::Context def plain?(filename) diff --git a/spec/helpers/markup_helper_spec.rb b/spec/helpers/markup_helper_spec.rb index 6c6410cee9b..f6e1720e113 100644 --- a/spec/helpers/markup_helper_spec.rb +++ b/spec/helpers/markup_helper_spec.rb @@ -268,7 +268,7 @@ describe MarkupHelper do end end - describe 'markup' do + describe '#markup' do let(:content) { 'Noël' } it 'preserves encoding' do @@ -302,6 +302,77 @@ describe MarkupHelper do end end + describe '#markup_unsafe' do + subject { helper.markup_unsafe(file_name, text, context) } + + let(:file_name) { 'foo.bar' } + let(:text) { 'Noël' } + let(:project_base) { build(:project, :repository) } + let(:context) { { project: project_base } } + + context 'when text is missing' do + let(:text) { nil } + + it 'returns an empty string' do + is_expected.to eq('') + end + end + + context 'when file is a markdown file' do + let(:file_name) { 'foo.md' } + + it 'returns html (rendered by Banzai)' do + expected_html = '<p data-sourcepos="1:1-1:5" dir="auto">Noël</p>' + + expect(Banzai).to receive(:render).with(text, context) { expected_html } + + is_expected.to eq(expected_html) + end + + context 'when renderer returns an error' do + before do + allow(Banzai).to receive(:render).and_raise("An error") + end + + it 'returns html (rendered by ActionView:TextHelper)' do + is_expected.to eq('<p>Noël</p>') + end + end + end + + context 'when file is asciidoc file' do + let(:file_name) { 'foo.adoc' } + + it 'returns html (rendered by Gitlab::Asciidoc)' do + expected_html = "<div>\n<p>Noël</p>\n</div>" + + expect(Gitlab::Asciidoc).to receive(:render).with(text, context) { expected_html } + + is_expected.to eq(expected_html) + end + end + + context 'when file is a regular text file' do + let(:file_name) { 'foo.txt' } + + it 'returns html (rendered by ActionView::TagHelper)' do + is_expected.to eq('<pre class="plain-readme">Noël</pre>') + end + end + + context 'when file has an unknown type' do + let(:file_name) { 'foo' } + + it 'returns html (rendered by Gitlab::OtherMarkup)' do + expected_html = 'Noël' + + expect(Gitlab::OtherMarkup).to receive(:render).with(file_name, text, context) { expected_html } + + is_expected.to eq(expected_html) + end + end + end + describe '#first_line_in_markdown' do shared_examples_for 'common markdown examples' do let(:project_base) { build(:project, :repository) } |