From 8846ecb4d28bf67a26efd97e61aa28ed4ed0d9f0 Mon Sep 17 00:00:00 2001 From: Ngan Pham Date: Wed, 6 May 2026 12:53:48 -0700 Subject: [PATCH] Rename mount label to "FixtureKit Insert" and harden coder subscriber MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The execute_batch label for fixture mount changes from "FixtureKit Load" to "FixtureKit Insert" to align with Rails' own fixture insert naming. The label rename causes fixture_kit's own mount notifications to match the coder's NAME_PATTERN (which recognizes "Insert" as a write verb). Without a guard, nested fixture inheritance would feed the parent's mount notification back into the child's generate subscriber and constantize "FixtureKit" — the module, not a class — and crash inside base_table_model. Switch the subscriber to safe_constantize and require the result to be a Class < ActiveRecord::Base before capturing it. Non-AR matches are silently skipped instead of raising. Co-Authored-By: Claude Opus 4.7 (1M context) --- lib/fixture_kit/coders/active_record_coder.rb | 7 +++++-- spec/unit/coders/active_record_coder_spec.rb | 4 ++-- spec/unit/fixture_cache_spec.rb | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/fixture_kit/coders/active_record_coder.rb b/lib/fixture_kit/coders/active_record_coder.rb index d06e7f8..32138ba 100644 --- a/lib/fixture_kit/coders/active_record_coder.rb +++ b/lib/fixture_kit/coders/active_record_coder.rb @@ -15,7 +15,10 @@ def generate(parent_data: nil, &block) model_name = name[NAME_PATTERN, :model_name] next unless model_name - captured_models.add(ActiveSupport::Inflector.constantize(model_name)) + klass = ActiveSupport::Inflector.safe_constantize(model_name) + next unless klass.is_a?(Class) && klass < ActiveRecord::Base + + captured_models.add(klass) end ActiveSupport::Notifications.subscribed(subscriber, EVENT, monotonic: true, &block) @@ -31,7 +34,7 @@ def mount(data) connection.disable_referential_integrity do # execute_batch is private in current supported Rails versions. # This should be revisited when Rails 8.2 makes it public. - connection.__send__(:execute_batch, statements, "FixtureKit Load") + connection.__send__(:execute_batch, statements, "FixtureKit Insert") end end end diff --git a/spec/unit/coders/active_record_coder_spec.rb b/spec/unit/coders/active_record_coder_spec.rb index 78099b2..753d3e2 100644 --- a/spec/unit/coders/active_record_coder_spec.rb +++ b/spec/unit/coders/active_record_coder_spec.rb @@ -140,9 +140,9 @@ def exercise_user_write_operations(suffix) ] expect(primary_connection).to receive(:disable_referential_integrity).once.and_yield - expect(primary_connection).to receive(:execute_batch).with(primary_statements, "FixtureKit Load").once + expect(primary_connection).to receive(:execute_batch).with(primary_statements, "FixtureKit Insert").once expect(analytics_connection).to receive(:disable_referential_integrity).once.and_yield - expect(analytics_connection).to receive(:execute_batch).with(analytics_statements, "FixtureKit Load").once + expect(analytics_connection).to receive(:execute_batch).with(analytics_statements, "FixtureKit Insert").once coder.mount(records) end diff --git a/spec/unit/fixture_cache_spec.rb b/spec/unit/fixture_cache_spec.rb index 4f7d8f5..8d4a1bf 100644 --- a/spec/unit/fixture_cache_spec.rb +++ b/spec/unit/fixture_cache_spec.rb @@ -356,9 +356,9 @@ def identifier_for(identifier) ] expect(primary_connection).to receive(:disable_referential_integrity).once.and_yield - expect(primary_connection).to receive(:execute_batch).with(primary_statements, "FixtureKit Load").once + expect(primary_connection).to receive(:execute_batch).with(primary_statements, "FixtureKit Insert").once expect(analytics_connection).to receive(:disable_referential_integrity).once.and_yield - expect(analytics_connection).to receive(:execute_batch).with(analytics_statements, "FixtureKit Load").once + expect(analytics_connection).to receive(:execute_batch).with(analytics_statements, "FixtureKit Insert").once expect(cache.load).to eq(:repository) end