Module: Apartment::TestFixtures
- Defined in:
- lib/apartment/test_fixtures.rb
Overview
Prepended on the class that includes ActiveRecord::TestFixtures (e.g., ActiveSupport::TestCase or the RSpec fixture host).
Rails’ setup_shared_connection_pool iterates all shards registered in the ConnectionHandler and assumes every shard has a :writing pool_config. Apartment’s role-specific tenant shards violate this invariant, causing ArgumentError. This module deregisters apartment pools before the fixture machinery iterates them. Pools rebuild lazily on next connection_pool call.
A guard ivar (@apartment_fixtures_cleaned) controls the two call paths: first call runs cleanup + super; re-entrant calls (from the !connection.active_record subscriber in setup_transactional_fixtures) return immediately — apartment pools must not pass through super’s shard/role iteration.