Skip to content
This repository
Browse code

don't convert mailer default values to procs

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
  • Loading branch information...
commit 49185875a5cd7f7e7a0799e40787cb358d3ba741 1 parent 1c4eb13
bughit authored
6  actionmailer/CHANGELOG.md
Source Rendered
... ...
@@ -1,3 +1,7 @@
1  
-* No changes.
  1
+* invoke mailer defaults as procs only if they are procs, do not convert
  2
+  with to_proc.  That an object is convertible to a proc does not mean it's
  3
+  meant to be always used as a proc.  Fixes #11533
  4
+
  5
+  *Alex Tsukernik*
2 6
 
3 7
 Please check [4-0-stable](https://github.com/rails/rails/blob/4-0-stable/actionmailer/CHANGELOG.md) for previous changes.
2  actionmailer/lib/action_mailer/base.rb
@@ -685,7 +685,7 @@ def mail(headers = {}, &block)
685 685
       # Call all the procs (if any)
686 686
       class_default = self.class.default
687 687
       default_values = class_default.merge(class_default) do |k,v|
688  
-        v.respond_to?(:to_proc) ? instance_eval(&v) : v
  688
+        v.is_a?(Proc) ? instance_eval(&v) : v
689 689
       end
690 690
 
691 691
       # Handle defaults
4  actionmailer/test/base_test.rb
@@ -578,6 +578,10 @@ def self.delivering_email(mail)
578 578
     assert(mail1.to_s.to_i > mail2.to_s.to_i)
579 579
   end
580 580
 
  581
+  test 'default values which have to_proc (e.g. symbols) should not be considered procs' do
  582
+    assert(ProcMailer.welcome['x-has-to-proc'].to_s == 'symbol')
  583
+  end
  584
+
581 585
   test "we can call other defined methods on the class as needed" do
582 586
     mail = ProcMailer.welcome
583 587
     assert_equal("Thanks for signing up this afternoon", mail.subject)
3  actionmailer/test/mailers/proc_mailer.rb
... ...
@@ -1,7 +1,8 @@
1 1
 class ProcMailer < ActionMailer::Base
2 2
   default to: 'system@test.lindsaar.net',
3 3
           'X-Proc-Method' => Proc.new { Time.now.to_i.to_s },
4  
-          subject: Proc.new { give_a_greeting }
  4
+          subject: Proc.new { give_a_greeting },
  5
+          'x-has-to-proc' => :symbol
5 6
 
6 7
   def welcome
7 8
     mail

0 notes on commit 4918587

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