2008-01-05 08:32:22 -05:00
|
|
|
require 'abstract_unit'
|
2005-08-22 17:17:01 -04:00
|
|
|
|
|
|
|
class RenderMailer < ActionMailer::Base
|
2010-01-24 11:31:18 -05:00
|
|
|
def inline_template
|
|
|
|
recipients 'test@localhost'
|
2005-08-22 17:17:01 -04:00
|
|
|
subject "using helpers"
|
|
|
|
from "tester@example.com"
|
2009-10-21 19:26:10 -04:00
|
|
|
|
|
|
|
@world = "Earth"
|
|
|
|
render :inline => "Hello, <%= @world %>"
|
2005-08-22 17:17:01 -04:00
|
|
|
end
|
|
|
|
|
2010-01-24 11:31:18 -05:00
|
|
|
def file_template
|
|
|
|
recipients 'test@localhost'
|
2005-08-22 17:17:01 -04:00
|
|
|
subject "using helpers"
|
|
|
|
from "tester@example.com"
|
2009-10-21 19:26:10 -04:00
|
|
|
|
2010-01-24 11:31:18 -05:00
|
|
|
@recipient = 'test@localhost'
|
2009-10-21 19:26:10 -04:00
|
|
|
render :file => "templates/signed_up"
|
2009-10-18 20:52:36 -04:00
|
|
|
end
|
|
|
|
|
2010-01-24 11:31:18 -05:00
|
|
|
def implicit_body
|
|
|
|
recipients 'test@localhost'
|
2009-10-18 20:52:36 -04:00
|
|
|
subject "using helpers"
|
|
|
|
from "tester@example.com"
|
|
|
|
|
2010-01-24 11:31:18 -05:00
|
|
|
@recipient = 'test@localhost'
|
2009-10-21 19:26:10 -04:00
|
|
|
render :template => "templates/signed_up"
|
2005-08-22 17:17:01 -04:00
|
|
|
end
|
|
|
|
|
2010-01-24 11:31:18 -05:00
|
|
|
def rxml_template
|
|
|
|
recipients 'test@localhost'
|
2007-10-15 16:30:48 -04:00
|
|
|
subject "rendering rxml template"
|
|
|
|
from "tester@example.com"
|
|
|
|
end
|
2008-08-22 14:43:34 -04:00
|
|
|
|
2010-01-24 11:31:18 -05:00
|
|
|
def included_subtemplate
|
|
|
|
recipients 'test@localhost'
|
2007-11-18 17:01:33 -05:00
|
|
|
subject "Including another template in the one being rendered"
|
|
|
|
from "tester@example.com"
|
|
|
|
end
|
2008-08-22 14:43:34 -04:00
|
|
|
|
2010-01-24 11:31:18 -05:00
|
|
|
def mailer_accessor
|
|
|
|
recipients 'test@localhost'
|
2009-12-25 15:35:40 -05:00
|
|
|
subject "Mailer Accessor"
|
2007-11-25 22:36:28 -05:00
|
|
|
from "tester@example.com"
|
2009-10-21 19:26:10 -04:00
|
|
|
|
2009-12-25 15:35:40 -05:00
|
|
|
render :inline => "Look, <%= mailer.subject %>!"
|
|
|
|
end
|
|
|
|
|
2010-01-24 11:31:18 -05:00
|
|
|
def no_instance_variable
|
|
|
|
recipients 'test@localhost'
|
2009-12-25 15:35:40 -05:00
|
|
|
subject "No Instance Variable"
|
|
|
|
from "tester@example.com"
|
|
|
|
|
2009-12-27 06:18:46 -05:00
|
|
|
silence_warnings do
|
|
|
|
render :inline => "Look, subject.nil? is <%= @subject.nil? %>!"
|
|
|
|
end
|
2007-11-25 22:36:28 -05:00
|
|
|
end
|
2007-10-15 16:30:48 -04:00
|
|
|
|
2005-08-22 17:17:01 -04:00
|
|
|
def initialize_defaults(method_name)
|
|
|
|
super
|
|
|
|
mailer_name "test_mailer"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-06-28 21:54:16 -04:00
|
|
|
class FirstMailer < ActionMailer::Base
|
2010-01-24 11:31:18 -05:00
|
|
|
def share
|
|
|
|
recipients 'test@localhost'
|
2006-06-28 21:54:16 -04:00
|
|
|
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'
|
2006-06-28 21:54:16 -04:00
|
|
|
subject "using helpers"
|
|
|
|
from "tester@example.com"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-12-27 06:09:20 -05:00
|
|
|
# CHANGED: Those tests were changed because body returns an object now
|
|
|
|
# Instead of mail.body.strip, we should mail.body.to_s.strip
|
2005-08-22 17:17:01 -04:00
|
|
|
class RenderHelperTest < Test::Unit::TestCase
|
|
|
|
def setup
|
2007-11-07 11:05:17 -05:00
|
|
|
set_delivery_method :test
|
2005-08-22 17:17:01 -04:00
|
|
|
ActionMailer::Base.perform_deliveries = true
|
2010-01-23 19:15:42 -05:00
|
|
|
ActionMailer::Base.deliveries.clear
|
2005-08-22 17:17:01 -04:00
|
|
|
|
|
|
|
@recipient = 'test@localhost'
|
|
|
|
end
|
|
|
|
|
2007-11-07 11:05:17 -05:00
|
|
|
def teardown
|
|
|
|
restore_delivery_method
|
|
|
|
end
|
|
|
|
|
2009-10-18 20:52:36 -04:00
|
|
|
def test_implicit_body
|
2010-01-24 11:31:18 -05:00
|
|
|
mail = RenderMailer.implicit_body
|
2009-12-27 04:56:16 -05:00
|
|
|
assert_equal "Hello there, \n\nMr. test@localhost", mail.body.to_s.strip
|
2009-10-18 20:52:36 -04:00
|
|
|
end
|
|
|
|
|
2005-08-22 17:17:01 -04:00
|
|
|
def test_inline_template
|
2010-01-24 11:31:18 -05:00
|
|
|
mail = RenderMailer.inline_template
|
2009-12-27 04:56:16 -05:00
|
|
|
assert_equal "Hello, Earth", mail.body.to_s.strip
|
2005-08-22 17:17:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_file_template
|
2010-01-24 11:31:18 -05:00
|
|
|
mail = RenderMailer.file_template
|
2009-12-27 04:56:16 -05:00
|
|
|
assert_equal "Hello there, \n\nMr. test@localhost", mail.body.to_s.strip
|
2005-08-22 17:17:01 -04:00
|
|
|
end
|
2007-10-15 16:30:48 -04:00
|
|
|
|
|
|
|
def test_rxml_template
|
2010-01-24 11:31:18 -05:00
|
|
|
mail = RenderMailer.rxml_template.deliver
|
2009-12-27 04:56:16 -05:00
|
|
|
assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test/>", mail.body.to_s.strip
|
2007-10-15 16:30:48 -04:00
|
|
|
end
|
2008-08-22 14:43:34 -04:00
|
|
|
|
2007-11-18 17:01:33 -05:00
|
|
|
def test_included_subtemplate
|
2010-01-24 11:31:18 -05:00
|
|
|
mail = RenderMailer.included_subtemplate.deliver
|
2009-12-27 04:56:16 -05:00
|
|
|
assert_equal "Hey Ho, let's go!", mail.body.to_s.strip
|
2007-11-18 17:01:33 -05:00
|
|
|
end
|
2009-12-25 15:35:40 -05:00
|
|
|
|
|
|
|
def test_mailer_accessor
|
2010-01-24 11:31:18 -05:00
|
|
|
mail = RenderMailer.mailer_accessor.deliver
|
2009-12-27 06:09:20 -05:00
|
|
|
assert_equal "Look, Mailer Accessor!", mail.body.to_s.strip
|
2009-12-25 15:35:40 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_no_instance_variable
|
2010-01-24 11:31:18 -05:00
|
|
|
mail = RenderMailer.no_instance_variable.deliver
|
2009-12-27 06:09:20 -05:00
|
|
|
assert_equal "Look, subject.nil? is true!", mail.body.to_s.strip
|
2009-12-25 15:35:40 -05:00
|
|
|
end
|
2005-08-22 17:17:01 -04:00
|
|
|
end
|
|
|
|
|
2006-06-28 21:54:16 -04:00
|
|
|
class FirstSecondHelperTest < Test::Unit::TestCase
|
|
|
|
def setup
|
2007-11-07 11:05:17 -05:00
|
|
|
set_delivery_method :test
|
2006-06-28 21:54:16 -04:00
|
|
|
ActionMailer::Base.perform_deliveries = true
|
2010-01-23 19:15:42 -05:00
|
|
|
ActionMailer::Base.deliveries.clear
|
2006-06-28 21:54:16 -04:00
|
|
|
|
|
|
|
@recipient = 'test@localhost'
|
|
|
|
end
|
|
|
|
|
2007-11-07 11:05:17 -05:00
|
|
|
def teardown
|
|
|
|
restore_delivery_method
|
|
|
|
end
|
|
|
|
|
2006-06-28 21:54:16 -04:00
|
|
|
def test_ordering
|
2010-01-24 11:31:18 -05:00
|
|
|
mail = FirstMailer.share
|
2009-12-27 04:56:16 -05:00
|
|
|
assert_equal "first mail", mail.body.to_s.strip
|
2010-01-24 11:31:18 -05:00
|
|
|
mail = SecondMailer.share
|
2009-12-27 04:56:16 -05:00
|
|
|
assert_equal "second mail", mail.body.to_s.strip
|
2010-01-24 11:31:18 -05:00
|
|
|
mail = FirstMailer.share
|
2009-12-27 04:56:16 -05:00
|
|
|
assert_equal "first mail", mail.body.to_s.strip
|
2010-01-24 11:31:18 -05:00
|
|
|
mail = SecondMailer.share
|
2009-12-27 04:56:16 -05:00
|
|
|
assert_equal "second mail", mail.body.to_s.strip
|
2006-06-28 21:54:16 -04:00
|
|
|
end
|
|
|
|
end
|