mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #8450 from senny/8448_mailer_return_values
the return value of mailer methods should not be relevant
This commit is contained in:
commit
287a8d878c
4 changed files with 16 additions and 2 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
* Explicit multipart messages no longer set the order of the MIME parts.
|
||||
*Nate Berkopec*
|
||||
|
||||
|
||||
* Do not render views when mail() isn't called.
|
||||
Fix #7761
|
||||
|
||||
|
|
|
@ -499,6 +499,7 @@ module ActionMailer
|
|||
# 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
|
||||
|
@ -506,7 +507,8 @@ module ActionMailer
|
|||
def process(*args) #:nodoc:
|
||||
lookup_context.skip_default_locale!
|
||||
|
||||
@_message = NullMail.new unless super
|
||||
super
|
||||
@_message = NullMail.new unless @_mail_was_called
|
||||
end
|
||||
|
||||
class NullMail #:nodoc:
|
||||
|
@ -666,6 +668,7 @@ module ActionMailer
|
|||
# end
|
||||
#
|
||||
def mail(headers={}, &block)
|
||||
@_mail_was_called = true
|
||||
m = @_message
|
||||
|
||||
# At the beginning, do not consider class default for parts order neither content_type
|
||||
|
|
|
@ -505,6 +505,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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue