diff options
author | Matthew Rudy Jacobs <MatthewRudyJacobs@gmail.com> | 2009-10-28 09:17:59 +0000 |
---|---|---|
committer | Yehuda Katz <wycats@gmail.com> | 2009-11-01 02:23:47 +0100 |
commit | f4f76772fb5c25357a54baaa9cd20f7e9a1cd653 (patch) | |
tree | c3095ca798d006fa5750538d862cf5fcc35da6ba /actionmailer/test | |
parent | 3f560386125adabe441facf2514ad53425e4af4e (diff) | |
download | rails-f4f76772fb5c25357a54baaa9cd20f7e9a1cd653.tar.gz rails-f4f76772fb5c25357a54baaa9cd20f7e9a1cd653.tar.bz2 rails-f4f76772fb5c25357a54baaa9cd20f7e9a1cd653.zip |
abstract all of the ActionMailer delivery methods into their own classes. thereby the following are equivalent
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.delivery_method = ActionMailer::DeliveryMethod::Smtp
we could equally set our own custom object
as long as it provides the instance method :perform_delivery(mail)
eg.
class MySmsDeliveryMethod
def perform_delivery(mail)
Sms.send(mail['to'], mail['body'])
end
end
MySmsMailer.delivery_method = MySmsDeliveryMethod.new
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionmailer/test')
-rw-r--r-- | actionmailer/test/delivery_method_test.rb | 36 | ||||
-rw-r--r-- | actionmailer/test/mail_service_test.rb | 2 | ||||
-rw-r--r-- | actionmailer/test/test_helper_test.rb | 2 |
3 files changed, 34 insertions, 6 deletions
diff --git a/actionmailer/test/delivery_method_test.rb b/actionmailer/test/delivery_method_test.rb index 1b8c3ba523..8f8c6b0275 100644 --- a/actionmailer/test/delivery_method_test.rb +++ b/actionmailer/test/delivery_method_test.rb @@ -11,6 +11,21 @@ class FileDeliveryMethodMailer < ActionMailer::Base self.delivery_method = :file end +class CustomDeliveryMethod + attr_accessor :custom_deliveries + def initialize() + @customer_deliveries = [] + end + + def self.perform_delivery(mail) + self.custom_deliveries << mail + end +end + +class CustomerDeliveryMailer < ActionMailer::Base + self.delivery_method = CustomDeliveryMethod.new +end + class ActionMailerBase_delivery_method_Test < Test::Unit::TestCase def setup set_delivery_method :smtp @@ -21,7 +36,7 @@ class ActionMailerBase_delivery_method_Test < Test::Unit::TestCase end def test_should_be_the_default_smtp - assert_equal :smtp, ActionMailer::Base.delivery_method + assert_instance_of ActionMailer::DeliveryMethod::Smtp, ActionMailer::Base.delivery_method end end @@ -35,7 +50,7 @@ class DefaultDeliveryMethodMailer_delivery_method_Test < Test::Unit::TestCase end def test_should_be_the_default_smtp - assert_equal :smtp, DefaultDeliveryMethodMailer.delivery_method + assert_instance_of ActionMailer::DeliveryMethod::Smtp, DefaultDeliveryMethodMailer.delivery_method end end @@ -49,7 +64,7 @@ class NonDefaultDeliveryMethodMailer_delivery_method_Test < Test::Unit::TestCase end def test_should_be_the_set_delivery_method - assert_equal :sendmail, NonDefaultDeliveryMethodMailer.delivery_method + assert_instance_of ActionMailer::DeliveryMethod::Sendmail, NonDefaultDeliveryMethodMailer.delivery_method end end @@ -63,7 +78,7 @@ class FileDeliveryMethodMailer_delivery_method_Test < Test::Unit::TestCase end def test_should_be_the_set_delivery_method - assert_equal :file, FileDeliveryMethodMailer.delivery_method + assert_instance_of ActionMailer::DeliveryMethod::File, FileDeliveryMethodMailer.delivery_method end def test_should_default_location_to_the_tmpdir @@ -71,3 +86,16 @@ class FileDeliveryMethodMailer_delivery_method_Test < Test::Unit::TestCase end end +class CustomDeliveryMethodMailer_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_instance_of CustomDeliveryMethod, CustomerDeliveryMailer.delivery_method + end +end diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index 5584afa8be..802c2b37d4 100644 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -554,7 +554,7 @@ class ActionMailerTest < Test::Unit::TestCase def test_doesnt_raise_errors_when_raise_delivery_errors_is_false ActionMailer::Base.raise_delivery_errors = false - TestMailer.any_instance.expects(:perform_delivery_test).raises(Exception) + TestMailer.delivery_method.expects(:perform_delivery).raises(Exception) assert_nothing_raised { TestMailer.deliver_signed_up(@recipient) } end diff --git a/actionmailer/test/test_helper_test.rb b/actionmailer/test/test_helper_test.rb index 65b07a71b8..a9f83f555b 100644 --- a/actionmailer/test/test_helper_test.rb +++ b/actionmailer/test/test_helper_test.rb @@ -10,7 +10,7 @@ end class TestHelperMailerTest < ActionMailer::TestCase def test_setup_sets_right_action_mailer_options - assert_equal :test, ActionMailer::Base.delivery_method + assert_instance_of ActionMailer::DeliveryMethod::Test, ActionMailer::Base.delivery_method assert ActionMailer::Base.perform_deliveries assert_equal [], ActionMailer::Base.deliveries end |