Skip to content

Commit

Permalink
Merge pull request #8450 from senny/8448_mailer_return_values
Browse files Browse the repository at this point in the history
the return value of mailer methods should not be relevant
  • Loading branch information
rafaelfranca committed Dec 10, 2012
2 parents f2d1e27 + ec3429a commit 287a8d8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion actionmailer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion actionmailer/lib/action_mailer/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -499,14 +499,16 @@ def method_missing(method_name, *args)
# 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

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:
Expand Down Expand Up @@ -666,6 +668,7 @@ def attachments
# 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
Expand Down
6 changes: 6 additions & 0 deletions actionmailer/test/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ def teardown
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
Expand Down
5 changes: 5 additions & 0 deletions actionmailer/test/mailers/base_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,9 @@ def email_with_translations

def without_mail_call
end

def with_nil_as_return_value(hash = {})
mail(:template_name => "welcome")
nil
end
end

0 comments on commit 287a8d8

Please sign in to comment.