mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Adding ability to pass proc's to the ActionMailer class default method
Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
parent
256a15c235
commit
08b07b60b6
2 changed files with 23 additions and 1 deletions
|
@ -528,8 +528,13 @@ module ActionMailer #:nodoc:
|
|||
content_type = headers[:content_type]
|
||||
parts_order = headers[:parts_order]
|
||||
|
||||
# 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
|
||||
end
|
||||
|
||||
# Handle defaults
|
||||
headers = headers.reverse_merge(self.class.default)
|
||||
headers = headers.reverse_merge(default_values)
|
||||
headers[:subject] ||= default_i18n_subject
|
||||
|
||||
# Apply charset at the beginning so all fields are properly quoted
|
||||
|
|
|
@ -113,6 +113,15 @@ class BaseTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
class ProcMailer < ActionMailer::Base
|
||||
default :to => 'system@test.lindsaar.net',
|
||||
'X-Proc-Method' => Proc.new { Time.now.to_i.to_s }
|
||||
|
||||
def welcome
|
||||
mail
|
||||
end
|
||||
end
|
||||
|
||||
test "method call to mail does not raise error" do
|
||||
assert_nothing_raised { BaseMailer.welcome }
|
||||
|
@ -560,6 +569,14 @@ class BaseTest < ActiveSupport::TestCase
|
|||
MyInterceptor.expects(:delivering_email).with(mail)
|
||||
mail.deliver
|
||||
end
|
||||
|
||||
test "being able to put proc's into the defaults hash and they get evaluated on mail sending" do
|
||||
mail1 = ProcMailer.welcome
|
||||
yesterday = 1.day.ago
|
||||
Time.stubs(:now).returns(yesterday)
|
||||
mail2 = ProcMailer.welcome
|
||||
assert(mail1['X-Proc-Method'].to_s.to_i > mail2['X-Proc-Method'].to_s.to_i)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
|
|
Loading…
Reference in a new issue