aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer
diff options
context:
space:
mode:
Diffstat (limited to 'actionmailer')
-rw-r--r--actionmailer/CHANGELOG.md2
-rw-r--r--actionmailer/lib/action_mailer/base.rb13
-rw-r--r--actionmailer/test/base_test.rb26
-rw-r--r--actionmailer/test/fixtures/base_test/after_action_mailer/welcome.html.erb (renamed from actionmailer/test/fixtures/base_test/after_filter_mailer/welcome.html.erb)0
-rw-r--r--actionmailer/test/fixtures/base_test/before_action_mailer/welcome.html.erb (renamed from actionmailer/test/fixtures/base_test/before_filter_mailer/welcome.html.erb)0
-rw-r--r--actionmailer/test/mailers/base_mailer.rb5
6 files changed, 30 insertions, 16 deletions
diff --git a/actionmailer/CHANGELOG.md b/actionmailer/CHANGELOG.md
index af91907f46..6fc25b3bb4 100644
--- a/actionmailer/CHANGELOG.md
+++ b/actionmailer/CHANGELOG.md
@@ -2,7 +2,7 @@
* Explicit multipart messages no longer set the order of the MIME parts.
*Nate Berkopec*
-
+
* Do not render views when mail() isn't called.
Fix #7761
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index 31005c9d9b..95a680ac23 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -284,12 +284,12 @@ module ActionMailer
#
# = Callbacks
#
- # You can specify callbacks using before_filter and after_filter for configuring your messages.
+ # You can specify callbacks using before_action and after_action for configuring your messages.
# This may be useful, for example, when you want to add default inline attachments for all
# messages sent out by a certain mailer class:
#
# class Notifier < ActionMailer::Base
- # before_filter :add_inline_attachment!
+ # before_action :add_inline_attachment!
#
# def welcome
# mail
@@ -306,8 +306,8 @@ module ActionMailer
# can define and configure callbacks in the same manner that you would use callbacks in
# classes that inherit from ActionController::Base.
#
- # Note that unless you have a specific reason to do so, you should prefer using before_filter
- # rather than after_filter in your ActionMailer classes so that headers are parsed properly.
+ # Note that unless you have a specific reason to do so, you should prefer using before_action
+ # rather than after_action in your ActionMailer classes so that headers are parsed properly.
#
# = Configuration options
#
@@ -499,6 +499,7 @@ module ActionMailer
# method, for instance).
def initialize(method_name=nil, *args)
super()
+ @_mail_was_called = false
@_message = Mail.new
process(method_name, *args) if method_name
end
@@ -506,7 +507,8 @@ module ActionMailer
def process(*args) #:nodoc:
lookup_context.skip_default_locale!
- @_message = NullMail.new unless super
+ super
+ @_message = NullMail.new unless @_mail_was_called
end
class NullMail #:nodoc:
@@ -666,6 +668,7 @@ module ActionMailer
# end
#
def mail(headers={}, &block)
+ @_mail_was_called = true
m = @_message
# At the beginning, do not consider class default for parts order neither content_type
diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb
index 3c21886502..170923673b 100644
--- a/actionmailer/test/base_test.rb
+++ b/actionmailer/test/base_test.rb
@@ -505,6 +505,12 @@ class BaseTest < ActiveSupport::TestCase
mail.deliver
end
+ test 'the return value of mailer methods is not relevant' do
+ mail = BaseMailer.with_nil_as_return_value
+ assert_equal('Welcome', mail.body.to_s.strip)
+ mail.deliver
+ end
+
# Before and After hooks
class MyObserver
@@ -584,9 +590,9 @@ class BaseTest < ActiveSupport::TestCase
assert_equal("Thanks for signing up this afternoon", mail.subject)
end
- test "modifying the mail message with a before_filter" do
- class BeforeFilterMailer < ActionMailer::Base
- before_filter :add_special_header!
+ test "modifying the mail message with a before_action" do
+ class BeforeActionMailer < ActionMailer::Base
+ before_action :add_special_header!
def welcome ; mail ; end
@@ -596,12 +602,12 @@ class BaseTest < ActiveSupport::TestCase
end
end
- assert_equal('Wow, so special', BeforeFilterMailer.welcome['X-Special-Header'].to_s)
+ assert_equal('Wow, so special', BeforeActionMailer.welcome['X-Special-Header'].to_s)
end
- test "modifying the mail message with an after_filter" do
- class AfterFilterMailer < ActionMailer::Base
- after_filter :add_special_header!
+ test "modifying the mail message with an after_action" do
+ class AfterActionMailer < ActionMailer::Base
+ after_action :add_special_header!
def welcome ; mail ; end
@@ -611,12 +617,12 @@ class BaseTest < ActiveSupport::TestCase
end
end
- assert_equal('Testing', AfterFilterMailer.welcome['X-Special-Header'].to_s)
+ assert_equal('Testing', AfterActionMailer.welcome['X-Special-Header'].to_s)
end
- test "adding an inline attachment using a before_filter" do
+ test "adding an inline attachment using a before_action" do
class DefaultInlineAttachmentMailer < ActionMailer::Base
- before_filter :add_inline_attachment!
+ before_action :add_inline_attachment!
def welcome ; mail ; end
diff --git a/actionmailer/test/fixtures/base_test/after_filter_mailer/welcome.html.erb b/actionmailer/test/fixtures/base_test/after_action_mailer/welcome.html.erb
index e69de29bb2..e69de29bb2 100644
--- a/actionmailer/test/fixtures/base_test/after_filter_mailer/welcome.html.erb
+++ b/actionmailer/test/fixtures/base_test/after_action_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_action_mailer/welcome.html.erb
index e69de29bb2..e69de29bb2 100644
--- a/actionmailer/test/fixtures/base_test/before_filter_mailer/welcome.html.erb
+++ b/actionmailer/test/fixtures/base_test/before_action_mailer/welcome.html.erb
diff --git a/actionmailer/test/mailers/base_mailer.rb b/actionmailer/test/mailers/base_mailer.rb
index 52342bc59e..8fca6177bd 100644
--- a/actionmailer/test/mailers/base_mailer.rb
+++ b/actionmailer/test/mailers/base_mailer.rb
@@ -118,4 +118,9 @@ class BaseMailer < ActionMailer::Base
def without_mail_call
end
+
+ def with_nil_as_return_value(hash = {})
+ mail(:template_name => "welcome")
+ nil
+ end
end