require 'rails_helper'
require 'email_cook'
require 'pretty_text'
describe EmailCook do
it "uses to PrettyText when there is no [plaintext] in raw" do
raw = "**Hello world!**"
expect(cook(raw)).to eq(PrettyText.cook(raw))
end
it "adds linebreaks to short lines" do
raw = plaintext("hello\nworld\n")
expect(cook(raw)).to eq("hello\n
world\n
")
end
it "doesn't add linebreaks to long lines" do
long = plaintext(<<~LONG_EMAIL)
Hello,
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc convallis volutpat
risus. Nulla ac faucibus quam, quis cursus lorem. Sed rutrum eget nunc sed accumsan.
Vestibulum feugiat mi vitae turpis tempor dignissim.
LONG_EMAIL
long_cooked = <<~LONG_COOKED.strip!
Hello,
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc convallis volutpat
risus. Nulla ac faucibus quam, quis cursus lorem. Sed rutrum eget nunc sed accumsan.
Vestibulum feugiat mi vitae turpis tempor dignissim.
LONG_COOKED
expect(cook(long)).to eq(long_cooked)
end
it "replaces a blank line with 2 linebreaks" do
long = plaintext(<<~LONG_EMAIL)
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc convallis volutpat
risus.
Nulla ac faucibus quam, quis cursus lorem. Sed rutrum eget nunc sed accumsan.
Vestibulum feugiat mi vitae turpis tempor dignissim.
Stet clita kasd gubergren.
LONG_EMAIL
long_cooked = <<~LONG_COOKED.strip!
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc convallis volutpat
risus.
Nulla ac faucibus quam, quis cursus lorem. Sed rutrum eget nunc sed accumsan.
Vestibulum feugiat mi vitae turpis tempor dignissim.
Stet clita kasd gubergren.
LONG_COOKED
expect(cook(long)).to eq(long_cooked)
end
it "escapes HTML" do
long = plaintext(<<~LONG_EMAIL)
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
https://www.eviltrout.com is my site') end it "it works and does not interpret Markdown in plaintext and elided" do long = <<~LONG_EMAIL [plaintext] *Lorem ipsum* dolor sit amet, consectetur adipiscing elit. [/plaintext] [attachments] [/attachments] [elided] At vero eos *et accusam* et justo duo dolores et ea rebum. [/elided] LONG_EMAIL long_cooked = <<~LONG_COOKED *Lorem ipsum* dolor sit amet, consectetur adipiscing elit.