Skip to content
This repository
Browse code

Merge pull request #8450 from senny/8448_mailer_return_values

the return value of mailer methods should not be relevant
  • Loading branch information...
commit 287a8d878ce18da401cbcc57c718a43c16e1494e 2 parents f2d1e27 + ec3429a
Rafael Mendonça França rafaelfranca authored
2  actionmailer/CHANGELOG.md
Source Rendered
@@ -2,7 +2,7 @@
2 2
3 3 * Explicit multipart messages no longer set the order of the MIME parts.
4 4 *Nate Berkopec*
5   -
  5 +
6 6 * Do not render views when mail() isn't called.
7 7 Fix #7761
8 8
5 actionmailer/lib/action_mailer/base.rb
@@ -499,6 +499,7 @@ def method_missing(method_name, *args)
499 499 # method, for instance).
500 500 def initialize(method_name=nil, *args)
501 501 super()
  502 + @_mail_was_called = false
502 503 @_message = Mail.new
503 504 process(method_name, *args) if method_name
504 505 end
@@ -506,7 +507,8 @@ def initialize(method_name=nil, *args)
506 507 def process(*args) #:nodoc:
507 508 lookup_context.skip_default_locale!
508 509
509   - @_message = NullMail.new unless super
  510 + super
  511 + @_message = NullMail.new unless @_mail_was_called
510 512 end
511 513
512 514 class NullMail #:nodoc:
@@ -666,6 +668,7 @@ def attachments
666 668 # end
667 669 #
668 670 def mail(headers={}, &block)
  671 + @_mail_was_called = true
669 672 m = @_message
670 673
671 674 # At the beginning, do not consider class default for parts order neither content_type
6 actionmailer/test/base_test.rb
@@ -505,6 +505,12 @@ def teardown
505 505 mail.deliver
506 506 end
507 507
  508 + test 'the return value of mailer methods is not relevant' do
  509 + mail = BaseMailer.with_nil_as_return_value
  510 + assert_equal('Welcome', mail.body.to_s.strip)
  511 + mail.deliver
  512 + end
  513 +
508 514 # Before and After hooks
509 515
510 516 class MyObserver
5 actionmailer/test/mailers/base_mailer.rb
@@ -118,4 +118,9 @@ def email_with_translations
118 118
119 119 def without_mail_call
120 120 end
  121 +
  122 + def with_nil_as_return_value(hash = {})
  123 + mail(:template_name => "welcome")
  124 + nil
  125 + end
121 126 end

0 comments on commit 287a8d8

Please sign in to comment.
Something went wrong with that request. Please try again.