Random things, I think I know

after_commit callbacks not getting triggered in test environment.

You cannot test after_commit callbacks for Rails model, if you are using this RSpec configuration (either in spec_helper or rails_helper) `config.use_transactional_fixtures = true`.

This configuration tells RSpec to run each of your examples within a transaction. In fact, you can see this information in comments, if you have generated the rails_helper file with rspec:install. What this means is, though, there will be no real database COMMIT which normally happens during a database transaction. Thus, the after_commit callbacks will get called.

To circumvent this, you can use database_cleaner gem, which provides various strategies like transaction, truncation or deletion for cleaning your database.

No comments:

Post a Comment