# encoding: utf-8
require 'spec_helper'
describe ActionMailer::Text::HtmlToPlainText do
it 'converts a fragment' do
expect(subject.convert_to_text('
Test
')).to match(/Test/)
end
it 'converts a body' do
expect(subject.convert_to_text('
Ignore me
Test
')).to match(/Test/)
end
it 'ignores titles' do
expect(subject.convert_to_text('
Ignore me
Test
')).not_to match(/Ignore me/)
end
it 'ignores header links' do
expect(subject.convert_to_text('
Test
')).not_to match(/\*/)
end
it 'ignores header titles' do
expect(subject.convert_to_text('
Ignore me
Test
')).not_to match(/Ignore me/)
end
it 'converts a malformed body' do
expect(subject.convert_to_text('
Ignore me
Test
')).to match(/Test/)
end
it 'dencodes html entities' do
expect(subject.convert_to_text('
cédille garçon & à ñ
')).to eq('cédille garçon & à ñ')
end
it 'strips whitespace' do
expect(subject.convert_to_text(" \ttext\ntext\n")).to eq("text\ntext")
expect(subject.convert_to_text(" \na \n a \t")).to eq("a\na")
expect(subject.convert_to_text(" \na \n\t \n \n a \t")).to eq("a\n\na")
expect(subject.convert_to_text('test text ')).to eq('test text')
expect(subject.convert_to_text('test text')).to eq('test text')
end
it 'leaves spaces for spans' do
expect(subject.convert_to_text('
Testline 2
')).to match(/Test line 2/)
end
it 'normalizes line breaks' do
expect(subject.convert_to_text("Test text\r\nTest text")).to eq("Test text\nTest text")
expect(subject.convert_to_text("Test text\nTest text")).to eq("Test text\nTest text")
end
it 'formats lists' do
expect(subject.convert_to_text("
', nil, 10_000))
.to eq('This is link1 ( http://www.google.com ) and link2 ( http://www.google.com ) is next.')
end
# see https://github.com/alexdunae/premailer/issues/72
it 'converts links within headings' do
expect(subject
.convert_to_text("