diff --git a/actionmailbox/CHANGELOG.md b/actionmailbox/CHANGELOG.md index fdec3909ca..6914abf8e0 100644 --- a/actionmailbox/CHANGELOG.md +++ b/actionmailbox/CHANGELOG.md @@ -1,3 +1,7 @@ +* Added `bounce_now_with` to send the bounce email without going through a mailer queue. + + *Ronan Limon Duparcmeur* + * Support configured primary key types in generated migrations. *Nishiki Liu* diff --git a/actionmailbox/lib/action_mailbox/base.rb b/actionmailbox/lib/action_mailbox/base.rb index 180f63ec98..d6ff9caf40 100644 --- a/actionmailbox/lib/action_mailbox/base.rb +++ b/actionmailbox/lib/action_mailbox/base.rb @@ -101,13 +101,18 @@ def finished_processing? # :nodoc: inbound_email.delivered? || inbound_email.bounced? end - # Enqueues the given +message+ for delivery and changes the inbound email's status to +:bounced+. def bounce_with(message) inbound_email.bounced! message.deliver_later end + # Immediately sends the given +message+ and changes the inbound email's status to +:bounced+. + def bounce_now_with(message) + inbound_email.bounced! + message.deliver_now + end + private def instrumentation_payload { diff --git a/actionmailbox/test/unit/mailbox/bouncing_test.rb b/actionmailbox/test/unit/mailbox/bouncing_test.rb index d4bd6ea6db..cb331de0c9 100644 --- a/actionmailbox/test/unit/mailbox/bouncing_test.rb +++ b/actionmailbox/test/unit/mailbox/bouncing_test.rb @@ -8,6 +8,12 @@ def process end end +class BouncingWithImmediateReplyMailbox < ActionMailbox::Base + def process + bounce_now_with BounceMailer.bounce(to: mail.from) + end +end + class ActionMailbox::Base::BouncingTest < ActiveSupport::TestCase include ActionMailer::TestHelper @@ -16,6 +22,10 @@ class ActionMailbox::Base::BouncingTest < ActiveSupport::TestCase from: "sender@example.com", to: "replies@example.com", subject: "Bounce me" end + teardown do + ActionMailer::Base.deliveries.clear + end + test "bouncing with a reply" do perform_enqueued_jobs only: ActionMailer::MailDeliveryJob do BouncingWithReplyMailbox.receive @inbound_email @@ -28,4 +38,17 @@ class ActionMailbox::Base::BouncingTest < ActiveSupport::TestCase assert_equal %w[ sender@example.com ], mail.to assert_equal "Your email was not delivered", mail.subject end + + test "bouncing now with a reply" do + assert_no_enqueued_emails do + BouncingWithImmediateReplyMailbox.receive @inbound_email + end + + assert @inbound_email.bounced? + assert_emails 1 + + mail = ActionMailer::Base.deliveries.last + assert_equal %w[ sender@example.com ], mail.to + assert_equal "Your email was not delivered", mail.subject + end end