Skip to content
Browse files

Merge pull request #15544 from zuhao/refactor_actionmailer_test_case

Restore test deliveries properly in ActionMailer.
  • Loading branch information...
2 parents ecd4151 + c4f4123 commit 0502189b504640a95a4729fac5c6a41c27de960f @spastorino spastorino committed Jun 6, 2014
Showing with 8 additions and 0 deletions.
  1. +8 −0 actionmailer/lib/action_mailer/test_case.rb
View
8 actionmailer/lib/action_mailer/test_case.rb
@@ -20,6 +20,7 @@ module Behavior
class_attribute :_mailer_class
setup :initialize_test_deliveries
setup :set_expected_mail
+ teardown :restore_test_deliveries
end
module ClassMethods
@@ -54,8 +55,15 @@ def determine_default_mailer(name)
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

0 comments on commit 0502189

Please sign in to comment.
Something went wrong with that request. Please try again.