aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib/action_mailer/test_helper.rb
diff options
context:
space:
mode:
authorGeorge Claghorn <george.claghorn@gmail.com>2017-09-27 17:45:28 -0400
committerGitHub <noreply@github.com>2017-09-27 17:45:28 -0400
commit212cf238e41f91a0d2ea5bb7ca50f13081b4c1ed (patch)
tree594cd47da7fd148ab97f091b699f78ef10de79ab /actionmailer/lib/action_mailer/test_helper.rb
parent2235f6692279740131298edeb12cfe4cc8fd6ccc (diff)
parentdb6847dcb6448ceeebe6cc37cc7d960dc72a0082 (diff)
downloadrails-212cf238e41f91a0d2ea5bb7ca50f13081b4c1ed.tar.gz
rails-212cf238e41f91a0d2ea5bb7ca50f13081b4c1ed.tar.bz2
rails-212cf238e41f91a0d2ea5bb7ca50f13081b4c1ed.zip
Merge pull request #30695 from mikker/add-asserts-enqueued-emails-with
Add assert_enqueued_email_with to ActionMailer::TestHelper
Diffstat (limited to 'actionmailer/lib/action_mailer/test_helper.rb')
-rw-r--r--actionmailer/lib/action_mailer/test_helper.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/actionmailer/lib/action_mailer/test_helper.rb b/actionmailer/lib/action_mailer/test_helper.rb
index ac8b944743..8ee4d06915 100644
--- a/actionmailer/lib/action_mailer/test_helper.rb
+++ b/actionmailer/lib/action_mailer/test_helper.rb
@@ -93,6 +93,48 @@ module ActionMailer
assert_enqueued_jobs number, only: [ ActionMailer::DeliveryJob, ActionMailer::Parameterized::DeliveryJob ], &block
end
+ # Asserts that a specific email has been enqueued, optionally
+ # matching arguments.
+ #
+ # def test_email
+ # ContactMailer.welcome.deliver_later
+ # assert_enqueued_email_with ContactMailer, :welcome
+ # end
+ #
+ # def test_email_with_arguments
+ # ContactMailer.welcome("Hello", "Goodbye").deliver_later
+ # assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
+ # end
+ #
+ # If a block is passed, that block should cause the specified email
+ # to be enqueued.
+ #
+ # def test_email_in_block
+ # assert_enqueued_email_with ContactMailer, :welcome do
+ # ContactMailer.welcome.deliver_later
+ # end
+ # end
+ #
+ # If `args` is provided as a Hash, a parameterized email is matched.
+ #
+ # def test_parameterized_email
+ # assert_enqueued_email_with ContactMailer, :welcome,
+ # args: {email: 'user@example.com} do
+ # ContactMailer.with(email: 'user@example.com').welcome.deliver_later
+ # end
+ # end
+ def assert_enqueued_email_with(mailer, method, args: nil, queue: "mailers", &block)
+ if args.is_a? Hash
+ job = ActionMailer::Parameterized::DeliveryJob
+ args = [mailer.to_s, method.to_s, "deliver_now", args]
+ else
+ job = ActionMailer::DeliveryJob
+ args = [mailer.to_s, method.to_s, "deliver_now", *args]
+ end
+
+ assert_enqueued_with(job: job, args: args, queue: queue, &block)
+ end
+
# Asserts that no emails are enqueued for later delivery.
#
# def test_no_emails