Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow ActionMailer subclasses to individually set their delivery meth…

…od (so two subclasses can have different delivery methods) (closes #10033) [zdennis]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8111 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 57cde631383a8a0fa8d231ac1ae85ea725e12cd5 1 parent 6b018e3
David Heinemeier Hansson dhh authored
2  actionmailer/CHANGELOG
View
@@ -1,5 +1,7 @@
*SVN*
+* Allow ActionMailer subclasses to individually set their delivery method (so two subclasses can have different delivery methods) #10033 [zdennis]
+
* Update TMail to v1.1.0. Use an updated version of TMail if available. [mikel]
* Introduce a new base test class for testing Mailers. ActionMailer::TestCase [Koz]
4 actionmailer/lib/action_mailer/base.rb
View
@@ -248,8 +248,8 @@ class Base
@@raise_delivery_errors = true
cattr_accessor :raise_delivery_errors
- @@delivery_method = :smtp
- cattr_accessor :delivery_method
+ superclass_delegating_accessor :delivery_method
+ self.delivery_method = :smtp
@@perform_deliveries = true
cattr_accessor :perform_deliveries
9 actionmailer/test/abstract_unit.rb
View
@@ -38,3 +38,12 @@ def uses_mocha(test_name)
rescue Gem::LoadError
$stderr.puts "Skipping #{test_name} tests (Mocha >= 0.5 is required). `gem install mocha` and try again."
end
+
+def set_delivery_method(delivery_method)
+ @old_delivery_method = ActionMailer::Base.delivery_method
+ ActionMailer::Base.delivery_method = delivery_method
+end
+
+def restore_delivery_method
+ ActionMailer::Base.delivery_method = @old_delivery_method
+end
51 actionmailer/test/delivery_method_test.rb
View
@@ -0,0 +1,51 @@
+require "#{File.dirname(__FILE__)}/abstract_unit"
+
+class DefaultDeliveryMethodMailer < ActionMailer::Base
+end
+
+class NonDefaultDeliveryMethodMailer < ActionMailer::Base
+ self.delivery_method = :sendmail
+end
+
+class ActionMailerBase_delivery_method_Test < Test::Unit::TestCase
+ def setup
+ set_delivery_method :smtp
+ end
+
+ def teardown
+ restore_delivery_method
+ end
+
+ def test_should_be_the_default_smtp
+ assert_equal :smtp, ActionMailer::Base.delivery_method
+ end
+end
+
+class DefaultDeliveryMethodMailer_delivery_method_Test < Test::Unit::TestCase
+ def setup
+ set_delivery_method :smtp
+ end
+
+ def teardown
+ restore_delivery_method
+ end
+
+ def test_should_be_the_default_smtp
+ assert_equal :smtp, DefaultDeliveryMethodMailer.delivery_method
+ end
+end
+
+class NonDefaultDeliveryMethodMailer_delivery_method_Test < Test::Unit::TestCase
+ def setup
+ set_delivery_method :smtp
+ end
+
+ def teardown
+ restore_delivery_method
+ end
+
+ def test_should_be_the_set_delivery_method
+ assert_equal :sendmail, NonDefaultDeliveryMethodMailer.delivery_method
+ end
+end
+
8 actionmailer/test/mail_helper_test.rb
View
@@ -60,13 +60,17 @@ def new_mail( charset="utf-8" )
end
def setup
- ActionMailer::Base.delivery_method = :test
+ set_delivery_method :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
@recipient = 'test@localhost'
end
-
+
+ def teardown
+ restore_delivery_method
+ end
+
def test_use_helper
mail = HelperMailer.create_use_helper(@recipient)
assert_match %r{Mr. Joe Person}, mail.encoded
12 actionmailer/test/mail_render_test.rb
View
@@ -45,13 +45,17 @@ def share(recipient)
class RenderHelperTest < Test::Unit::TestCase
def setup
- ActionMailer::Base.delivery_method = :test
+ set_delivery_method :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
@recipient = 'test@localhost'
end
+ def teardown
+ restore_delivery_method
+ end
+
def test_inline_template
mail = RenderMailer.create_inline_template(@recipient)
assert_equal "Hello, Earth", mail.body.strip
@@ -70,13 +74,17 @@ def test_rxml_template
class FirstSecondHelperTest < Test::Unit::TestCase
def setup
- ActionMailer::Base.delivery_method = :test
+ set_delivery_method :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
@recipient = 'test@localhost'
end
+ def teardown
+ restore_delivery_method
+ end
+
def test_ordering
mail = FirstMailer.create_share(@recipient)
assert_equal "first mail", mail.body.strip
11 actionmailer/test/mail_service_test.rb
View
@@ -282,7 +282,7 @@ def new_mail( charset="utf-8" )
# Replacing logger work around for mocha bug. Should be fixed in mocha 0.3.3
def setup
- ActionMailer::Base.delivery_method = :test
+ set_delivery_method :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.deliveries = []
@@ -290,9 +290,10 @@ def setup
@original_logger = TestMailer.logger
@recipient = 'test@localhost'
end
-
+
def teardown
TestMailer.logger = @original_logger
+ restore_delivery_method
end
def test_nested_parts
@@ -902,11 +903,15 @@ def send
end
def setup
- ActionMailer::Base.delivery_method = :test
+ set_delivery_method :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
end
+ def teardown
+ restore_delivery_method
+ end
+
def test_send_method
assert_nothing_raised do
assert_emails 1 do
6 actionmailer/test/url_test.rb
View
@@ -40,13 +40,17 @@ def new_mail( charset="utf-8" )
end
def setup
- ActionMailer::Base.delivery_method = :test
+ set_delivery_method :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
@recipient = 'test@localhost'
end
+ def teardown
+ restore_delivery_method
+ end
+
def test_signed_up_with_url
ActionController::Routing::Routes.draw do |map|
map.connect ':controller/:action/:id'
Please sign in to comment.
Something went wrong with that request. Please try again.