提交 b786f065 编写于 作者: Y Yves Senn

Do not render views when mail() isn't called. (NullMail refactoring)

上级 2e44dda2
## 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
`Mailer.foo(*args).deliver`. This makes it easy to write e.g.
`Mailer.expects(:deliver_foo)` when testing code that calls
......
......@@ -510,7 +510,19 @@ def initialize(method_name=nil, *args)
def process(*args) #:nodoc:
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
def mailer_name
......
......@@ -499,6 +499,12 @@ def teardown
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
class MyObserver
......
<% raise 'the template should not be rendered' %>
\ No newline at end of file
......@@ -115,4 +115,7 @@ def different_layout(layout_name='')
def email_with_translations
mail body: render("email_with_translations", formats: [:html])
end
def without_mail_call
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册