Skip to content
Browse files

Merge pull request #8048 from senny/7761_dont_render_view_without_mai…

…l_call

Do not render views when mail() isn't called. (NullMail refactoring)
Conflicts:
	actionmailer/CHANGELOG.md
  • Loading branch information...
1 parent 2b5d3aa commit 37586ddf279c46c3d0c8c2553d0918aa82ceb020 @rafaelfranca rafaelfranca committed Oct 28, 2012
View
11 actionmailer/CHANGELOG.md
@@ -1,15 +1,26 @@
+## Rails 3.2.9 (unreleased) ##
+
+* Do not render views when mail() isn't called.
+ Fix #7761
+
+ *Yves Senn*
+
+
## Rails 3.2.8 (Aug 9, 2012) ##
* No changes.
+
## Rails 3.2.7 (Jul 26, 2012) ##
* No changes.
+
## Rails 3.2.6 (Jun 12, 2012) ##
* No changes.
+
## Rails 3.2.5 (Jun 1, 2012) ##
* No changes.
View
14 actionmailer/lib/action_mailer/base.rb
@@ -454,7 +454,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
View
6 actionmailer/test/base_test.rb
@@ -471,6 +471,12 @@ def teardown
assert_equal(%{<img alt="Dummy" src="http://local.com/images/dummy.png" />}, mail.body.to_s.strip)
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
View
1 actionmailer/test/fixtures/base_mailer/without_mail_call.erb
@@ -0,0 +1 @@
+<% raise 'the template should not be rendered' %>
View
3 actionmailer/test/mailers/base_mailer.rb
@@ -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

0 comments on commit 37586dd

Please sign in to comment.
Something went wrong with that request. Please try again.