Permalink
Browse files

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>
  • Loading branch information...
mikel authored and josevalim committed May 2, 2010
1 parent 08b07b6 commit ceaa100e59c7953ce5c0e978ddd6d5bc046c9fd9
Showing with 15 additions and 2 deletions.
  1. +1 −1 actionmailer/lib/action_mailer/base.rb
  2. +14 −1 actionmailer/test/base_test.rb
@@ -530,7 +530,7 @@ def mail(headers={}, &block)

# 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
@@ -116,11 +116,19 @@ def different_layout(layout_name='')

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 @@ def self.delivering_email(mail)
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

0 comments on commit ceaa100

Please sign in to comment.