Testing the after_commit byte in Rails 4 with transactional lights turned on

I have a Rails 4 application and I use transactional tools and want my hook_cooks to fire when my integration specifications start.

Of course, no commits happen when you use transactional lights, so in Rails 3 there was this patch: https://gist.github.com/charleseff/1305285 , and it was made into a gem: 'test_after_commit'

Rails 4 has changed the internals of active_record so much that Rails 3 patches cannot be ported.

Has anyone solved this problem in Rails 4?

+4
source share
1 answer

I solved this by putting the following code in spec / support / helpers / test_after_commit.rb

require 'active_record/connection_adapters/abstract/transaction' module ActiveRecord module ConnectionAdapters class SavepointTransaction < OpenTransaction def perform_commit_with_transactional_fixtures commit_records if number == 1 perform_commit_without_transactional_fixtures end alias_method_chain :perform_commit, :transactional_fixtures end end end 

https://gist.github.com/cmaitchison/5168104

+3
source

Source: https://habr.com/ru/post/1469423/


All Articles