Added bounce_now_with
`ActionMailbox::Base#bounce_with` enqueues the bounce email. For situations where it is preferable to skip the email queues, this commit introduces `#bounce_now_with`, which sends the bounce email immediately (like `deliver_now` vs. `deliver_later`). # Delivers the email immediately MyMailbox.bounce_now_with MyMailer.my_method(args)
This commit is contained in:
parent
48e17e5ce7
commit
3bac56e11f
@ -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*
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user