1 require 'abstract_unit'
3 class AutoLayoutMailer
< ActionMailer
::Base
6 subject
"You have a mail"
7 from
"tester@example.com"
12 subject
"You have a mail"
13 from
"tester@example.com"
14 body
render(:inline => "Hello, <%= @world %>", :layout => 'spam', :body => { :world => "Earth" })
17 def nolayout(recipient
)
19 subject
"You have a mail"
20 from
"tester@example.com"
21 body
render(:inline => "Hello, <%= @world %>", :layout => false, :body => { :world => "Earth" })
25 class ExplicitLayoutMailer
< ActionMailer
::Base
26 layout
'spam', :except => [:logout]
30 subject
"You have a mail"
31 from
"tester@example.com"
36 subject
"You have a mail"
37 from
"tester@example.com"
41 class LayoutMailerTest
< Test
::Unit::TestCase
43 set_delivery_method
:test
44 ActionMailer
::Base.perform_deliveries
= true
45 ActionMailer
::Base.deliveries
= []
47 @recipient = 'test@localhost'
51 restore_delivery_method
54 def test_should_pickup_default_layout
55 mail
= AutoLayoutMailer
.create_hello(@recipient)
56 assert_equal
"Hello from layout Inside", mail
.body
.strip
59 def test_should_pickup_layout_given_to_render
60 mail
= AutoLayoutMailer
.create_spam(@recipient)
61 assert_equal
"Spammer layout Hello, Earth", mail
.body
.strip
64 def test_should_respect_layout_false
65 mail
= AutoLayoutMailer
.create_nolayout(@recipient)
66 assert_equal
"Hello, Earth", mail
.body
.strip
69 def test_explicit_class_layout
70 mail
= ExplicitLayoutMailer
.create_signup(@recipient)
71 assert_equal
"Spammer layout We do not spam", mail
.body
.strip
74 def test_explicit_layout_exceptions
75 mail
= ExplicitLayoutMailer
.create_logout(@recipient)
76 assert_equal
"You logged out", mail
.body
.strip