diff options
author | Zuhao Wan <wanzuhao@gmail.com> | 2014-06-07 00:11:24 +0800 |
---|---|---|
committer | Zuhao Wan <wanzuhao@gmail.com> | 2014-06-07 00:11:24 +0800 |
commit | c4f4123ef45463a09b36186047dbdc82f933fe46 (patch) | |
tree | 605cd59844aad17a929f137be18cd98318089681 /actionmailer/lib/action_mailer | |
parent | ecd4151aa829214c7b10f24bc5eca194089b4319 (diff) | |
download | rails-c4f4123ef45463a09b36186047dbdc82f933fe46.tar.gz rails-c4f4123ef45463a09b36186047dbdc82f933fe46.tar.bz2 rails-c4f4123ef45463a09b36186047dbdc82f933fe46.zip |
Restore test deliveries properly in ActionMailer.
`ActionMailer::Base.delivery_method` and
`ActionMailer::Base.perform_deliveries` have leaked states.
"delivery method can be customized per instance" and "delivery method
can be customized in subclasses not changing the parent" in
delivery_methods_test.rb will fail if test_helper_test.rb (in which
TestHelperMailerTest is inherited from ActionMailer::TestCase) runs
before it.
Diffstat (limited to 'actionmailer/lib/action_mailer')
-rw-r--r-- | actionmailer/lib/action_mailer/test_case.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/actionmailer/lib/action_mailer/test_case.rb b/actionmailer/lib/action_mailer/test_case.rb index 207f949fe2..a5442c0316 100644 --- a/actionmailer/lib/action_mailer/test_case.rb +++ b/actionmailer/lib/action_mailer/test_case.rb @@ -20,6 +20,7 @@ module ActionMailer class_attribute :_mailer_class setup :initialize_test_deliveries setup :set_expected_mail + teardown :restore_test_deliveries end module ClassMethods @@ -54,8 +55,15 @@ module ActionMailer protected def initialize_test_deliveries + @old_delivery_method = ActionMailer::Base.delivery_method + @old_perform_deliveries = ActionMailer::Base.perform_deliveries ActionMailer::Base.delivery_method = :test ActionMailer::Base.perform_deliveries = true + end + + def restore_test_deliveries + ActionMailer::Base.delivery_method = @old_delivery_method + ActionMailer::Base.perform_deliveries = @old_perform_deliveries ActionMailer::Base.deliveries.clear end |