Reputation: 156
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!
Upvotes: 0
Views: 102
Reputation: 1965
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.
Upvotes: 0
Reputation: 9523
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.
Upvotes: 0