aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer
diff options
context:
space:
mode:
Diffstat (limited to 'actionmailer')
-rw-r--r--actionmailer/CHANGELOG.md5
-rw-r--r--actionmailer/lib/action_mailer/base.rb3
-rw-r--r--actionmailer/test/base_test.rb7
3 files changed, 15 insertions, 0 deletions
diff --git a/actionmailer/CHANGELOG.md b/actionmailer/CHANGELOG.md
index ed8ee89617..e29890f2d8 100644
--- a/actionmailer/CHANGELOG.md
+++ b/actionmailer/CHANGELOG.md
@@ -1,5 +1,10 @@
## Rails 4.0.0 (unreleased) ##
+* 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
+ the mailer. *Jon Leighton*
+
* Allow delivery method options to be set per mail instance *Aditya Sanghi*
If your smtp delivery settings are dynamic,
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index ff6911f44f..bd33f81f1e 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -142,6 +142,7 @@ module ActionMailer
# for delivery later:
#
# Notifier.welcome(david).deliver # sends the email
+ # Notifier.deliver_welcome(david) # synonym for the former
# mail = Notifier.welcome(david) # => a Mail::Message object
# mail.deliver # sends the email
#
@@ -487,6 +488,8 @@ module ActionMailer
def method_missing(method_name, *args)
if action_methods.include?(method_name.to_s)
QueuedMessage.new(queue, self, method_name, *args)
+ elsif method_name.to_s =~ /^deliver_(.+)$/ && action_methods.include?($1)
+ public_send($1, *args).deliver
else
super
end
diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb
index 4f2af50fdd..17ce8b7072 100644
--- a/actionmailer/test/base_test.rb
+++ b/actionmailer/test/base_test.rb
@@ -662,6 +662,13 @@ class BaseTest < ActiveSupport::TestCase
assert_equal ["robert.pankowecki@gmail.com"], DefaultFromMailer.welcome.from
end
+ test "Mailer.deliver_welcome calls Mailer.welcome.deliver" do
+ BaseMailer.deliveries.clear
+ BaseMailer.deliver_welcome(subject: 'omg')
+ assert_equal 1, BaseMailer.deliveries.length
+ assert_equal 'omg', BaseMailer.deliveries.first.subject
+ end
+
protected
# Execute the block setting the given values and restoring old values after