1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionmailer/test/old_base/mail_layout_test.rb

127 lines
3.4 KiB
Ruby
Raw Normal View History

require 'abstract_unit'
class AutoLayoutMailer < ActionMailer::Base
2010-01-26 10:27:21 -05:00
2010-01-24 11:31:18 -05:00
def hello
recipients 'test@localhost'
subject "You have a mail"
from "tester@example.com"
end
2010-01-24 11:31:18 -05:00
def spam
recipients 'test@localhost'
subject "You have a mail"
from "tester@example.com"
@world = "Earth"
body render(:inline => "Hello, <%= @world %>", :layout => 'spam')
end
2010-01-24 11:31:18 -05:00
def nolayout
recipients 'test@localhost'
subject "You have a mail"
from "tester@example.com"
@world = "Earth"
body render(:inline => "Hello, <%= @world %>", :layout => false)
end
2010-01-24 11:31:18 -05:00
def multipart(type = nil)
recipients 'test@localhost'
subject "You have a mail"
from "tester@example.com"
content_type(type) if type
end
end
class ExplicitLayoutMailer < ActionMailer::Base
layout 'spam', :except => [:logout]
2010-01-24 11:31:18 -05:00
def signup
recipients 'test@localhost'
subject "You have a mail"
from "tester@example.com"
end
2010-01-24 11:31:18 -05:00
def logout
recipients 'test@localhost'
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.clear
end
def teardown
restore_delivery_method
end
def test_should_pickup_default_layout
2010-01-24 11:31:18 -05:00
mail = AutoLayoutMailer.hello
assert_equal "Hello from layout Inside", mail.body.to_s.strip
end
def test_should_pickup_multipart_layout
2010-01-24 11:31:18 -05:00
mail = AutoLayoutMailer.multipart
assert_equal "multipart/alternative", mail.mime_type
assert_equal 2, mail.parts.size
assert_equal 'text/plain', mail.parts.first.mime_type
assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.to_s
assert_equal 'text/html', mail.parts.last.mime_type
assert_equal "Hello from layout text/html multipart", mail.parts.last.body.to_s
end
def test_should_pickup_multipartmixed_layout
2010-01-24 11:31:18 -05:00
mail = AutoLayoutMailer.multipart("multipart/mixed")
assert_equal "multipart/mixed", mail.mime_type
assert_equal 2, mail.parts.size
assert_equal 'text/plain', mail.parts.first.mime_type
assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.to_s
assert_equal 'text/html', mail.parts.last.mime_type
assert_equal "Hello from layout text/html multipart", mail.parts.last.body.to_s
end
def test_should_fix_multipart_layout
2010-01-24 11:31:18 -05:00
mail = AutoLayoutMailer.multipart("text/plain")
assert_equal "multipart/alternative", mail.mime_type
assert_equal 2, mail.parts.size
assert_equal 'text/plain', mail.parts.first.mime_type
assert_equal "text/plain layout - text/plain multipart", mail.parts.first.body.to_s
assert_equal 'text/html', mail.parts.last.mime_type
assert_equal "Hello from layout text/html multipart", mail.parts.last.body.to_s
end
def test_should_pickup_layout_given_to_render
2010-01-24 11:31:18 -05:00
mail = AutoLayoutMailer.spam
assert_equal "Spammer layout Hello, Earth", mail.body.to_s.strip
end
def test_should_respect_layout_false
2010-01-24 11:31:18 -05:00
mail = AutoLayoutMailer.nolayout
assert_equal "Hello, Earth", mail.body.to_s.strip
end
def test_explicit_class_layout
2010-01-24 11:31:18 -05:00
mail = ExplicitLayoutMailer.signup
assert_equal "Spammer layout We do not spam", mail.body.to_s.strip
end
def test_explicit_layout_exceptions
2010-01-24 11:31:18 -05:00
mail = ExplicitLayoutMailer.logout
assert_equal "You logged out", mail.body.to_s.strip
end
end