@@ -842,9 +842,12 @@ def setup_fixtures
842
842
@loaded_fixtures = load_fixtures
843
843
@@already_loaded_fixtures [ self . class ] = @loaded_fixtures
844
844
end
845
- ActiveRecord ::Base . connection . increment_open_transactions
846
- ActiveRecord ::Base . connection . transaction_joinable = false
847
- ActiveRecord ::Base . connection . begin_db_transaction
845
+ @fixture_connections = enlist_fixture_connections
846
+ @fixture_connections . each do |connection |
847
+ connection . increment_open_transactions
848
+ connection . transaction_joinable = false
849
+ connection . begin_db_transaction
850
+ end
848
851
# Load fixtures for every test.
849
852
else
850
853
ActiveRecord ::Fixtures . reset_cache
@@ -864,13 +867,22 @@ def teardown_fixtures
864
867
end
865
868
866
869
# Rollback changes if a transaction is active.
867
- if run_in_transaction? && ActiveRecord ::Base . connection . open_transactions != 0
868
- ActiveRecord ::Base . connection . rollback_db_transaction
869
- ActiveRecord ::Base . connection . decrement_open_transactions
870
+ if run_in_transaction?
871
+ @fixture_connections . each do |connection |
872
+ if connection . open_transactions != 0
873
+ connection . rollback_db_transaction
874
+ connection . decrement_open_transactions
875
+ end
876
+ end
877
+ @fixture_connections . clear
870
878
end
871
879
ActiveRecord ::Base . clear_active_connections!
872
880
end
873
881
882
+ def enlist_fixture_connections
883
+ ActiveRecord ::Base . connection_handler . connection_pools . values . map ( &:connection )
884
+ end
885
+
874
886
private
875
887
def load_fixtures
876
888
fixtures = ActiveRecord ::Fixtures . create_fixtures ( fixture_path , fixture_table_names , fixture_class_names )
0 commit comments