aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer
diff options
context:
space:
mode:
authorMikel Lindsaar <raasdnil@gmail.com>2010-05-02 13:16:28 +1000
committerJosé Valim <jose.valim@gmail.com>2010-05-02 11:56:08 +0200
commitceaa100e59c7953ce5c0e978ddd6d5bc046c9fd9 (patch)
tree62b46bc1f51d5821bd2c7d2868ee70de890b78ad /actionmailer
parent08b07b60b6d91a2f7bba5eec1e9b1d26599c578a (diff)
downloadrails-ceaa100e59c7953ce5c0e978ddd6d5bc046c9fd9.tar.gz
rails-ceaa100e59c7953ce5c0e978ddd6d5bc046c9fd9.tar.bz2
rails-ceaa100e59c7953ce5c0e978ddd6d5bc046c9fd9.zip
Adding ability for the procs to be called within the instance, allows you to pass results from instance methods to the mail header
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionmailer')
-rw-r--r--actionmailer/lib/action_mailer/base.rb2
-rw-r--r--actionmailer/test/base_test.rb15
2 files changed, 15 insertions, 2 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index 3a49da5984..b88172dfc2 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -530,7 +530,7 @@ module ActionMailer #:nodoc:
# Call all the procs (if any)
default_values = self.class.default.merge(self.class.default) do |k,v|
- v.respond_to?(:call) ? v.call : v
+ v.respond_to?(:call) ? v.bind(self).call : v
end
# Handle defaults
diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb
index 81e41dc8d4..5506d62d6a 100644
--- a/actionmailer/test/base_test.rb
+++ b/actionmailer/test/base_test.rb
@@ -116,11 +116,19 @@ class BaseTest < ActiveSupport::TestCase
class ProcMailer < ActionMailer::Base
default :to => 'system@test.lindsaar.net',
- 'X-Proc-Method' => Proc.new { Time.now.to_i.to_s }
+ 'X-Proc-Method' => Proc.new { Time.now.to_i.to_s },
+ :subject => Proc.new { give_a_greeting }
def welcome
mail
end
+
+ private
+
+ def give_a_greeting
+ "Thanks for signing up this afternoon"
+ end
+
end
test "method call to mail does not raise error" do
@@ -577,6 +585,11 @@ class BaseTest < ActiveSupport::TestCase
mail2 = ProcMailer.welcome
assert(mail1['X-Proc-Method'].to_s.to_i > mail2['X-Proc-Method'].to_s.to_i)
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)
+ end
protected