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