Skip to content
Browse files

Merge pull request #11581 from bughit/11533_to_proc_backport

don't convert mailer default values to procs
  • Loading branch information...
2 parents aae745b + 4f6e6e1 commit c4f7a0cfef605f9187578e3a93db088fe0b815cd @rafaelfranca rafaelfranca committed Jul 24, 2013
View
6 actionmailer/CHANGELOG.md
@@ -56,4 +56,10 @@
settings, headers, attachments, delivery settings or change delivery using
`before_filter`, `after_filter`, etc. *Justin S. Leitgeb*
+* invoke mailer defaults as procs only if they are procs, do not convert
+ with to_proc. That an object is convertible to a proc does not mean it's
+ meant to be always used as a proc. Fixes #11533
+
+ *Alex Tsukernik*
+
Please check [3-2-stable](https://github.com/rails/rails/blob/3-2-stable/actionmailer/CHANGELOG.md) for previous changes.
View
2 actionmailer/lib/action_mailer/base.rb
@@ -670,7 +670,7 @@ def mail(headers = {}, &block)
# Call all the procs (if any)
class_default = self.class.default
default_values = class_default.merge(class_default) do |k,v|
- v.respond_to?(:to_proc) ? instance_eval(&v) : v
+ v.is_a?(Proc) ? instance_eval(&v) : v
end
# Handle defaults
View
4 actionmailer/test/base_test.rb
@@ -578,6 +578,10 @@ def self.delivering_email(mail)
assert(mail1.to_s.to_i > mail2.to_s.to_i)
end
+ test 'default values which have to_proc (e.g. symbols) should not be considered procs' do
+ assert(ProcMailer.welcome['x-has-to-proc'].to_s == 'symbol')
+ end
+
test "we can call other defined methods on the class as needed" do
mail = ProcMailer.welcome
assert_equal("Thanks for signing up this afternoon", mail.subject)
View
3 actionmailer/test/mailers/proc_mailer.rb
@@ -1,7 +1,8 @@
class ProcMailer < ActionMailer::Base
default to: 'system@test.lindsaar.net',
'X-Proc-Method' => Proc.new { Time.now.to_i.to_s },
- subject: Proc.new { give_a_greeting }
+ subject: Proc.new { give_a_greeting },
+ 'x-has-to-proc' => :symbol
def welcome
mail

0 comments on commit c4f7a0c

Please sign in to comment.
Something went wrong with that request. Please try again.