Skip to content

Commit

Permalink
Added test for generated/specified text parts
Browse files Browse the repository at this point in the history
  • Loading branch information
ndbroadbent committed Sep 13, 2011
1 parent f66e7b1 commit 8c31c8d
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions test/inline_css_hook_test.rb
@@ -1,11 +1,6 @@
require 'abstract_unit'

class HelperMailer < ActionMailer::Base
helper ActionMailer::InlineCssHelper

def use_inline_css_hook
mail_with_defaults do |format|
format.html { render(:inline => %Q{
TEST_HTML = %Q{
<html>
<head>
<style>
Expand All @@ -15,9 +10,21 @@ def use_inline_css_hook
<body>
<div id="test">Test</div>
</body>
</html>
}) }
format.text { render(:inline => "Text Part") }
</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

Expand All @@ -29,10 +36,20 @@ def mail_with_defaults(&block)
end
end


class InlineCssHookTest < ActionMailer::TestCase
def test_inline_css_hook
mail = HelperMailer.use_inline_css_hook.deliver
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

0 comments on commit 8c31c8d

Please sign in to comment.