plataformatec/devise — pull request #2311 by pixeltrix (2013-03-01 14:47:43+00:00)
Title: Improve documentation on sending delayed emails

There are a couple of gotchas in the existing documentation about the `send_devise_notification` hook.

1. The `after_commit` callback can be called multiple times so you should clear the array otherwise any additional invocations will trigger extra copies of the email.

2. The `after_commit` callback is only called when a record is created or updated so you need to check for `new_record?` or `changed?` before adding it to `pending_notifications` otherwise it's okay to send it immediately.

The `new_record? || changed?` condition is necessary because the latter isn't always true for new records, e.g:

``` ruby
>> User.new.changed?
=> false
```