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" })
24
def multipart(recipient, type = nil)
26
subject "You have a mail"
27
from "tester@example.com"
29
content_type(type) if type
33
class ExplicitLayoutMailer < ActionMailer::Base
34
layout 'spam', :except => [:logout]
38
subject "You have a mail"
39
from "tester@example.com"
44
subject "You have a mail"
45
from "tester@example.com"
49
class LayoutMailerTest < Test::Unit::TestCase
51
set_delivery_method :test
52
ActionMailer::Base.perform_deliveries = true
53
ActionMailer::Base.deliveries = []
55
@recipient = 'test@localhost'
59
restore_delivery_method
62
def test_should_pickup_default_layout
63
mail = AutoLayoutMailer.create_hello(@recipient)
64
assert_equal "Hello from layout Inside", mail.body.strip
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
72
assert_equal 'text/plain', mail.parts.first.content_type
73
assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body
75
assert_equal 'text/html', mail.parts.last.content_type
76
assert_equal "Hello from layout text/html multipart", mail.parts.last.body
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
84
assert_equal 'text/plain', mail.parts.first.content_type
85
assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body
87
assert_equal 'text/html', mail.parts.last.content_type
88
assert_equal "Hello from layout text/html multipart", mail.parts.last.body
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
96
assert_equal 'text/plain', mail.parts.first.content_type
97
assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body
99
assert_equal 'text/html', mail.parts.last.content_type
100
assert_equal "Hello from layout text/html multipart", mail.parts.last.body
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
109
def test_should_respect_layout_false
110
mail = AutoLayoutMailer.create_nolayout(@recipient)
111
assert_equal "Hello, Earth", mail.body.strip
114
def test_explicit_class_layout
115
mail = ExplicitLayoutMailer.create_signup(@recipient)
116
assert_equal "Spammer layout We do not spam", mail.body.strip
119
def test_explicit_layout_exceptions
120
mail = ExplicitLayoutMailer.create_logout(@recipient)
121
assert_equal "You logged out", mail.body.strip