diff options
author | Xavier Noria <fxn@hashref.com> | 2010-05-04 19:36:26 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-05-04 19:36:26 +0200 |
commit | 583b60d109522907020700225f1c739737297a2d (patch) | |
tree | a36d986cbbb73c94d217cbe86c9af7ef97a89567 /actionmailer | |
parent | 44a98967676492995d19fd4d541dbc9d52bf6b53 (diff) | |
parent | 0dd3b4630fea4bd4d4010b7096c9ee79d34c4501 (diff) | |
download | rails-583b60d109522907020700225f1c739737297a2d.tar.gz rails-583b60d109522907020700225f1c739737297a2d.tar.bz2 rails-583b60d109522907020700225f1c739737297a2d.zip |
Merge remote branch 'rails/master'
Diffstat (limited to 'actionmailer')
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 11 | ||||
-rw-r--r-- | actionmailer/test/base_test.rb | 30 |
2 files changed, 38 insertions, 3 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index efef5da6d7..88298966eb 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -354,7 +354,7 @@ module ActionMailer #:nodoc: # end # end def receive(raw_mail) - ActiveSupport::Notifications.instrument("action_mailer.receive") do |payload| + ActiveSupport::Notifications.instrument("receive.action_mailer") do |payload| mail = Mail.new(raw_mail) set_payload_for_mail(payload, mail) new.receive(mail) @@ -366,7 +366,7 @@ module ActionMailer #:nodoc: # when you call <tt>:deliver</tt> on the Mail::Message, calling +deliver_mail+ directly # and passing a Mail::Message will do nothing except tell the logger you sent the email. def deliver_mail(mail) #:nodoc: - ActiveSupport::Notifications.instrument("action_mailer.deliver") do |payload| + ActiveSupport::Notifications.instrument("deliver.action_mailer") do |payload| self.set_payload_for_mail(payload, mail) yield # Let Mail do the delivery actions end @@ -566,8 +566,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.bind(self).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 diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index 8e69073009..5506d62d6a 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -113,6 +113,23 @@ 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 }, + :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 assert_nothing_raised { BaseMailer.welcome } @@ -560,6 +577,19 @@ 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 + + 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 |