Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap ActiveRecord configuration into initializer #432

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions lib/factory_bot_rails/railtie.rb
leoarnold marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ class Railtie < Rails::Railtie
FactoryBot.definition_file_paths = definition_file_paths
end

ActiveSupport.on_load :active_record do
config = Rails.configuration.factory_bot
initializer "factory_bot.reject_primary_key_attributes" do
ActiveSupport.on_load :active_record do
config = Rails.configuration.factory_bot
leoarnold marked this conversation as resolved.
Show resolved Hide resolved

if config.reject_primary_key_attributes
require "factory_bot_rails/factory_validator/active_record_validator"
if config.reject_primary_key_attributes
require "factory_bot_rails/factory_validator/active_record_validator"

config.validator.add_validator FactoryValidator::ActiveRecordValidator.new
config.validator.add_validator FactoryValidator::ActiveRecordValidator.new
end
end
end

Expand Down
Loading