require 'spec_helper' require 'redcarpet' describe LadyJosephine::Redcarpet::CustomMarkdownFormatter do let(:subject) do markdown = Redcarpet::Markdown.new(LadyJosephine::Redcarpet::CustomMarkdownFormatter) markdown.render(text).html_safe end describe '#block_code' do let(:text) { "```\ncode\n```" } it { should eq "
\ncode
\n" } end describe '#paragraph' do let(:text) { "paragraph one\n\nparagraph two"} it { should eq "paragraph one
\n
\nparagraph two" } end describe '#blockquote' do let(:text) { "> Quote"} it { should eq "Quote" } end describe '#list' do let(:text) { "* item one\n* item two"} it { should eq "
  • item one
  • \n
  • item two
  • \n" } end describe '#codespan' do let(:text) { "this `codespan` is working"} it { should eq "this codespan is working" } end describe '#postprocess' do let(:text) { "<br>"} it { should eq "
    \n" } end describe '#preprocess' do let(:text) { "\"testint quotes\" \n"} it { should eq "„testint quotes“
    " } end describe '#link' do before :all do @old_host = Dummy::Application.config.action_mailer.default_url_options[:host] Dummy::Application.config.action_mailer.default_url_options[:host] = "example.com" end after :all do Dummy::Application.config.action_mailer.default_url_options[:host] = @old_host end context 'should render links with target=_blank for external links' do let(:text) { "[bitcrowd](http://bitcrowd.net)" } it { should eq "bitcrowd" } end context 'should render links without target=_blank for internal links' do context 'for relative urls' do let(:text) { "[link to page](/this/link)" } it { should eq "link to page" } end context 'for urls with a example.com domain' do let(:text) { "[link to page](http://example.com/this/link)" } it { should eq "link to page" } end context 'for urls with a example.com domain' do let(:text) { "[link to page](http://example.com/this/link)" } it { should eq "link to page" } end end context 'should also work if the host config has port and protocol' do let(:test_host) { "http://0.0.0.0:3000" } context 'for urls with a 0.0.0.0:3000 domain' do let(:text) { "[link to page](http://0.0.0.0:3000/this/link)" } before do @replaced_host = Dummy::Application.config.action_mailer.default_url_options[:host] Dummy::Application.config.action_mailer.default_url_options[:host] = "http://0.0.0.0:3000" end after do Dummy::Application.config.action_mailer.default_url_options[:host] = @replaced_host end it { should eq "link to page" } end end end end