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"
|
2010-01-26 13:15:20 -05:00
|
|
|
body 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'
|
2010-01-26 13:15:20 -05:00
|
|
|
body render(:file => "templates/signed_up")
|
2005-08-22 17:17:01 -04:00
|
|
|
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
|
2010-01-26 13:15:20 -05:00
|
|
|
body render(:inline => "Look, subject.nil? is <%= @subject.nil? %>!")
|
2009-12-27 06:18:46 -05:00
|
|
|
end
|
2007-11-25 22:36:28 -05:00
|
|
|
end
|
2007-10-15 16:30:48 -04:00
|
|
|
|
2010-01-26 10:37:20 -05:00
|
|
|
def multipart_alternative
|
|
|
|
recipients 'test@localhost'
|
|
|
|
subject 'multipart/alternative'
|
|
|
|
from 'tester@example.com'
|
|
|
|
|
|
|
|
build_multipart_message(:foo => "bar")
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def build_multipart_message(assigns = {})
|
|
|
|
content_type "multipart/alternative"
|
|
|
|
|
|
|
|
part "text/plain" do |p|
|
|
|
|
p.body = build_body_part('plain', assigns, :layout => false)
|
|
|
|
end
|
|
|
|
|
|
|
|
part "text/html" do |p|
|
|
|
|
p.body = build_body_part('html', assigns)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_body_part(content_type, assigns, options = {})
|
2010-01-26 13:50:59 -05:00
|
|
|
ActiveSupport::Deprecation.silence do
|
|
|
|
render "#{template}.#{content_type}", :body => assigns
|
|
|
|
end
|
2010-01-26 10:37:20 -05:00
|
|
|
end
|
2005-08-22 17:17:01 -04:00
|
|
|
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
|
2010-08-29 19:42:09 -04:00
|
|
|
ActiveSupport::Deprecation.silenced = true
|
2005-08-22 17:17:01 -04:00
|
|
|
|
|
|
|
@recipient = 'test@localhost'
|
|
|
|
end
|
|
|
|
|
2007-11-07 11:05:17 -05:00
|
|
|
def teardown
|
2010-08-29 19:42:09 -04:00
|
|
|
ActiveSupport::Deprecation.silenced = false
|
2007-11-07 11:05:17 -05:00
|
|
|
restore_delivery_method
|
|
|
|
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
|
2010-08-14 04:58:34 -04: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
|
|
|
|
2009-12-25 15:35:40 -05:00
|
|
|
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
|
2010-08-29 19:42:09 -04:00
|
|
|
ActiveSupport::Deprecation.silenced = true
|
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
|
2010-08-29 19:42:09 -04:00
|
|
|
ActiveSupport::Deprecation.silenced = false
|
2007-11-07 11:05:17 -05:00
|
|
|
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
|