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

Allow primary key attributes #451

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
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
16 changes: 0 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,6 @@ rails generate factory_bot:model NAME [field:type field:type] [options]

[default factory template]: https://github.com/thoughtbot/factory_bot_rails/tree/main/lib/generators/factory_bot/model/templates/factories.erb

### Active Record Configuration

By default, FactoryBot will refuse to generate Active Record primary key
columns. Without additional configuration, an Active Record model treats a
column named `id` as its primary key.

For example, defining an `id` attribute with `add_attribute(:id)`, `id { ... }`,
or `sequence(:id)` will raise a `FactoryBot::AttributeDefinitionError`.

You can disable this behavior by adding the following to the appropriate environment configuration in `config/environments`
e.g. `config/environments/test.rb`:

```ruby
config.factory_bot.reject_primary_key_attributes = false
```

## Contributing

Please see [CONTRIBUTING.md](CONTRIBUTING.md).
Expand Down

This file was deleted.

13 changes: 0 additions & 13 deletions lib/factory_bot_rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module FactoryBotRails
class Railtie < Rails::Railtie
config.factory_bot = ActiveSupport::OrderedOptions.new
config.factory_bot.definition_file_paths = FactoryBot.definition_file_paths
config.factory_bot.reject_primary_key_attributes = true
config.factory_bot.validator = FactoryBotRails::FactoryValidator.new

initializer "factory_bot.set_fixture_replacement" do
Expand All @@ -21,18 +20,6 @@ class Railtie < Rails::Railtie
FactoryBot.definition_file_paths = definition_file_paths
end

initializer "factory_bot.reject_primary_key_attributes" do
ActiveSupport.on_load :active_record do
config = Rails.configuration.factory_bot

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

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

config.after_initialize do |app|
FactoryBot.find_definitions
Reloader.new(app).run
Expand Down

This file was deleted.