plataformatec/devise — pull request #2430 by kramerc (2013-05-23 03:18:38+00:00)
Title: Avoid sending confirmations to blank emails.

When writing tests for my Devise model, I came across an issue when using the `should validate_uniqueness_of` matcher from [Shoulda](https://github.com/thoughtbot/shoulda-matchers).

```
1) User
Failure/Error: it { should validate_uniqueness_of :username }
ArgumentError:
At least one recipient (To, Cc or Bcc) is required to send a message
# ./spec/models/user_spec.rb:6:in `block (2 levels) in '
```

Shoulda [skips validations](https://github.com/thoughtbot/shoulda-matchers/blob/2b9130b46266d062dd731ce58950406c5fa94f71/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb#L126) when creating records for this matcher. As it is only filling in one attribute, which in this case is username, Devise tries to send a confirmation email to a blank email address after the first record is created because it assumes validations won't be skipped. This results in the error above.

I fixed this issue by modifying the methods inside confirmable that consider whether to send (re)confirmations and consider whether postponing the email address change for reconfirmations to account for blank email addresses.