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_render_test.rb

158 lines
3.8 KiB
Ruby
Raw Normal View History

require 'abstract_unit'
class RenderMailer < ActionMailer::Base
2010-01-24 11:31:18 -05:00
def inline_template
recipients 'test@localhost'
subject "using helpers"
from "tester@example.com"
@world = "Earth"
render :inline => "Hello, <%= @world %>"
end
2010-01-24 11:31:18 -05:00
def file_template
recipients 'test@localhost'
subject "using helpers"
from "tester@example.com"
2010-01-24 11:31:18 -05:00
@recipient = 'test@localhost'
render :file => "templates/signed_up"
end
2010-01-24 11:31:18 -05:00
def implicit_body
recipients 'test@localhost'
subject "using helpers"
from "tester@example.com"
2010-01-24 11:31:18 -05:00
@recipient = 'test@localhost'
render :template => "templates/signed_up"
end
2010-01-24 11:31:18 -05:00
def rxml_template
recipients 'test@localhost'
subject "rendering rxml template"
from "tester@example.com"
end
2010-01-24 11:31:18 -05:00
def included_subtemplate
recipients 'test@localhost'
subject "Including another template in the one being rendered"
from "tester@example.com"
end
2010-01-24 11:31:18 -05:00
def mailer_accessor
recipients 'test@localhost'
subject "Mailer Accessor"
from "tester@example.com"
render :inline => "Look, <%= mailer.subject %>!"
end
2010-01-24 11:31:18 -05:00
def no_instance_variable
recipients 'test@localhost'
subject "No Instance Variable"
from "tester@example.com"
silence_warnings do
render :inline => "Look, subject.nil? is <%= @subject.nil? %>!"
end
end
def initialize_defaults(method_name)
super
mailer_name "test_mailer"
end
end
class FirstMailer < ActionMailer::Base
2010-01-24 11:31:18 -05:00
def share
recipients 'test@localhost'
subject "using helpers"
from "tester@example.com"
end
end
class SecondMailer < ActionMailer::Base
2010-01-24 11:31:18 -05:00
def share
recipients 'test@localhost'
subject "using helpers"
from "tester@example.com"
end
end
# CHANGED: Those tests were changed because body returns an object now
# Instead of mail.body.strip, we should mail.body.to_s.strip
class RenderHelperTest < Test::Unit::TestCase
def setup
set_delivery_method :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries.clear
@recipient = 'test@localhost'
end
def teardown
restore_delivery_method
end
def test_implicit_body
2010-01-24 11:31:18 -05:00
mail = RenderMailer.implicit_body
assert_equal "Hello there, \n\nMr. test@localhost", mail.body.to_s.strip
end
def test_inline_template
2010-01-24 11:31:18 -05:00
mail = RenderMailer.inline_template
assert_equal "Hello, Earth", mail.body.to_s.strip
end
def test_file_template
2010-01-24 11:31:18 -05:00
mail = RenderMailer.file_template
assert_equal "Hello there, \n\nMr. test@localhost", mail.body.to_s.strip
end
def test_rxml_template
2010-01-24 11:31:18 -05:00
mail = RenderMailer.rxml_template.deliver
assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test/>", mail.body.to_s.strip
end
def test_included_subtemplate
2010-01-24 11:31:18 -05:00
mail = RenderMailer.included_subtemplate.deliver
assert_equal "Hey Ho, let's go!", mail.body.to_s.strip
end
def test_mailer_accessor
2010-01-24 11:31:18 -05:00
mail = RenderMailer.mailer_accessor.deliver
assert_equal "Look, Mailer Accessor!", mail.body.to_s.strip
end
def test_no_instance_variable
2010-01-24 11:31:18 -05:00
mail = RenderMailer.no_instance_variable.deliver
assert_equal "Look, subject.nil? is true!", mail.body.to_s.strip
end
end
class FirstSecondHelperTest < Test::Unit::TestCase
def setup
set_delivery_method :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries.clear
@recipient = 'test@localhost'
end
def teardown
restore_delivery_method
end
def test_ordering
2010-01-24 11:31:18 -05:00
mail = FirstMailer.share
assert_equal "first mail", mail.body.to_s.strip
2010-01-24 11:31:18 -05:00
mail = SecondMailer.share
assert_equal "second mail", mail.body.to_s.strip
2010-01-24 11:31:18 -05:00
mail = FirstMailer.share
assert_equal "first mail", mail.body.to_s.strip
2010-01-24 11:31:18 -05:00
mail = SecondMailer.share
assert_equal "second mail", mail.body.to_s.strip
end
end