Note: This PR is only a proof of concept idea due to monkey-patching FactoryBot::Factory.
Problem
A new default in factory_bot_rails is to raise errors when a factory is defining a primary key. There are occasionally needs to assign a ActiveRecord model's primary key explicitly in a factory (see examples in #438). We don't want to entirely skip that additional check for every factory by disabling reject_primary_key_attributes for all factories.
Possible Solution
Add a per factory configuration to skip the check for specific factories.
FactoryBot.define do
factory :warehouse, config: { allow_primary_key_definitions: true } do
sequence(:id)
end
end
Note: This PR is only a proof of concept idea due to monkey-patching
FactoryBot::Factory
.Problem
A new default in factory_bot_rails is to raise errors when a factory is defining a primary key. There are occasionally needs to assign a
ActiveRecord
model's primary key explicitly in a factory (see examples in #438). We don't want to entirely skip that additional check for every factory by disablingreject_primary_key_attributes
for all factories.Possible Solution
Add a per factory configuration to skip the check for specific factories.