2016-07-13 01:33:13 +08:00
require 'rails_helper'
require 'email_cook'
describe EmailCook do
2016-07-13 01:49:03 +08:00
it 'adds linebreaks to short lines' do
2016-07-13 01:33:13 +08:00
expect ( EmailCook . new ( " hello \n world \n " ) . cook ) . to eq ( " hello \n <br>world \n <br> " )
end
2016-07-13 01:49:03 +08:00
it " doesn't add linebreaks to long lines " do
long = <<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
Hello ,
< br >
< br > 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 .
2016-07-13 19:14:40 +08:00
< br > < br >
2016-07-13 01:49:03 +08:00
LONG_COOKED
expect ( EmailCook . new ( long ) . cook ) . to eq ( long_cooked . strip )
end
2017-10-18 02:36:57 +08:00
it 'creates oneboxed link when the line contains only a link' do
expect ( EmailCook . new ( " https://www.eviltrout.com " ) . cook ) . to eq ( '<a href="https://www.eviltrout.com" class="onebox" target="_blank">https://www.eviltrout.com</a><br>' )
2016-07-13 01:33:13 +08:00
end
2016-07-19 01:46:13 +08:00
it 'autolinks without the beginning of a line' do
2017-10-18 02:36:57 +08:00
expect ( EmailCook . new ( " my site: https://www.eviltrout.com " ) . cook ) . to eq ( 'my site: <a href="https://www.eviltrout.com">https://www.eviltrout.com</a><br>' )
end
it 'autolinks without the end of a line' do
expect ( EmailCook . new ( " https://www.eviltrout.com is my site " ) . cook ) . to eq ( '<a href="https://www.eviltrout.com">https://www.eviltrout.com</a> is my site<br>' )
2016-07-19 01:46:13 +08:00
end
2016-07-19 02:38:40 +08:00
it 'links even within a quote' do
2017-10-18 02:36:57 +08:00
expect ( EmailCook . new ( " > https://www.eviltrout.com " ) . cook ) . to eq ( '<blockquote><a href="https://www.eviltrout.com">https://www.eviltrout.com</a><br></blockquote>' )
2016-07-19 02:38:40 +08:00
end
2016-07-13 01:33:13 +08:00
end