require 'spec_helper' describe Administrate::Field::SimpleMarkdown do subject { Administrate::Field::SimpleMarkdown.new(:simple_markdown, data, :show) } let(:md) { '**foo** is the new _bar_' } let(:text) { 'foo is the new bar' } let(:html) { '
foo is the new bar
' } describe '#data' do let(:output) { subject.data } context 'with nil' do let(:data) { nil } it 'returns an empty string' do expect(output).to eq '' end end context 'with data' do let(:data) { text } it 'returns the data' do expect(output).to eq text end end end describe '#to_s' do let(:output) { subject.to_s } context 'with nil' do let(:data) { nil } it 'returns an empty string' do expect(output).to eq '' end end context 'with a string' do let(:data) { text } it 'returns the same string' do expect(output).to eq "#{text}\n" end end context 'with Markdown' do let(:data) { md } it 'strips out the formatting' do expect(output).to eq "#{text}\n" end end end describe '#to_html' do let(:output) { subject.to_html } context 'with nil' do let(:data) { nil } it 'returns an empty string' do expect(output).to eq '' end end context 'with a string' do let(:data) { text } it 'wraps it in a paragraph' do expect(output).to eq "#{text}
\n" end end context 'with Markdown' do let(:data) { md } it 'converts it to HTML' do expect(output).to eq "#{html}\n" end end end describe '#html_id' do let(:data) { nil } let(:output) { subject.html_id } context 'with a non-namespaced model' do before { stub_const 'Foo', Class.new} let(:resource) { Foo.new } it 'returns the expected HTML id' do allow(subject).to receive(:resource).and_return(resource) expect(output).to eq 'foo_simple_markdown' end end context 'with a namespaced model' do before { stub_const 'Foo::Bar', Class.new} let(:resource) { Foo::Bar.new } it 'returns the expected HTML id' do allow(subject).to receive(:resource).and_return(resource) expect(output).to eq 'foo_bar_simple_markdown' end end end end