提交 c1c4ecb9 编写于 作者: R Rafael Mendonça França

Merge pull request #6801 from dmathieu/mailer_raise_if_no_implicit_template

Mailer with no implicit template
## Rails 4.0.0 (unreleased) ##
* Raise an `ActionView::MissingTemplate` exception when no implicit template could be found. *Damien Mathieu*
## Rails 3.2.5 (Jun 1, 2012) ## ## Rails 3.2.5 (Jun 1, 2012) ##
* No changes. * No changes.
......
...@@ -184,6 +184,16 @@ module ActionMailer #:nodoc: ...@@ -184,6 +184,16 @@ module ActionMailer #:nodoc:
# and the second being a <tt>application/pdf</tt> with a Base64 encoded copy of the file.pdf book # and the second being a <tt>application/pdf</tt> with a Base64 encoded copy of the file.pdf book
# with the filename +free_book.pdf+. # with the filename +free_book.pdf+.
# #
# If you need to send attachments with no content, you need to create an empty view for it,
# or add an empty body parameter like this:
#
# class ApplicationMailer < ActionMailer::Base
# def welcome(recipient)
# attachments['free_book.pdf'] = File.read('path/to/file.pdf')
# mail(:to => recipient, :subject => "New account information", :body => "")
# end
# end
#
# = Inline Attachments # = Inline Attachments
# #
# You can also specify that a file should be displayed inline with other HTML. This is useful # You can also specify that a file should be displayed inline with other HTML. This is useful
...@@ -598,8 +608,10 @@ def attachments ...@@ -598,8 +608,10 @@ def attachments
# end # end
# end # end
# #
# Will look for all templates at "app/views/notifier" with name "welcome". However, those # Will look for all templates at "app/views/notifier" with name "welcome".
# can be customized: # If no welcome template exists, it will raise an ActionView::MissingTemplate error.
#
# However, those can be customized:
# #
# mail(:template_path => 'notifications', :template_name => 'another') # mail(:template_path => 'notifications', :template_name => 'another')
# #
...@@ -733,8 +745,12 @@ def collect_responses_and_parts_order(headers) #:nodoc: ...@@ -733,8 +745,12 @@ def collect_responses_and_parts_order(headers) #:nodoc:
def each_template(paths, name, &block) #:nodoc: def each_template(paths, name, &block) #:nodoc:
templates = lookup_context.find_all(name, Array(paths)) templates = lookup_context.find_all(name, Array(paths))
if templates.empty?
raise ActionView::MissingTemplate.new([paths], name, [paths], false, 'mailer')
else
templates.uniq { |t| t.formats }.each(&block) templates.uniq { |t| t.formats }.each(&block)
end end
end
def create_parts_from_responses(m, responses) #:nodoc: def create_parts_from_responses(m, responses) #:nodoc:
if responses.size == 1 && !m.has_attachments? if responses.size == 1 && !m.has_attachments?
......
...@@ -433,6 +433,13 @@ def teardown ...@@ -433,6 +433,13 @@ def teardown
assert_equal("TEXT Implicit Multipart", mail.text_part.body.decoded) assert_equal("TEXT Implicit Multipart", mail.text_part.body.decoded)
end end
test "should raise if missing template in implicit render" do
assert_raises ActionView::MissingTemplate do
BaseMailer.implicit_different_template('missing_template').deliver
end
assert_equal(0, BaseMailer.deliveries.length)
end
test "you can specify a different template for explicit render" do test "you can specify a different template for explicit render" do
mail = BaseMailer.explicit_different_template('explicit_multipart_templates').deliver mail = BaseMailer.explicit_different_template('explicit_multipart_templates').deliver
assert_equal("HTML Explicit Multipart Templates", mail.html_part.body.decoded) assert_equal("HTML Explicit Multipart Templates", mail.html_part.body.decoded)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册