aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2012-09-29 22:29:29 +0200
committerYves Senn <yves.senn@gmail.com>2012-10-28 20:45:43 +0100
commitb786f065d3fc6b0869f7f485042e8667e71ff66d (patch)
tree703e918d99de02f946898f019a74c1be5eff359e /actionmailer
parent2e44dda27ae8df9301b1a83bfaa74708678bfcd4 (diff)
downloadrails-b786f065d3fc6b0869f7f485042e8667e71ff66d.tar.gz
rails-b786f065d3fc6b0869f7f485042e8667e71ff66d.tar.bz2
rails-b786f065d3fc6b0869f7f485042e8667e71ff66d.zip
Do not render views when mail() isn't called. (NullMail refactoring)
Diffstat (limited to 'actionmailer')
-rw-r--r--actionmailer/CHANGELOG.md5
-rw-r--r--actionmailer/lib/action_mailer/base.rb14
-rw-r--r--actionmailer/test/base_test.rb6
-rw-r--r--actionmailer/test/fixtures/base_mailer/without_mail_call.erb1
-rw-r--r--actionmailer/test/mailers/base_mailer.rb3
5 files changed, 28 insertions, 1 deletions
diff --git a/actionmailer/CHANGELOG.md b/actionmailer/CHANGELOG.md
index 68b34805ff..ebce32bf11 100644
--- a/actionmailer/CHANGELOG.md
+++ b/actionmailer/CHANGELOG.md
@@ -1,5 +1,10 @@
## 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
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index fee4a64248..4d1c697502 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -510,7 +510,19 @@ module ActionMailer
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
diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb
index 1cb3ce63fe..b30ec2ddc9 100644
--- a/actionmailer/test/base_test.rb
+++ b/actionmailer/test/base_test.rb
@@ -499,6 +499,12 @@ class BaseTest < ActiveSupport::TestCase
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
diff --git a/actionmailer/test/fixtures/base_mailer/without_mail_call.erb b/actionmailer/test/fixtures/base_mailer/without_mail_call.erb
new file mode 100644
index 0000000000..290379d5fb
--- /dev/null
+++ b/actionmailer/test/fixtures/base_mailer/without_mail_call.erb
@@ -0,0 +1 @@
+<% raise 'the template should not be rendered' %> \ No newline at end of file
diff --git a/actionmailer/test/mailers/base_mailer.rb b/actionmailer/test/mailers/base_mailer.rb
index f25d9b9aff..52342bc59e 100644
--- a/actionmailer/test/mailers/base_mailer.rb
+++ b/actionmailer/test/mailers/base_mailer.rb
@@ -115,4 +115,7 @@ class BaseMailer < ActionMailer::Base
def email_with_translations
mail body: render("email_with_translations", formats: [:html])
end
+
+ def without_mail_call
+ end
end