ruby-on-railsrspecruby-on-rails-5rspec-railsdatabase-cleaner

What is "with_after_commit" and why can't I find anything about it?


I helping out on a test suite that came from Rails 4 (which I am not so familiar with) and there were some tests that had "with_after_commit: true" in their declaration.

After a bit of tinkering I removed it and the test suite ran a little bit faster.

It was used in rails_helper.rb as well, much like this: Why after_commit not running even with use_transactional_fixtures = false

The thing is: I can't find any information about it that would justify its use. I only find references to it in the thread above.

Thanks!


Solution

  • What you're looking for is the ActiveRecord callback called after_commit, not with_after_commit (this is just the name of your test case).

    It's documented here and you can find plenty of resources if you just Google it.

    It's also good to take a look at the Active Record Callbacks Guide.