diff options
author | Yoshiyuki Kinjo <yskkin@gmail.com> | 2018-09-09 20:16:20 +0900 |
---|---|---|
committer | Yoshiyuki Kinjo <yskkin@gmail.com> | 2018-09-09 20:17:36 +0900 |
commit | 576209b45bf6d20e91562da77e454bc58bda3658 (patch) | |
tree | 4e9875069319fd7254a43082b4c44ffabbe56895 /actionmailer | |
parent | 383b8bc8e215d5fa2b018d6f0b9c363ea95251cf (diff) | |
download | rails-576209b45bf6d20e91562da77e454bc58bda3658.tar.gz rails-576209b45bf6d20e91562da77e454bc58bda3658.tar.bz2 rails-576209b45bf6d20e91562da77e454bc58bda3658.zip |
Add `perform_deliveries` to a payload of `deliver.action_mailer` notification.
Diffstat (limited to 'actionmailer')
-rw-r--r-- | actionmailer/CHANGELOG.md | 6 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 20 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/log_subscriber.rb | 7 | ||||
-rw-r--r-- | actionmailer/test/log_subscriber_test.rb | 9 |
4 files changed, 27 insertions, 15 deletions
diff --git a/actionmailer/CHANGELOG.md b/actionmailer/CHANGELOG.md index 415c54ec70..5158f23a27 100644 --- a/actionmailer/CHANGELOG.md +++ b/actionmailer/CHANGELOG.md @@ -1,4 +1,8 @@ -* Skip delivery notification when `perform_deliveries` is false. +* Add `perform_deliveries` to a payload of `deliver.action_mailer` notification. + + *Yoshiyuki Kinjo* + +* Change delivery logging message when `perform_deliveries` is false. *Yoshiyuki Kinjo* diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 1ab2c55a6c..55f701b18e 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -579,7 +579,6 @@ module ActionMailer # calling +deliver_mail+ directly and passing a <tt>Mail::Message</tt> will do # nothing except tell the logger you sent the email. def deliver_mail(mail) #:nodoc: - return unless mail.perform_deliveries ActiveSupport::Notifications.instrument("deliver.action_mailer") do |payload| set_payload_for_mail(payload, mail) yield # Let Mail do the delivery actions @@ -589,15 +588,16 @@ module ActionMailer private def set_payload_for_mail(payload, mail) - payload[:mailer] = name - payload[:message_id] = mail.message_id - payload[:subject] = mail.subject - payload[:to] = mail.to - payload[:from] = mail.from - payload[:bcc] = mail.bcc if mail.bcc.present? - payload[:cc] = mail.cc if mail.cc.present? - payload[:date] = mail.date - payload[:mail] = mail.encoded + payload[:mailer] = name + payload[:message_id] = mail.message_id + payload[:subject] = mail.subject + payload[:to] = mail.to + payload[:from] = mail.from + payload[:bcc] = mail.bcc if mail.bcc.present? + payload[:cc] = mail.cc if mail.cc.present? + payload[:date] = mail.date + payload[:mail] = mail.encoded + payload[:perform_deliveries] = mail.perform_deliveries end def method_missing(method_name, *args) diff --git a/actionmailer/lib/action_mailer/log_subscriber.rb b/actionmailer/lib/action_mailer/log_subscriber.rb index 87cfbfff28..25c99342c2 100644 --- a/actionmailer/lib/action_mailer/log_subscriber.rb +++ b/actionmailer/lib/action_mailer/log_subscriber.rb @@ -9,8 +9,13 @@ module ActionMailer # An email was delivered. def deliver(event) info do + perform_deliveries = event.payload[:perform_deliveries] recipients = Array(event.payload[:to]).join(", ") - "Sent mail to #{recipients} (#{event.duration.round(1)}ms)" + if perform_deliveries + "Sent mail to #{recipients} (#{event.duration.round(1)}ms)" + else + "Skipped sending mail to #{recipients} as `perform_deliveries` is false" + end end debug { event.payload[:mail] } diff --git a/actionmailer/test/log_subscriber_test.rb b/actionmailer/test/log_subscriber_test.rb index 48edb80c0c..7686fd10c9 100644 --- a/actionmailer/test/log_subscriber_test.rb +++ b/actionmailer/test/log_subscriber_test.rb @@ -37,13 +37,16 @@ class AMLogSubscriberTest < ActionMailer::TestCase BaseMailer.deliveries.clear end - def test_deliver_is_not_notified_when_perform_deliveries_is_false + def test_deliver_message_when_perform_deliveries_is_false BaseMailer.welcome_without_deliveries.deliver_now wait - assert_equal(0, @logger.logged(:info).size) - assert_equal(1, @logger.logged(:debug).size) + assert_equal(1, @logger.logged(:info).size) + assert_match("Skipped sending mail to system@test.lindsaar.net as `perform_deliveries` is false", @logger.logged(:info).first) + + assert_equal(2, @logger.logged(:debug).size) assert_match(/BaseMailer#welcome_without_deliveries: processed outbound mail in [\d.]+ms/, @logger.logged(:debug).first) + assert_match("Welcome", @logger.logged(:debug).second) ensure BaseMailer.deliveries.clear end |