mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #8048 from senny/7761_dont_render_view_without_mail_call
Do not render views when mail() isn't called. (NullMail refactoring)
This commit is contained in:
commit
a273b6bd34
5 changed files with 28 additions and 1 deletions
|
@ -1,5 +1,10 @@
|
||||||
## Rails 4.0.0 (unreleased) ##
|
## Rails 4.0.0 (unreleased) ##
|
||||||
|
|
||||||
|
* Do not render views when mail() isn't called.
|
||||||
|
Fix #7761
|
||||||
|
|
||||||
|
*Yves Senn*
|
||||||
|
|
||||||
* Support `Mailer.deliver_foo(*args)` as a synonym for
|
* Support `Mailer.deliver_foo(*args)` as a synonym for
|
||||||
`Mailer.foo(*args).deliver`. This makes it easy to write e.g.
|
`Mailer.foo(*args).deliver`. This makes it easy to write e.g.
|
||||||
`Mailer.expects(:deliver_foo)` when testing code that calls
|
`Mailer.expects(:deliver_foo)` when testing code that calls
|
||||||
|
|
|
@ -510,7 +510,19 @@ module ActionMailer
|
||||||
|
|
||||||
def process(*args) #:nodoc:
|
def process(*args) #:nodoc:
|
||||||
lookup_context.skip_default_locale!
|
lookup_context.skip_default_locale!
|
||||||
super
|
|
||||||
|
generated_mail = super
|
||||||
|
unless generated_mail
|
||||||
|
@_message = NullMail.new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class NullMail #:nodoc:
|
||||||
|
def body; '' end
|
||||||
|
|
||||||
|
def method_missing(*args)
|
||||||
|
nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def mailer_name
|
def mailer_name
|
||||||
|
|
|
@ -499,6 +499,12 @@ class BaseTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'the view is not rendered when mail was never called' do
|
||||||
|
mail = BaseMailer.without_mail_call
|
||||||
|
assert_equal('', mail.body.to_s.strip)
|
||||||
|
mail.deliver
|
||||||
|
end
|
||||||
|
|
||||||
# Before and After hooks
|
# Before and After hooks
|
||||||
|
|
||||||
class MyObserver
|
class MyObserver
|
||||||
|
|
1
actionmailer/test/fixtures/base_mailer/without_mail_call.erb
vendored
Normal file
1
actionmailer/test/fixtures/base_mailer/without_mail_call.erb
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<% raise 'the template should not be rendered' %>
|
|
@ -115,4 +115,7 @@ class BaseMailer < ActionMailer::Base
|
||||||
def email_with_translations
|
def email_with_translations
|
||||||
mail body: render("email_with_translations", formats: [:html])
|
mail body: render("email_with_translations", formats: [:html])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def without_mail_call
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue