mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Clear ActionMailer deliveries on setup and teardown
Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
This commit is contained in:
parent
9364d50654
commit
9d63111499
2 changed files with 42 additions and 1 deletions
|
@ -15,10 +15,12 @@ module ActionMailer
|
|||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
setup :clear_test_deliveries
|
||||
teardown :clear_test_deliveries
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def clear_test_deliveries
|
||||
if ActionMailer::Base.delivery_method == :test
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
@ -76,6 +78,7 @@ module ActionMailer
|
|||
set_delivery_method :test
|
||||
@old_perform_deliveries = ActionMailer::Base.perform_deliveries
|
||||
ActionMailer::Base.perform_deliveries = true
|
||||
ActionMailer::Base.deliveries.clear
|
||||
end
|
||||
|
||||
def restore_test_deliveries # :nodoc:
|
||||
|
@ -89,6 +92,7 @@ module ActionMailer
|
|||
end
|
||||
|
||||
def restore_delivery_method # :nodoc:
|
||||
ActionMailer::Base.deliveries.clear
|
||||
ActionMailer::Base.delivery_method = @old_delivery_method
|
||||
end
|
||||
|
||||
|
@ -114,6 +118,5 @@ module ActionMailer
|
|||
end
|
||||
|
||||
include Behavior
|
||||
include ClearTestDeliveries
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,6 +3,44 @@ require 'abstract_unit'
|
|||
class TestTestMailer < ActionMailer::Base
|
||||
end
|
||||
|
||||
class ClearTestDeliveriesMixinTest < ActiveSupport::TestCase
|
||||
include ActionMailer::TestCase::ClearTestDeliveries
|
||||
|
||||
def before_setup
|
||||
ActionMailer::Base.delivery_method, @original_delivery_method = :test, ActionMailer::Base.delivery_method
|
||||
ActionMailer::Base.deliveries << 'better clear me, setup'
|
||||
super
|
||||
end
|
||||
|
||||
def after_teardown
|
||||
super
|
||||
assert_equal [], ActionMailer::Base.deliveries
|
||||
ActionMailer::Base.delivery_method = @original_delivery_method
|
||||
end
|
||||
|
||||
def test_deliveries_are_cleared_on_setup_and_teardown
|
||||
assert_equal [], ActionMailer::Base.deliveries
|
||||
ActionMailer::Base.deliveries << 'better clear me, teardown'
|
||||
end
|
||||
end
|
||||
|
||||
class MailerDeliveriesClearingTest < ActionMailer::TestCase
|
||||
def before_setup
|
||||
ActionMailer::Base.deliveries << 'better clear me, setup'
|
||||
super
|
||||
end
|
||||
|
||||
def after_teardown
|
||||
super
|
||||
assert_equal [], ActionMailer::Base.deliveries
|
||||
end
|
||||
|
||||
def test_deliveries_are_cleared_on_setup_and_teardown
|
||||
assert_equal [], ActionMailer::Base.deliveries
|
||||
ActionMailer::Base.deliveries << 'better clear me, teardown'
|
||||
end
|
||||
end
|
||||
|
||||
class CrazyNameMailerTest < ActionMailer::TestCase
|
||||
tests TestTestMailer
|
||||
|
||||
|
|
Loading…
Reference in a new issue