diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 09f69484..ce426cc2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -254,6 +254,8 @@ module ApplicationHelper end def markdown(text) + return '' if text.nil? + options = { autolink: true, space_after_headers: true, diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 89a44ea2..42070572 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -22,6 +22,22 @@ describe ApplicationHelper, type: :helper do end end + describe 'markdown' do + it 'should return empty string for nil' do + expect(markdown(nil)).to eq '' + end + + it 'should return HTML for header markdown' do + expect(Redcarpet::Markdown).to receive(:new). + with(Redcarpet::Render::HTML, autolink: true, + space_after_headers: true, + no_intra_emphasis: true). + and_call_original + + expect(markdown('# this is my header')).to eq "

this is my header

\n" + end + end + describe '#registered_text' do describe 'returns correct string' do it 'when there are no registrations' do