Skip to content

Commit 8846ecb

Browse files
nganclaude
andcommitted
Rename mount label to "FixtureKit Insert" and harden coder subscriber
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) <noreply@anthropic.com>
1 parent 9aae82d commit 8846ecb

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

lib/fixture_kit/coders/active_record_coder.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ def generate(parent_data: nil, &block)
1515
model_name = name[NAME_PATTERN, :model_name]
1616
next unless model_name
1717

18-
captured_models.add(ActiveSupport::Inflector.constantize(model_name))
18+
klass = ActiveSupport::Inflector.safe_constantize(model_name)
19+
next unless klass.is_a?(Class) && klass < ActiveRecord::Base
20+
21+
captured_models.add(klass)
1922
end
2023

2124
ActiveSupport::Notifications.subscribed(subscriber, EVENT, monotonic: true, &block)
@@ -31,7 +34,7 @@ def mount(data)
3134
connection.disable_referential_integrity do
3235
# execute_batch is private in current supported Rails versions.
3336
# This should be revisited when Rails 8.2 makes it public.
34-
connection.__send__(:execute_batch, statements, "FixtureKit Load")
37+
connection.__send__(:execute_batch, statements, "FixtureKit Insert")
3538
end
3639
end
3740
end

spec/unit/coders/active_record_coder_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ def exercise_user_write_operations(suffix)
140140
]
141141

142142
expect(primary_connection).to receive(:disable_referential_integrity).once.and_yield
143-
expect(primary_connection).to receive(:execute_batch).with(primary_statements, "FixtureKit Load").once
143+
expect(primary_connection).to receive(:execute_batch).with(primary_statements, "FixtureKit Insert").once
144144
expect(analytics_connection).to receive(:disable_referential_integrity).once.and_yield
145-
expect(analytics_connection).to receive(:execute_batch).with(analytics_statements, "FixtureKit Load").once
145+
expect(analytics_connection).to receive(:execute_batch).with(analytics_statements, "FixtureKit Insert").once
146146

147147
coder.mount(records)
148148
end

spec/unit/fixture_cache_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,9 @@ def identifier_for(identifier)
356356
]
357357

358358
expect(primary_connection).to receive(:disable_referential_integrity).once.and_yield
359-
expect(primary_connection).to receive(:execute_batch).with(primary_statements, "FixtureKit Load").once
359+
expect(primary_connection).to receive(:execute_batch).with(primary_statements, "FixtureKit Insert").once
360360
expect(analytics_connection).to receive(:disable_referential_integrity).once.and_yield
361-
expect(analytics_connection).to receive(:execute_batch).with(analytics_statements, "FixtureKit Load").once
361+
expect(analytics_connection).to receive(:execute_batch).with(analytics_statements, "FixtureKit Insert").once
362362

363363
expect(cache.load).to eq(:repository)
364364
end

0 commit comments

Comments
 (0)