Permalink
Browse files

Merge pull request #7202 from asanghi/perform_deliveries_in_mail

Allow perform_deliveries to be set within mailer action
  • Loading branch information...
2 parents 067efad + 7c8424e commit 1935cfd07fde9bc6f3c60547aa85279869eaf804 @josevalim josevalim committed Aug 4, 2012
@@ -683,7 +683,7 @@ def mail(headers={}, &block)
m.charset = charset = headers[:charset]
# Set configure delivery behavior
- wrap_delivery_behavior!(headers.delete(:delivery_method))
+ wrap_delivery_behavior!(headers.delete(:delivery_method),headers.delete(:perform_deliveries))
@spastorino

spastorino Aug 4, 2012

Owner

add a space there bro ECOMMON :P

@josevalim

josevalim Aug 4, 2012

Member

Spaces are codepoints that need to be handled by the parser and make rails boot slow. 👎 for spaces.

:trollface:

@fxn

fxn Aug 4, 2012

Owner

I'd like to work on a minified Rails for v5 for a faster parse, this missing space goes in the right direction. :trollface:

# Assign all headers except parts_order, content_type and body
assignable = headers.except(:parts_order, :content_type, :body, :template_name, :template_path)
@@ -57,7 +57,7 @@ def add_delivery_method(symbol, klass, default_options={})
self.delivery_methods = delivery_methods.merge(symbol.to_sym => klass).freeze
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
mail.delivery_handler = self
@@ -74,7 +74,7 @@ def wrap_delivery_behavior(mail, method=nil) #:nodoc:
mail.delivery_method(method)
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
end
end
@@ -82,6 +82,7 @@ class DeliveryMailer < ActionMailer::Base
def welcome(hash={})
mail(DEFAULT_HEADERS.merge(hash))
end
+
end
def setup
@@ -129,6 +130,18 @@ def teardown
DeliveryMailer.welcome.deliver
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
DeliveryMailer.perform_deliveries = false
DeliveryMailer.deliveries.clear

0 comments on commit 1935cfd

Please sign in to comment.