Skip to content

Commit

Permalink
Fix ActionMailer assertions don't work for parameterized mail with le…
Browse files Browse the repository at this point in the history
…gacy delivery job

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

Fixes rails#37605
  • Loading branch information
bogdanvlviv committed Oct 30, 2019
1 parent 0097b24 commit 37b72ff
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions actionmailer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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*
Expand Down
3 changes: 2 additions & 1 deletion actionmailer/lib/action_mailer/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ def assert_no_enqueued_emails(&block)
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
28 changes: 28 additions & 0 deletions actionmailer/test/test_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,20 @@ def test_assert_enqueued_emails
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
Expand All @@ -216,6 +230,20 @@ def test_assert_enqueued_parameterized_emails
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
Expand Down

0 comments on commit 37b72ff

Please sign in to comment.