aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-06-20 13:09:54 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-06-20 13:09:54 -0700
commitc1c4ecb9dbf40ca8118d5c1c1053b158fe867229 (patch)
tree94dab7b2af1ebd7e052c866236524d52adaff302
parentb046ea452cdf08035d192d041250b436a3991af8 (diff)
parent45b1045d16126e69ad5af395fa14d1291914a4d4 (diff)
downloadrails-c1c4ecb9dbf40ca8118d5c1c1053b158fe867229.tar.gz
rails-c1c4ecb9dbf40ca8118d5c1c1053b158fe867229.tar.bz2
rails-c1c4ecb9dbf40ca8118d5c1c1053b158fe867229.zip
Merge pull request #6801 from dmathieu/mailer_raise_if_no_implicit_template
Mailer with no implicit template
-rw-r--r--actionmailer/CHANGELOG.md4
-rw-r--r--actionmailer/lib/action_mailer/base.rb22
-rw-r--r--actionmailer/test/base_test.rb7
-rw-r--r--actionmailer/test/fixtures/base_mailer/attachment_with_hash.html.erb0
-rw-r--r--actionmailer/test/fixtures/base_mailer/attachment_with_hash_default_encoding.html.erb0
-rw-r--r--actionmailer/test/fixtures/base_mailer/welcome_with_headers.html.erb0
-rw-r--r--actionmailer/test/fixtures/base_test/after_filter_mailer/welcome.html.erb0
-rw-r--r--actionmailer/test/fixtures/base_test/before_filter_mailer/welcome.html.erb0
-rw-r--r--actionmailer/test/fixtures/base_test/default_inline_attachment_mailer/welcome.html.erb0
-rw-r--r--actionmailer/test/fixtures/mail_delivery_test/delivery_mailer/welcome.html.erb0
-rw-r--r--actionmailer/test/fixtures/proc_mailer/welcome.html.erb0
11 files changed, 30 insertions, 3 deletions
diff --git a/actionmailer/CHANGELOG.md b/actionmailer/CHANGELOG.md
index e6021939ff..a822412090 100644
--- a/actionmailer/CHANGELOG.md
+++ b/actionmailer/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 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) ##
* No changes.
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index 4f0cff0612..1899b13e71 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -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
# 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
#
# You can also specify that a file should be displayed inline with other HTML. This is useful
@@ -598,8 +608,10 @@ module ActionMailer #:nodoc:
# end
# end
#
- # Will look for all templates at "app/views/notifier" with name "welcome". However, those
- # can be customized:
+ # Will look for all templates at "app/views/notifier" with name "welcome".
+ # If no welcome template exists, it will raise an ActionView::MissingTemplate error.
+ #
+ # However, those can be customized:
#
# mail(:template_path => 'notifications', :template_name => 'another')
#
@@ -733,7 +745,11 @@ module ActionMailer #:nodoc:
def each_template(paths, name, &block) #:nodoc:
templates = lookup_context.find_all(name, Array(paths))
- templates.uniq { |t| t.formats }.each(&block)
+ if templates.empty?
+ raise ActionView::MissingTemplate.new([paths], name, [paths], false, 'mailer')
+ else
+ templates.uniq { |t| t.formats }.each(&block)
+ end
end
def create_parts_from_responses(m, responses) #:nodoc:
diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb
index 1d747ed18a..1b2e39b3f7 100644
--- a/actionmailer/test/base_test.rb
+++ b/actionmailer/test/base_test.rb
@@ -433,6 +433,13 @@ class BaseTest < ActiveSupport::TestCase
assert_equal("TEXT Implicit Multipart", mail.text_part.body.decoded)
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
mail = BaseMailer.explicit_different_template('explicit_multipart_templates').deliver
assert_equal("HTML Explicit Multipart Templates", mail.html_part.body.decoded)
diff --git a/actionmailer/test/fixtures/base_mailer/attachment_with_hash.html.erb b/actionmailer/test/fixtures/base_mailer/attachment_with_hash.html.erb
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/actionmailer/test/fixtures/base_mailer/attachment_with_hash.html.erb
diff --git a/actionmailer/test/fixtures/base_mailer/attachment_with_hash_default_encoding.html.erb b/actionmailer/test/fixtures/base_mailer/attachment_with_hash_default_encoding.html.erb
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/actionmailer/test/fixtures/base_mailer/attachment_with_hash_default_encoding.html.erb
diff --git a/actionmailer/test/fixtures/base_mailer/welcome_with_headers.html.erb b/actionmailer/test/fixtures/base_mailer/welcome_with_headers.html.erb
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/actionmailer/test/fixtures/base_mailer/welcome_with_headers.html.erb
diff --git a/actionmailer/test/fixtures/base_test/after_filter_mailer/welcome.html.erb b/actionmailer/test/fixtures/base_test/after_filter_mailer/welcome.html.erb
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/actionmailer/test/fixtures/base_test/after_filter_mailer/welcome.html.erb
diff --git a/actionmailer/test/fixtures/base_test/before_filter_mailer/welcome.html.erb b/actionmailer/test/fixtures/base_test/before_filter_mailer/welcome.html.erb
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/actionmailer/test/fixtures/base_test/before_filter_mailer/welcome.html.erb
diff --git a/actionmailer/test/fixtures/base_test/default_inline_attachment_mailer/welcome.html.erb b/actionmailer/test/fixtures/base_test/default_inline_attachment_mailer/welcome.html.erb
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/actionmailer/test/fixtures/base_test/default_inline_attachment_mailer/welcome.html.erb
diff --git a/actionmailer/test/fixtures/mail_delivery_test/delivery_mailer/welcome.html.erb b/actionmailer/test/fixtures/mail_delivery_test/delivery_mailer/welcome.html.erb
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/actionmailer/test/fixtures/mail_delivery_test/delivery_mailer/welcome.html.erb
diff --git a/actionmailer/test/fixtures/proc_mailer/welcome.html.erb b/actionmailer/test/fixtures/proc_mailer/welcome.html.erb
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/actionmailer/test/fixtures/proc_mailer/welcome.html.erb