mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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.
This commit is contained in:
parent
aa8918aecb
commit
7e0cf56363
3 changed files with 15 additions and 0 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue