mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Adding options to register observers and interceptors through ActionMailer::Base.register_observer and ActionMailer::Base.register_interceptor. These hook into Mail.register_interceptor and Mail.register_observer. Also bumped Mail requirement to 2.1.3
Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
parent
a6684eeb78
commit
cefc136ec3
3 changed files with 42 additions and 1 deletions
|
@ -18,6 +18,6 @@ Gem::Specification.new do |s|
|
|||
s.has_rdoc = true
|
||||
|
||||
s.add_dependency('actionpack', '= 3.0.0.beta1')
|
||||
s.add_dependency('mail', '~> 2.1.2')
|
||||
s.add_dependency('mail', '~> 2.1.3')
|
||||
s.add_dependency('text-format', '~> 1.0.0')
|
||||
end
|
||||
|
|
|
@ -181,6 +181,18 @@ module ActionMailer #:nodoc:
|
|||
# and the second being a <tt>application/pdf</tt> with a Base64 encoded copy of the file.pdf book
|
||||
# with the filename +free_book.pdf+.
|
||||
#
|
||||
# = Observing and Intercepting Mails
|
||||
#
|
||||
# ActionMailer provides hooks into the Mail observer and interceptor methods. These allow you to
|
||||
# register objects that are called during the mail delivery life cycle.
|
||||
#
|
||||
# An observer object must implement the <tt>:delivered_email(message)</tt> method which will be
|
||||
# called once for every email sent after the email has been sent.
|
||||
#
|
||||
# An interceptor object must implement the <tt>:delivering_email(message)</tt> method which will be
|
||||
# called before the email is sent, allowing you to make modifications to the email before it hits
|
||||
# the delivery agents. Your object should make and needed modifications directly to the passed
|
||||
# in Mail::Message instance.
|
||||
#
|
||||
# = Configuration options
|
||||
#
|
||||
|
@ -265,6 +277,9 @@ module ActionMailer #:nodoc:
|
|||
|
||||
include ActionMailer::OldApi
|
||||
include ActionMailer::DeprecatedApi
|
||||
|
||||
delegate :register_observer, :to => Mail
|
||||
delegate :register_interceptor, :to => Mail
|
||||
|
||||
private_class_method :new #:nodoc:
|
||||
|
||||
|
|
|
@ -502,6 +502,32 @@ class BaseTest < ActiveSupport::TestCase
|
|||
mail = BaseMailer.welcome_from_another_path(['unknown/invalid', 'another.path/base_mailer'])
|
||||
assert_equal("Welcome from another path", mail.body.encoded)
|
||||
end
|
||||
|
||||
# Before and After hooks
|
||||
|
||||
class MyObserver
|
||||
def self.delivered_email(mail)
|
||||
end
|
||||
end
|
||||
|
||||
test "you can register an observer to the mail object that gets informed on email delivery" do
|
||||
ActionMailer::Base.register_observer(MyObserver)
|
||||
mail = BaseMailer.welcome
|
||||
MyObserver.expects(:delivered_email).with(mail)
|
||||
mail.deliver
|
||||
end
|
||||
|
||||
class MyInterceptor
|
||||
def self.delivering_email(mail)
|
||||
end
|
||||
end
|
||||
|
||||
test "you can register an interceptor to the mail object that gets passed the mail object before delivery" do
|
||||
ActionMailer::Base.register_interceptor(MyInterceptor)
|
||||
mail = BaseMailer.welcome
|
||||
MyInterceptor.expects(:delivering_email).with(mail)
|
||||
mail.deliver
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
|
|
Loading…
Reference in a new issue