Search code examples
ruby-on-rails-3ruby-on-rails-3.1commitrspec2rspec-rails

Why after_commit not running even with use_transactional_fixtures = false


Transactional fixtures in rspec prevent after_commit from being called, but even when I disable them with

RSpec.configure do |config|
  config.use_transactional_fixtures = false
end

The after_commit callback does not run.

Here is a rails app with the latest rspec / rails that I have produced the issue on: git://github.com/sheabarton/after_commit_demo.git


Solution

  • One way around this is to trigger the commit callbacks manually. Example:

    describe SomeModel do
      subject { ... }
    
      context 'after_commit' do
        after { subject.run_callbacks(:commit) }
    
        it 'does something' do
          subject.should_receive(:some_message)
        end
      end
    end
    

    A little late, but hope this helps others.