55
66ActiveJob ::Base . logger = Logger . new ( nil )
77
8+ # Shared test store UUID for parallel mutant workers
9+ DEFAULT_TEST_STORE_ID = "00000000-0000-4000-8000-000000000001"
10+
11+ # Global hook to ensure default store exists before ANY test runs
12+ # This runs once per test process, after DB is prepared but before tests start
13+ module EnsureDefaultStore
14+ def before_setup
15+ unless defined? ( @@default_store_created )
16+ ActiveRecord ::Base . connection . execute ( <<-SQL )
17+ INSERT INTO admin_stores (id, name, created_at, updated_at)
18+ VALUES ('#{ DEFAULT_TEST_STORE_ID } ', 'Default Test Store', NOW(), NOW())
19+ ON CONFLICT (id) DO NOTHING
20+ SQL
21+ @@default_store_created = true
22+ end
23+ super
24+ end
25+ end
26+
27+ # Prepend to all integration tests
28+ ActionDispatch ::IntegrationTest . prepend ( EnsureDefaultStore )
29+
830class InMemoryTestCase < ActiveSupport ::TestCase
931
1032 def before_setup
@@ -130,9 +152,6 @@ def payment_released
130152end
131153
132154class InMemoryRESIntegrationTestCase < ActionDispatch ::IntegrationTest
133- # Shared test store UUID - used by all parallel workers to avoid transaction isolation issues
134- DEFAULT_TEST_STORE_ID = "00000000-0000-4000-8000-000000000001"
135-
136155 def before_setup
137156 result = super
138157 @previous_event_store = Rails . configuration . event_store
@@ -141,7 +160,7 @@ def before_setup
141160 Rails . configuration . command_bus = Arkency ::CommandBus . new
142161
143162 Configuration . new . call ( Rails . configuration . event_store , Rails . configuration . command_bus )
144- @default_store_id = ensure_default_store
163+ @default_store_id = DEFAULT_TEST_STORE_ID
145164 result
146165 end
147166
@@ -237,17 +256,6 @@ def run_command(command)
237256 Rails . configuration . command_bus . call ( command )
238257 end
239258
240- def ensure_default_store
241- # Create default test store directly in DB, outside of transaction
242- # This ensures it's visible to all parallel mutant workers
243- ActiveRecord ::Base . connection . execute ( <<-SQL )
244- INSERT INTO admin_stores (id, name, created_at, updated_at)
245- VALUES ('#{ DEFAULT_TEST_STORE_ID } ', 'Default Test Store', NOW(), NOW())
246- ON CONFLICT (id) DO NOTHING
247- SQL
248- DEFAULT_TEST_STORE_ID
249- end
250-
251259 def register_store ( name )
252260 # For "Default Store", return the shared test store ID
253261 return DEFAULT_TEST_STORE_ID if name == "Default Store" || name == "Default Test Store"
0 commit comments