Fix ActionMailer assertions don't work for parameterized mail with legacy delivery job

We should backport this to `6-0-stable`.

Fixes https://github.com/rails/rails/issues/37605
This commit is contained in:
bogdanvlviv 2019-10-30 21:55:12 +00:00
parent 0097b24bb2
commit 37b72ff5de
No known key found for this signature in database
GPG Key ID: E4ACD76A6DB6DFDD
3 changed files with 34 additions and 1 deletions

View File

@ -1,3 +1,7 @@
* Fix ActionMailer assertions don't work for parameterized mail with legacy delivery job.
*bogdanvlviv*
* Added `email_address_with_name` to properly escape addresses with names.
*Sunny Ripert*

View File

@ -155,7 +155,8 @@ module ActionMailer
def delivery_job_filter(job)
job_class = job.is_a?(Hash) ? job.fetch(:job) : job.class
Base.descendants.map(&:delivery_job).include?(job_class)
Base.descendants.map(&:delivery_job).include?(job_class) ||
ActionMailer::Parameterized::DeliveryJob == job_class
end
end
end

View File

@ -206,6 +206,20 @@ class TestHelperMailerTest < ActionMailer::TestCase
end
end
def test_assert_enqueued_emails_with_legacy_delivery_job
previous_delivery_job = TestHelperMailer.delivery_job
TestHelperMailer.delivery_job = ActionMailer::DeliveryJob
assert_nothing_raised do
assert_enqueued_emails 1 do
silence_stream($stdout) do
TestHelperMailer.test.deliver_later
end
end
end
ensure
TestHelperMailer.delivery_job = previous_delivery_job
end
def test_assert_enqueued_parameterized_emails
assert_nothing_raised do
assert_enqueued_emails 1 do
@ -216,6 +230,20 @@ class TestHelperMailerTest < ActionMailer::TestCase
end
end
def test_assert_enqueued_parameterized_emails_with_legacy_delivery_job
previous_delivery_job = TestHelperMailer.delivery_job
TestHelperMailer.delivery_job = ActionMailer::DeliveryJob
assert_nothing_raised do
assert_enqueued_emails 1 do
silence_stream($stdout) do
TestHelperMailer.with(a: 1).test.deliver_later
end
end
end
ensure
TestHelperMailer.delivery_job = previous_delivery_job
end
def test_assert_enqueued_emails_too_few_sent
error = assert_raise ActiveSupport::TestCase::Assertion do
assert_enqueued_emails 2 do