A few days ago, I've had a few failing jobs on Resque to send confirmation e-mails with ActiveRecord::RecordNotFound errors, because Resque tried to send the e-mail after the resource is created, but before database commit.
Changing this on Confirmable did the trick, but some tests failed because devise's test suit uses ActiveSuport::TestCase.use_transactional_fixtures, and the mail is never sent, since the transaction is never commited.
diff --git a/lib/devise/models/confirmable.rb b/lib/devise/models/confirmable.rb
index f21ecb7..a50c9ee 100644
@@ -34,7 +34,7 @@ module Devise
before_create :generate_confirmation_token, :if => :confirmation_required?
- after_create :send_on_create_confirmation_instructions, :if => :confirmation_required?
+ after_commit :send_on_create_confirmation_instructions, :if => :confirmation_required?
before_update :postpone_email_change_until_confirmation, :if => :postpone_email_change?
after_update :send_confirmation_instructions, :if => :reconfirmation_required?
Yeah, check this:
We won't default to after_commit, but there is a mechanism on master that allows you to fix this issue.