Updated README.rdoc again
[feedcatcher.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
24 def multipart(recipient, type = nil)
25 recipients recipient
26 subject "You have a mail"
27 from "tester@example.com"
28
29 content_type(type) if type
30 end
31 end
32
33 class ExplicitLayoutMailer < ActionMailer::Base
34 layout 'spam', :except => [:logout]
35
36 def signup(recipient)
37 recipients recipient
38 subject "You have a mail"
39 from "tester@example.com"
40 end
41
42 def logout(recipient)
43 recipients recipient
44 subject "You have a mail"
45 from "tester@example.com"
46 end
47 end
48
49 class LayoutMailerTest < Test::Unit::TestCase
50 def setup
51 set_delivery_method :test
52 ActionMailer::Base.perform_deliveries = true
53 ActionMailer::Base.deliveries = []
54
55 @recipient = 'test@localhost'
56 end
57
58 def teardown
59 restore_delivery_method
60 end
61
62 def test_should_pickup_default_layout
63 mail = AutoLayoutMailer.create_hello(@recipient)
64 assert_equal "Hello from layout Inside", mail.body.strip
65 end
66
67 def test_should_pickup_multipart_layout
68 mail = AutoLayoutMailer.create_multipart(@recipient)
69 assert_equal "multipart/alternative", mail.content_type
70 assert_equal 2, mail.parts.size
71
72 assert_equal 'text/plain', mail.parts.first.content_type
73 assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body
74
75 assert_equal 'text/html', mail.parts.last.content_type
76 assert_equal "Hello from layout text/html multipart", mail.parts.last.body
77 end
78
79 def test_should_pickup_multipartmixed_layout
80 mail = AutoLayoutMailer.create_multipart(@recipient, "multipart/mixed")
81 assert_equal "multipart/mixed", mail.content_type
82 assert_equal 2, mail.parts.size
83
84 assert_equal 'text/plain', mail.parts.first.content_type
85 assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body
86
87 assert_equal 'text/html', mail.parts.last.content_type
88 assert_equal "Hello from layout text/html multipart", mail.parts.last.body
89 end
90
91 def test_should_fix_multipart_layout
92 mail = AutoLayoutMailer.create_multipart(@recipient, "text/plain")
93 assert_equal "multipart/alternative", mail.content_type
94 assert_equal 2, mail.parts.size
95
96 assert_equal 'text/plain', mail.parts.first.content_type
97 assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body
98
99 assert_equal 'text/html', mail.parts.last.content_type
100 assert_equal "Hello from layout text/html multipart", mail.parts.last.body
101 end
102
103
104 def test_should_pickup_layout_given_to_render
105 mail = AutoLayoutMailer.create_spam(@recipient)
106 assert_equal "Spammer layout Hello, Earth", mail.body.strip
107 end
108
109 def test_should_respect_layout_false
110 mail = AutoLayoutMailer.create_nolayout(@recipient)
111 assert_equal "Hello, Earth", mail.body.strip
112 end
113
114 def test_explicit_class_layout
115 mail = ExplicitLayoutMailer.create_signup(@recipient)
116 assert_equal "Spammer layout We do not spam", mail.body.strip
117 end
118
119 def test_explicit_layout_exceptions
120 mail = ExplicitLayoutMailer.create_logout(@recipient)
121 assert_equal "You logged out", mail.body.strip
122 end
123 end