mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
allow perform deliveries to be set within mailer action
This commit is contained in:
parent
4ac81de52f
commit
7c8424e057
3 changed files with 16 additions and 3 deletions
|
@ -684,7 +684,7 @@ module ActionMailer #:nodoc:
|
||||||
m.charset = charset = headers[:charset]
|
m.charset = charset = headers[:charset]
|
||||||
|
|
||||||
# Set configure delivery behavior
|
# Set configure delivery behavior
|
||||||
wrap_delivery_behavior!(headers.delete(:delivery_method))
|
wrap_delivery_behavior!(headers.delete(:delivery_method),headers.delete(:perform_deliveries))
|
||||||
|
|
||||||
# Assign all headers except parts_order, content_type and body
|
# Assign all headers except parts_order, content_type and body
|
||||||
assignable = headers.except(:parts_order, :content_type, :body, :template_name, :template_path)
|
assignable = headers.except(:parts_order, :content_type, :body, :template_name, :template_path)
|
||||||
|
|
|
@ -57,7 +57,7 @@ module ActionMailer
|
||||||
self.delivery_methods = delivery_methods.merge(symbol.to_sym => klass).freeze
|
self.delivery_methods = delivery_methods.merge(symbol.to_sym => klass).freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def wrap_delivery_behavior(mail, method=nil) #:nodoc:
|
def wrap_delivery_behavior(mail, method=nil, perform_deliveries_header=nil) #:nodoc:
|
||||||
method ||= self.delivery_method
|
method ||= self.delivery_method
|
||||||
mail.delivery_handler = self
|
mail.delivery_handler = self
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ module ActionMailer
|
||||||
mail.delivery_method(method)
|
mail.delivery_method(method)
|
||||||
end
|
end
|
||||||
|
|
||||||
mail.perform_deliveries = perform_deliveries
|
mail.perform_deliveries = perform_deliveries && (perform_deliveries_header.nil? || perform_deliveries_header)
|
||||||
mail.raise_delivery_errors = raise_delivery_errors
|
mail.raise_delivery_errors = raise_delivery_errors
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -82,6 +82,7 @@ class MailDeliveryTest < ActiveSupport::TestCase
|
||||||
def welcome(hash={})
|
def welcome(hash={})
|
||||||
mail(DEFAULT_HEADERS.merge(hash))
|
mail(DEFAULT_HEADERS.merge(hash))
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
|
@ -129,6 +130,18 @@ class MailDeliveryTest < ActiveSupport::TestCase
|
||||||
DeliveryMailer.welcome.deliver
|
DeliveryMailer.welcome.deliver
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "does not perform deliveries if customized per instance" do
|
||||||
|
DeliveryMailer.perform_deliveries = true
|
||||||
|
m = DeliveryMailer.welcome(:perform_deliveries => false)
|
||||||
|
assert_equal(false,m.perform_deliveries)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "does not perform deliveries if globally set to off but instance instructs delivery" do
|
||||||
|
DeliveryMailer.perform_deliveries = false
|
||||||
|
m = DeliveryMailer.welcome(:perform_deliveries => true)
|
||||||
|
assert_equal(false,m.perform_deliveries)
|
||||||
|
end
|
||||||
|
|
||||||
test "does not append the deliveries collection if told not to perform the delivery" do
|
test "does not append the deliveries collection if told not to perform the delivery" do
|
||||||
DeliveryMailer.perform_deliveries = false
|
DeliveryMailer.perform_deliveries = false
|
||||||
DeliveryMailer.deliveries.clear
|
DeliveryMailer.deliveries.clear
|
||||||
|
|
Loading…
Reference in a new issue