Testing after_commit with RSpec and mocking
I thought Mihail Davydenkov's comment deserved to be an answer:
You can also use
subject.run_callbacks(:commit)
.
Also note that this issue (commit callbacks not getting called in transactional tests) should be fixed in rails 5.0+ so you may wish to make a note to remove any workarounds you may use in the meantime when you upgrade. See: https://github.com/rails/rails/pull/18458
Try to use test_after_commit gem
or add following code in spec/support/helpers/test_after_commit.rb - Gist