From 59305b7d5d272b97ad6ef173f028d612acbd90eb Mon Sep 17 00:00:00 2001 From: Joel Chippindale Date: Tue, 5 May 2009 09:37:44 +0100 Subject: [PATCH 1/2] Default sent_on time to now in ActionMailer This is the most common time to set for the a mail and makes it less likely that a mail will be sent out without the date header being set. --- actionmailer/lib/action_mailer/base.rb | 1 + actionmailer/test/mail_service_test.rb | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index af2cc2e..541c72b 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -552,6 +552,7 @@ module ActionMailer #:nodoc: @headers ||= {} @body ||= {} @mime_version = @@default_mime_version.dup if @@default_mime_version + @sent_on ||= Time.now end def render_template(template, body) diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index 919ab5d..934a207 100644 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -18,7 +18,6 @@ class TestMailer < ActionMailer::Base @recipients = recipient @subject = "[Signed up] Welcome #{recipient}" @from = "system@loudthinking.com" - @sent_on = Time.local(2004, 12, 12) @body["recipient"] = recipient end @@ -357,12 +356,14 @@ class ActionMailerTest < Test::Unit::TestCase end def test_signed_up + Time.stubs(:now => Time.now) + expected = new_mail expected.to = @recipient expected.subject = "[Signed up] Welcome #{@recipient}" expected.body = "Hello there, \n\nMr. #{@recipient}" expected.from = "system@loudthinking.com" - expected.date = Time.local(2004, 12, 12) + expected.date = Time.now created = nil assert_nothing_raised { created = TestMailer.create_signed_up(@recipient) } -- 1.6.3.1 From ccbae570f0d9e1972c0eb6c8ecf1f45fca38a5f7 Mon Sep 17 00:00:00 2001 From: Joel Chippindale Date: Thu, 11 Jun 2009 09:40:10 +0100 Subject: [PATCH 2/2] Added test to show you can get old behaviour by setting sent_on to nil --- actionmailer/test/mail_service_test.rb | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-) diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index 934a207..4a1b7c3 100644 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -279,6 +279,14 @@ class TestMailer < ActionMailer::Base body :body => "foo", :bar => "baz" end + def sent_on_nil(recipient) + recipients recipient + subject "Date set to nil" + from "test@example.com" + body "testing" + sent_on nil + end + class <