aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2007-11-07 16:05:17 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2007-11-07 16:05:17 +0000
commit57cde631383a8a0fa8d231ac1ae85ea725e12cd5 (patch)
tree085048b9a8aa2456b4842cf45af66bde320615b8
parent6b018e3d08c52417034cd648952668192327a9b7 (diff)
downloadrails-57cde631383a8a0fa8d231ac1ae85ea725e12cd5.tar.gz
rails-57cde631383a8a0fa8d231ac1ae85ea725e12cd5.tar.bz2
rails-57cde631383a8a0fa8d231ac1ae85ea725e12cd5.zip
Allow ActionMailer subclasses to individually set their delivery method (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
-rw-r--r--actionmailer/CHANGELOG2
-rw-r--r--actionmailer/lib/action_mailer/base.rb4
-rw-r--r--actionmailer/test/abstract_unit.rb9
-rw-r--r--actionmailer/test/delivery_method_test.rb51
-rw-r--r--actionmailer/test/mail_helper_test.rb8
-rw-r--r--actionmailer/test/mail_render_test.rb12
-rwxr-xr-xactionmailer/test/mail_service_test.rb11
-rw-r--r--actionmailer/test/url_test.rb6
8 files changed, 93 insertions, 10 deletions
diff --git a/actionmailer/CHANGELOG b/actionmailer/CHANGELOG
index 2e4f5cfe33..9e1aac05ee 100644
--- a/actionmailer/CHANGELOG
+++ b/actionmailer/CHANGELOG
@@ -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]
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index 51371ef2e0..8bf051c99f 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -248,8 +248,8 @@ module ActionMailer #:nodoc:
@@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
diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb
index 0a73b1b462..9b7a4661b6 100644
--- a/actionmailer/test/abstract_unit.rb
+++ b/actionmailer/test/abstract_unit.rb
@@ -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
diff --git a/actionmailer/test/delivery_method_test.rb b/actionmailer/test/delivery_method_test.rb
new file mode 100644
index 0000000000..ebee23560a
--- /dev/null
+++ b/actionmailer/test/delivery_method_test.rb
@@ -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
+
diff --git a/actionmailer/test/mail_helper_test.rb b/actionmailer/test/mail_helper_test.rb
index 344dcd7c49..70e5cb81d5 100644
--- a/actionmailer/test/mail_helper_test.rb
+++ b/actionmailer/test/mail_helper_test.rb
@@ -60,13 +60,17 @@ class MailerHelperTest < Test::Unit::TestCase
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
diff --git a/actionmailer/test/mail_render_test.rb b/actionmailer/test/mail_render_test.rb
index a725dac4ca..d6ee21a8b9 100644
--- a/actionmailer/test/mail_render_test.rb
+++ b/actionmailer/test/mail_render_test.rb
@@ -45,13 +45,17 @@ end
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 @@ end
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
diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb
index 58c6d39749..09132ed7e6 100755
--- a/actionmailer/test/mail_service_test.rb
+++ b/actionmailer/test/mail_service_test.rb
@@ -282,7 +282,7 @@ class ActionMailerTest < Test::Unit::TestCase
# 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 @@ class ActionMailerTest < Test::Unit::TestCase
@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 @@ class MethodNamingTest < Test::Unit::TestCase
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
diff --git a/actionmailer/test/url_test.rb b/actionmailer/test/url_test.rb
index 9d94bb996a..5647869622 100644
--- a/actionmailer/test/url_test.rb
+++ b/actionmailer/test/url_test.rb
@@ -40,13 +40,17 @@ class ActionMailerUrlTest < Test::Unit::TestCase
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'