require "rails_helper" describe Markdowner do it "parses simple markdown" do expect(Markdowner.to_html("hello there *italics* and **bold**!")) .to eq("

hello there italics and bold!

\n") end it "turns @username into a link if @username exists" do create(:user, :username => "blahblah") expect(Markdowner.to_html("hi @blahblah test")) .to eq("

hi " + "@blahblah test

\n") expect(Markdowner.to_html("hi @flimflam test")) .to eq("

hi @flimflam test

\n") end # bug#209 it "keeps punctuation inside of auto-generated links when using brackets" do expect(Markdowner.to_html("hi test")) .to eq("

hi " + "http://example.com/a. test

\n") end # bug#242 it "does not expand @ signs inside urls" do create(:user, :username => "blahblah") expect(Markdowner.to_html("hi http://example.com/@blahblah/ test")) .to eq("

hi " + "http://example.com/@blahblah/ test

\n") expect(Markdowner.to_html("hi [test](http://example.com/@blahblah/)")) .to eq("

hi " + "test

\n") end it "correctly adds ugc" do expect(Markdowner.to_html("[ex](http://example.com)")) .to eq("

" + "ex

\n") expect(Markdowner.to_html("[ex](//example.com)")) .to eq("

" + "ex

\n") expect(Markdowner.to_html("[ex](/~abc)")) .to eq("

ex

\n") end context "when images are not allowed" do subject { Markdowner.to_html(description, allow_images: false) } let(:fake_img_url) { 'https://lbst.rs/fake.jpg' } context "when single inline image in description" do let(:description) { "![#{alt_text}](#{fake_img_url} \"#{title_text}\")" } let(:alt_text) { nil } let(:title_text) { nil } def target_html inner_text = nil "

#{inner_text}

\n" end context "with no alt text, title text" do it "turns inline image into links with the url as the default text" do expect(subject).to eq(target_html(fake_img_url)) end end context "with title text" do let(:title_text) { 'title text' } it "turns inline image into links with title text" do expect(subject).to eq(target_html(title_text)) end end context "with alt text" do let(:alt_text) { 'alt text' } it "turns inline image into links with alt text" do expect(subject).to eq(target_html(alt_text)) end end context "with title text and alt text" do let(:title_text) { 'title text' } it "turns inline image into links, preferring title text" do expect(subject).to eq(target_html(title_text)) end end end context "with multiple inline images in description" do let(:description) do "![](#{fake_img_url})" \ "![](#{fake_img_url})" \ "![alt text](#{fake_img_url})" \ "![](#{fake_img_url} \"title text\")" \ "![alt text](#{fake_img_url} \"title text 2\")" end it 'turns all inline images into links' do expect(subject).to eq( "

" \ "#{fake_img_url}" \ "#{fake_img_url}" \ "alt text" \ "title text" \ "title text 2" \ "

\n" ) end end end context "when images are allowed" do subject { Markdowner.to_html("![](https://lbst.rs/fake.jpg)", allow_images: true) } it 'allows image tags' do expect(subject).to include '