2008-09-09 18:25:09 -04:00
|
|
|
require 'abstract_unit'
|
|
|
|
|
|
|
|
class AutoLayoutMailer < ActionMailer::Base
|
|
|
|
def hello(recipient)
|
|
|
|
recipients recipient
|
|
|
|
subject "You have a mail"
|
|
|
|
from "tester@example.com"
|
|
|
|
end
|
|
|
|
|
|
|
|
def spam(recipient)
|
|
|
|
recipients recipient
|
|
|
|
subject "You have a mail"
|
|
|
|
from "tester@example.com"
|
2009-10-21 19:26:10 -04:00
|
|
|
|
|
|
|
@world = "Earth"
|
|
|
|
render(:inline => "Hello, <%= @world %>", :layout => 'spam')
|
2008-09-09 18:25:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def nolayout(recipient)
|
|
|
|
recipients recipient
|
|
|
|
subject "You have a mail"
|
|
|
|
from "tester@example.com"
|
2009-10-21 19:26:10 -04:00
|
|
|
|
|
|
|
@world = "Earth"
|
|
|
|
render(:inline => "Hello, <%= @world %>", :layout => false)
|
2008-09-09 18:25:09 -04:00
|
|
|
end
|
2008-11-20 16:39:34 -05:00
|
|
|
|
2009-03-10 12:23:52 -04:00
|
|
|
def multipart(recipient, type = nil)
|
2008-11-20 16:39:34 -05:00
|
|
|
recipients recipient
|
|
|
|
subject "You have a mail"
|
|
|
|
from "tester@example.com"
|
2009-03-10 12:23:52 -04:00
|
|
|
|
|
|
|
content_type(type) if type
|
2008-11-20 16:39:34 -05:00
|
|
|
end
|
2008-09-09 18:25:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class ExplicitLayoutMailer < ActionMailer::Base
|
|
|
|
layout 'spam', :except => [:logout]
|
|
|
|
|
|
|
|
def signup(recipient)
|
|
|
|
recipients recipient
|
|
|
|
subject "You have a mail"
|
|
|
|
from "tester@example.com"
|
|
|
|
end
|
|
|
|
|
|
|
|
def logout(recipient)
|
|
|
|
recipients recipient
|
|
|
|
subject "You have a mail"
|
|
|
|
from "tester@example.com"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class LayoutMailerTest < Test::Unit::TestCase
|
|
|
|
def setup
|
|
|
|
set_delivery_method :test
|
|
|
|
ActionMailer::Base.perform_deliveries = true
|
|
|
|
ActionMailer::Base.deliveries = []
|
|
|
|
|
|
|
|
@recipient = 'test@localhost'
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
restore_delivery_method
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_should_pickup_default_layout
|
|
|
|
mail = AutoLayoutMailer.create_hello(@recipient)
|
2009-12-27 04:56:16 -05:00
|
|
|
assert_equal "Hello from layout Inside", mail.body.to_s.strip
|
2008-09-09 18:25:09 -04:00
|
|
|
end
|
|
|
|
|
2008-11-20 16:39:34 -05:00
|
|
|
def test_should_pickup_multipart_layout
|
|
|
|
mail = AutoLayoutMailer.create_multipart(@recipient)
|
2009-11-12 00:08:50 -05:00
|
|
|
# CHANGED: content_type returns an object
|
|
|
|
# assert_equal "multipart/alternative", mail.content_type
|
2009-11-20 05:19:10 -05:00
|
|
|
assert_equal "multipart/alternative", mail.content_type.string
|
2009-03-10 12:23:52 -04:00
|
|
|
assert_equal 2, mail.parts.size
|
|
|
|
|
2009-11-12 00:08:50 -05:00
|
|
|
# CHANGED: content_type returns an object
|
|
|
|
# assert_equal 'text/plain', mail.parts.first.content_type
|
2009-11-20 05:19:10 -05:00
|
|
|
assert_equal 'text/plain', mail.parts.first.content_type.string
|
2009-11-12 00:08:50 -05:00
|
|
|
|
|
|
|
# CHANGED: body returns an object
|
|
|
|
# assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body
|
2009-12-27 04:56:16 -05:00
|
|
|
assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.to_s
|
2009-03-10 12:23:52 -04:00
|
|
|
|
2009-11-12 00:08:50 -05:00
|
|
|
# CHANGED: content_type returns an object
|
|
|
|
# assert_equal 'text/html', mail.parts.last.content_type
|
2009-11-20 05:19:10 -05:00
|
|
|
assert_equal 'text/html', mail.parts.last.content_type.string
|
2009-11-12 00:08:50 -05:00
|
|
|
|
|
|
|
# CHANGED: body returns an object
|
|
|
|
# assert_equal "Hello from layout text/html multipart", mail.parts.last.body
|
2009-12-27 04:56:16 -05:00
|
|
|
assert_equal "Hello from layout text/html multipart", mail.parts.last.body.to_s
|
2009-03-10 12:23:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_should_pickup_multipartmixed_layout
|
|
|
|
mail = AutoLayoutMailer.create_multipart(@recipient, "multipart/mixed")
|
2009-11-12 00:08:50 -05:00
|
|
|
# CHANGED: content_type returns an object
|
|
|
|
# assert_equal "multipart/mixed", mail.content_type
|
2009-11-20 05:19:10 -05:00
|
|
|
assert_equal "multipart/mixed", mail.content_type.string
|
2008-11-20 16:39:34 -05:00
|
|
|
assert_equal 2, mail.parts.size
|
|
|
|
|
2009-11-12 00:08:50 -05:00
|
|
|
# CHANGED: content_type returns an object
|
|
|
|
# assert_equal 'text/plain', mail.parts.first.content_type
|
2009-11-20 05:19:10 -05:00
|
|
|
assert_equal 'text/plain', mail.parts.first.content_type.string
|
2009-11-12 00:08:50 -05:00
|
|
|
# CHANGED: body returns an object
|
|
|
|
# assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body
|
2009-12-27 04:56:16 -05:00
|
|
|
assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.to_s
|
2008-11-20 16:39:34 -05:00
|
|
|
|
2009-11-12 00:08:50 -05:00
|
|
|
# CHANGED: content_type returns an object
|
|
|
|
# assert_equal 'text/html', mail.parts.last.content_type
|
2009-11-20 05:19:10 -05:00
|
|
|
assert_equal 'text/html', mail.parts.last.content_type.string
|
2009-11-12 00:08:50 -05:00
|
|
|
# CHANGED: body returns an object
|
|
|
|
# assert_equal "Hello from layout text/html multipart", mail.parts.last.body
|
2009-12-27 04:56:16 -05:00
|
|
|
assert_equal "Hello from layout text/html multipart", mail.parts.last.body.to_s
|
2008-11-20 16:39:34 -05:00
|
|
|
end
|
|
|
|
|
2009-03-10 12:23:52 -04:00
|
|
|
def test_should_fix_multipart_layout
|
|
|
|
mail = AutoLayoutMailer.create_multipart(@recipient, "text/plain")
|
2009-11-20 05:19:10 -05:00
|
|
|
assert_equal "multipart/alternative", mail.content_type.string
|
2009-03-10 12:23:52 -04:00
|
|
|
assert_equal 2, mail.parts.size
|
|
|
|
|
2009-11-20 05:19:10 -05:00
|
|
|
assert_equal 'text/plain', mail.parts.first.content_type.string
|
2009-12-27 04:56:16 -05:00
|
|
|
assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.to_s
|
2009-03-10 12:23:52 -04:00
|
|
|
|
2009-11-20 05:19:10 -05:00
|
|
|
assert_equal 'text/html', mail.parts.last.content_type.string
|
2009-12-27 04:56:16 -05:00
|
|
|
assert_equal "Hello from layout text/html multipart", mail.parts.last.body.to_s
|
2009-03-10 12:23:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2008-09-09 18:25:09 -04:00
|
|
|
def test_should_pickup_layout_given_to_render
|
|
|
|
mail = AutoLayoutMailer.create_spam(@recipient)
|
2009-12-27 04:56:16 -05:00
|
|
|
assert_equal "Spammer layout Hello, Earth", mail.body.to_s.strip
|
2008-09-09 18:25:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_should_respect_layout_false
|
|
|
|
mail = AutoLayoutMailer.create_nolayout(@recipient)
|
2009-12-27 04:56:16 -05:00
|
|
|
assert_equal "Hello, Earth", mail.body.to_s.strip
|
2008-09-09 18:25:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_explicit_class_layout
|
|
|
|
mail = ExplicitLayoutMailer.create_signup(@recipient)
|
2009-12-27 04:56:16 -05:00
|
|
|
assert_equal "Spammer layout We do not spam", mail.body.to_s.strip
|
2008-09-09 18:25:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_explicit_layout_exceptions
|
|
|
|
mail = ExplicitLayoutMailer.create_logout(@recipient)
|
2009-12-27 04:56:16 -05:00
|
|
|
assert_equal "You logged out", mail.body.to_s.strip
|
2008-09-09 18:25:09 -04:00
|
|
|
end
|
|
|
|
end
|