forked from premailer/actionmailer_inline_css
/
inline_css_hook_test.rb
55 lines (45 loc) · 1.45 KB
/
inline_css_hook_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require 'abstract_unit'
TEST_HTML = %Q{
<html>
<head>
<style>
#test { color: #123456; }
</style>
</head>
<body>
<div id="test">Test</div>
</body>
</html>}
class HelperMailer < ActionMailer::Base
helper ActionMailer::InlineCssHelper
def use_inline_css_hook_with_only_html_part
mail_with_defaults do |format|
format.html { render(:inline => TEST_HTML) }
end
end
def use_inline_css_hook_with_text_and_html_parts
mail_with_defaults do |format|
format.html { render(:inline => TEST_HTML) }
format.text { render(:inline => "Different Text Part") }
end
end
protected
def mail_with_defaults(&block)
mail(:to => "test@localhost", :from => "tester@example.com",
:subject => "using helpers", &block)
end
end
class InlineCssHookTest < ActionMailer::TestCase
def test_inline_css_hook_with_only_html_part
mail = HelperMailer.use_inline_css_hook_with_only_html_part.deliver
assert_match '<div id="test" style="color: #123456;">Test</div>', mail.html_part.body.encoded
# Test generated text part
assert_match 'Test', mail.text_part.body.encoded
end
def test_inline_css_hook_with_text_and_html_parts
mail = HelperMailer.use_inline_css_hook_with_text_and_html_parts.deliver
assert_match '<div id="test" style="color: #123456;">Test</div>', mail.html_part.body.encoded
# Test specified text part
assert_match 'Different Text Part', mail.text_part.body.encoded
end
end