0

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!

Cattani
  • 124
  • 1
  • 9

2 Answers2

0

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.

Tamer Shlash
  • 9,314
  • 5
  • 44
  • 82
  • I think what OP was asking about is something like this: `context 'blah blah blah', with_after_commit: true do ... end`, which is exactly what I'm trying to find out. – Matthew Clark Jun 10 '22 at 19:45
0

I know this is old, but I had the same question, so I'm sharing what I figured out for posterity.

What you're seeing is an RSpec filter, which is basically a hook that can be selectively invoked.

So, in the question you cited, the example shows the following filter:

config.before(:each, :with_after_commit => true) do
  DatabaseCleaner.strategy = :truncation
end

Then the spec is defined as:

describe "", :with_after_commit => true do
  #...
end

So, the with_after_commit => true is what allows the before(:each) hook to fire.

Matthew Clark
  • 1,885
  • 21
  • 32