Permalink
Browse files

update readme

  • Loading branch information...
spaghetticode committed May 16, 2012
1 parent 38d4fc1 commit d5c9d7dc4de3b8b43a666f210436d7015ad5bfcd
Showing with 11 additions and 92 deletions.
  1. +11 −8 README.md
  2. +0 −84 features/around_deliver_callback.feature
View
@@ -2,15 +2,19 @@
[![Build Status](https://secure.travis-ci.org/spaghetticode/actionmailer-callbacks.png)](http://travis-ci.org/spaghetticode/actionmailer-callbacks)
-This gem adds the following methods to ActionMailer, similar to ActionController
-before/around filters:
+This gem adds before_create and around_create to ActionMailer::Base to make it
+work similarly to ActionController before/around filters and ActiveRecord::Base
+callbacks:
```ruby
before_create :log_params, except: :test_email
around_create :benchmark, only: :test_email
- around_deliver :benckmark
```
+*except* and *only* options are optional and has same functionality as in
+ActionController.
+
+
## Requirements
The master branch now works only with Actionmailer 3.x, if you need to add
@@ -33,11 +37,10 @@ And then run ```bundle```
If you need something like before/after deliver callbacks ActionMailer 3.x comes
ready for that: you can use an *observer* or an *instrumentation* for that.
-*around_create* and *around_deliver* wrap the mail method execution (and all
-callbacks). You can use them for rescuing from errors or for benchmarking, for
-example.
-There can be only one *around_create* or *around_deliver* method for each email method,
-if there are more than one only the first will be executed.
+*around_create* wrap the mail method execution (and all before_create callbacks).
+You can use them for rescuing from errors or for benchmarking, for example.
+There can be only one *around_create* method for each email method, if you
+register more than one only the first will be executed.
## Example
@@ -1,84 +0,0 @@
-Feature: around_deliver callback
- As an actionmailer gem user
- I want to be able to use the around_create callback
- So that I can wrap the email creation process with my callback
-
- The "around_deliver" callback allows to wrap the email creation
- process around another method definition.
- The macro accepts the callback name as first arguments and an
- optional hash with "only" and/or "except" keys that are
- functionally equivalent to the ones of ActionController
- before/after/around create filters: for example in order
- to run a callback only for the "test" action you should
- specify one of the following:
- around_deliver :test_callback, only: :test
- around_deliver :test_callback, only: [:test]
-
-Scenario: successful around_deliver calling
- Given the following mailer class with an around_deliver callback:
- """
- class TestMailer < ::ActionMailer::Base
- around_deliver :log_args
-
- def self.logger
- @logger ||= Array.new
- end
-
- def test(recipient)
- mail(
- to: recipient,
- from: 'sender@test.com',
- subject: 'Test Email'
- )
- end
-
- private
-
- def log_args(*args)
- self.class.logger << "Test email now being called"
- yield
- self.class.logger << "Test email was successfully created"
- end
- end
- """
- When I run the code "TestMailer.test('recipient@test.com').deliver"
- Then an email should have been created
- And the logger for the class "TestMailer" should contain:
- """
- Test email now being called
- """
- And the logger for the class "TestMailer" should contain:
- """
- Test email was successfully created
- """
-
- Scenario: around_deliver callback skipped because not included in "only" directive
- Given the following mailer class with an around_deliver callback:
- """
- class TestMailer < ::ActionMailer::Base
- around_deliver :log_args, only: :only_method
-
- def self.logger
- @logger ||= Array.new
- end
-
- def test(recipient)
- mail(
- to: recipient,
- from: 'sender@test.com',
- subject: 'Test Email'
- )
- end
-
- private
-
- def log_args(*args)
- self.class.logger << "Test email now being called"
- yield
- self.class.logger << "Test email was successfully created"
- end
- end
- """
- When I run the code "TestMailer.test('recipient@test.com').deliver"
- Then an email should have been created
- And the logger for the class "TestMailer" should be empty

0 comments on commit d5c9d7d

Please sign in to comment.