diff options
author | Josh Kalderimis <josh.kalderimis@gmail.com> | 2011-04-02 10:51:47 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-04-04 10:49:09 +0200 |
commit | 284ca810c17a89d15d809ba203289487044fcff9 (patch) | |
tree | 9e0be53c5e570609bea56ffc135638e493708d5e /actionmailer/test | |
parent | 454ec93ff79af4c0ddb31d01827021b549d12413 (diff) | |
download | rails-284ca810c17a89d15d809ba203289487044fcff9.tar.gz rails-284ca810c17a89d15d809ba203289487044fcff9.tar.bz2 rails-284ca810c17a89d15d809ba203289487044fcff9.zip |
remove AM delegating register_observer and register_interceptor to Mail and instead implement smarter versions allowing for string class names, also added proper Railtie support with tests.
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionmailer/test')
-rw-r--r-- | actionmailer/test/base_test.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb index 6a7931da8c..9fdd0e1ced 100644 --- a/actionmailer/test/base_test.rb +++ b/actionmailer/test/base_test.rb @@ -478,6 +478,11 @@ class BaseTest < ActiveSupport::TestCase end end + class MySecondObserver + 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 @@ -485,11 +490,31 @@ class BaseTest < ActiveSupport::TestCase mail.deliver end + test "you can register an observer using its stringified name to the mail object that gets informed on email delivery" do + ActionMailer::Base.register_observer("BaseTest::MyObserver") + mail = BaseMailer.welcome + MyObserver.expects(:delivered_email).with(mail) + mail.deliver + end + + test "you can register multiple observers to the mail object that both get informed on email delivery" do + ActionMailer::Base.register_observers("BaseTest::MyObserver", MySecondObserver) + mail = BaseMailer.welcome + MyObserver.expects(:delivered_email).with(mail) + MySecondObserver.expects(:delivered_email).with(mail) + mail.deliver + end + class MyInterceptor def self.delivering_email(mail) end end + class MySecondInterceptor + 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 @@ -497,6 +522,21 @@ class BaseTest < ActiveSupport::TestCase mail.deliver end + test "you can register an interceptor using its stringified name to the mail object that gets passed the mail object before delivery" do + ActionMailer::Base.register_interceptor("BaseTest::MyInterceptor") + mail = BaseMailer.welcome + MyInterceptor.expects(:delivering_email).with(mail) + mail.deliver + end + + test "you can register multiple interceptors to the mail object that both get passed the mail object before delivery" do + ActionMailer::Base.register_interceptors("BaseTest::MyInterceptor", MySecondInterceptor) + mail = BaseMailer.welcome + MyInterceptor.expects(:delivering_email).with(mail) + MySecondInterceptor.expects(:delivering_email).with(mail) + mail.deliver + end + test "being able to put proc's into the defaults hash and they get evaluated on mail sending" do mail1 = ProcMailer.welcome yesterday = 1.day.ago |