Froze rails gems
[depot.git] / vendor / rails / actionmailer / test / mail_layout_test.rb
1 require 'abstract_unit'
2
3 class AutoLayoutMailer < ActionMailer::Base
4 def hello(recipient)
5 recipients recipient
6 subject "You have a mail"
7 from "tester@example.com"
8 end
9
10 def spam(recipient)
11 recipients recipient
12 subject "You have a mail"
13 from "tester@example.com"
14 body render(:inline => "Hello, <%= @world %>", :layout => 'spam', :body => { :world => "Earth" })
15 end
16
17 def nolayout(recipient)
18 recipients recipient
19 subject "You have a mail"
20 from "tester@example.com"
21 body render(:inline => "Hello, <%= @world %>", :layout => false, :body => { :world => "Earth" })
22 end
23 end
24
25 class ExplicitLayoutMailer < ActionMailer::Base
26 layout 'spam', :except => [:logout]
27
28 def signup(recipient)
29 recipients recipient
30 subject "You have a mail"
31 from "tester@example.com"
32 end
33
34 def logout(recipient)
35 recipients recipient
36 subject "You have a mail"
37 from "tester@example.com"
38 end
39 end
40
41 class LayoutMailerTest < Test::Unit::TestCase
42 def setup
43 set_delivery_method :test
44 ActionMailer::Base.perform_deliveries = true
45 ActionMailer::Base.deliveries = []
46
47 @recipient = 'test@localhost'
48 end
49
50 def teardown
51 restore_delivery_method
52 end
53
54 def test_should_pickup_default_layout
55 mail = AutoLayoutMailer.create_hello(@recipient)
56 assert_equal "Hello from layout Inside", mail.body.strip
57 end
58
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
62 end
63
64 def test_should_respect_layout_false
65 mail = AutoLayoutMailer.create_nolayout(@recipient)
66 assert_equal "Hello, Earth", mail.body.strip
67 end
68
69 def test_explicit_class_layout
70 mail = ExplicitLayoutMailer.create_signup(@recipient)
71 assert_equal "Spammer layout We do not spam", mail.body.strip
72 end
73
74 def test_explicit_layout_exceptions
75 mail = ExplicitLayoutMailer.create_logout(@recipient)
76 assert_equal "You logged out", mail.body.strip
77 end
78 end