提交 383b8bc8 编写于 作者: Y Yoshiyuki Kinjo

Skip delivery notification when perform_deliveries is false.

上级 5f35c60f
* Skip delivery notification when `perform_deliveries` is false.
*Yoshiyuki Kinjo*
* Allow call `assert_enqueued_email_with` with no block.
Example:
......
......@@ -579,6 +579,7 @@ def receive(raw_mail)
# 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
......
......@@ -37,6 +37,17 @@ def test_deliver_is_notified
BaseMailer.deliveries.clear
end
def test_deliver_is_not_notified_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_match(/BaseMailer#welcome_without_deliveries: processed outbound mail in [\d.]+ms/, @logger.logged(:debug).first)
ensure
BaseMailer.deliveries.clear
end
def test_receive_is_notified
fixture = File.read(File.expand_path("fixtures/raw_email", __dir__))
TestMailer.receive(fixture)
......
......@@ -21,6 +21,11 @@ def welcome_from_another_path(path)
mail(template_name: "welcome", template_path: path)
end
def welcome_without_deliveries
mail(template_name: "welcome")
mail.perform_deliveries = false
end
def html_only(hash = {})
mail(hash)
end
......
......@@ -787,7 +787,7 @@ files (environment.rb, production.rb, etc...)
|`sendmail_settings`|Allows you to override options for the `:sendmail` delivery method.<ul><li>`:location` - The location of the sendmail executable. Defaults to `/usr/sbin/sendmail`.</li><li>`:arguments` - The command line arguments to be passed to sendmail. Defaults to `-i`.</li></ul>|
|`raise_delivery_errors`|Whether or not errors should be raised if the email fails to be delivered. This only works if the external email server is configured for immediate delivery.|
|`delivery_method`|Defines a delivery method. Possible values are:<ul><li>`:smtp` (default), can be configured by using `config.action_mailer.smtp_settings`.</li><li>`:sendmail`, can be configured by using `config.action_mailer.sendmail_settings`.</li><li>`:file`: save emails to files; can be configured by using `config.action_mailer.file_settings`.</li><li>`:test`: save emails to `ActionMailer::Base.deliveries` array.</li></ul>See [API docs](http://api.rubyonrails.org/classes/ActionMailer/Base.html) for more info.|
|`perform_deliveries`|Determines whether deliveries are actually carried out when the `deliver` method is invoked on the Mail message. By default they are, but this can be turned off to help functional testing.|
|`perform_deliveries`|Determines whether deliveries are actually carried out when the `deliver` method is invoked on the Mail message. By default they are, but this can be turned off to help functional testing. If this value is `false`, `deliveries` array will not be populated even if delivery_method is :test.|
|`deliveries`|Keeps an array of all the emails sent out through the Action Mailer with delivery_method :test. Most useful for unit and functional testing.|
|`default_options`|Allows you to set default values for the `mail` method options (`:from`, `:reply_to`, etc.).|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册