From 9b72c36783516f5ef8f2fac5f6f342a6a48d8d78 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Mon, 10 Dec 2012 17:00:41 +0100 Subject: Backport #8450, the return value from mailer methods is not relevant. Conflicts: actionmailer/CHANGELOG.md actionmailer/lib/action_mailer/base.rb --- actionmailer/CHANGELOG.md | 16 ++++++++++++++++ actionmailer/lib/action_mailer/base.rb | 7 +++---- actionmailer/test/base_test.rb | 6 ++++++ actionmailer/test/mailers/base_mailer.rb | 5 +++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/actionmailer/CHANGELOG.md b/actionmailer/CHANGELOG.md index 1005516f42..d4d592a964 100644 --- a/actionmailer/CHANGELOG.md +++ b/actionmailer/CHANGELOG.md @@ -1,5 +1,21 @@ ## Rails 3.2.10 (unreleased) ## +* The return value from mailer methods is no longer relevant. This fixes a bug, + which was introduced with 3.2.9. + Backport #8450 + Fix #8448 + + class ExampleMailer < ActionMailer::Base + # in 3.2.9, returning a falsy value from a mailer action, prevented the email from beeing sent. + # With 3.2.10 the return value is no longer relevant. If you call mail() the email will be sent. + def nil_returning_mailer_action + mail() + nil + end + end + + *Yves Senn* + ## Rails 3.2.9 (Nov 12, 2012) ## * Do not render views when mail() isn't called. diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 1aeeadcacc..9e2f640915 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -448,6 +448,7 @@ module ActionMailer #:nodoc: # method, for instance). def initialize(method_name=nil, *args) super() + @mail_was_called = false @_message = Mail.new process(method_name, *args) if method_name end @@ -455,10 +456,8 @@ module ActionMailer #:nodoc: def process(*args) #:nodoc: lookup_context.skip_default_locale! - generated_mail = super - unless generated_mail - @_message = NullMail.new - end + super + @_message = NullMail.new unless @mail_was_called end class NullMail #:nodoc: diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index b69b26faf0..f648cb1546 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -477,6 +477,12 @@ class BaseTest < ActiveSupport::TestCase mail.deliver end + test 'the return value of mailer methods is not relevant' do + mail = BaseMailer.with_nil_as_return_value + assert_equal('Welcome', mail.body.to_s.strip) + mail.deliver + end + # Before and After hooks class MyObserver diff --git a/actionmailer/test/mailers/base_mailer.rb b/actionmailer/test/mailers/base_mailer.rb index 8c4430b046..50438ead2a 100644 --- a/actionmailer/test/mailers/base_mailer.rb +++ b/actionmailer/test/mailers/base_mailer.rb @@ -118,4 +118,9 @@ class BaseMailer < ActionMailer::Base def without_mail_call end + + def with_nil_as_return_value(hash = {}) + mail(:template_name => "welcome") + nil + end end -- cgit v1.2.3