diff options
author | José Valim <jose.valim@plataformatec.com.br> | 2013-07-24 10:13:50 -0700 |
---|---|---|
committer | José Valim <jose.valim@plataformatec.com.br> | 2013-07-24 10:13:50 -0700 |
commit | fa265346a95b2264f163f170e8322afb223063c7 (patch) | |
tree | 126e1a8d767cdc1bb5e95ec9a42f8f08d1e538ff | |
parent | 758b2c37776cb0871c65c44061e96076dc5f4dfa (diff) | |
parent | 49185875a5cd7f7e7a0799e40787cb358d3ba741 (diff) | |
download | rails-fa265346a95b2264f163f170e8322afb223063c7.tar.gz rails-fa265346a95b2264f163f170e8322afb223063c7.tar.bz2 rails-fa265346a95b2264f163f170e8322afb223063c7.zip |
Merge pull request #11559 from bughit/11533_to_proc
don't convert mailer default values to procs
-rw-r--r-- | actionmailer/CHANGELOG.md | 6 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 2 | ||||
-rw-r--r-- | actionmailer/test/base_test.rb | 4 | ||||
-rw-r--r-- | actionmailer/test/mailers/proc_mailer.rb | 3 |
4 files changed, 12 insertions, 3 deletions
diff --git a/actionmailer/CHANGELOG.md b/actionmailer/CHANGELOG.md index 9e9d07b386..1659696bfb 100644 --- a/actionmailer/CHANGELOG.md +++ b/actionmailer/CHANGELOG.md @@ -1,3 +1,7 @@ -* No changes. +* 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 [4-0-stable](https://github.com/rails/rails/blob/4-0-stable/actionmailer/CHANGELOG.md) for previous changes. diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index fcdd6747b8..cc3a412221 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -685,7 +685,7 @@ module ActionMailer # 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 diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index b9c56c540d..b74728ae34 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -578,6 +578,10 @@ class BaseTest < ActiveSupport::TestCase 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) diff --git a/actionmailer/test/mailers/proc_mailer.rb b/actionmailer/test/mailers/proc_mailer.rb index 733633b575..7e189d861f 100644 --- a/actionmailer/test/mailers/proc_mailer.rb +++ b/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 |