Skip to content

Commit

Permalink
Allow primary key attributes
Browse files Browse the repository at this point in the history
This improvement went out too quickly, so let's undo it.

Lots of the work around it was great and we want to keep that, so this
surgically snips out:

- The README describing the feature.
- The ActiveRecordValidator that implements the validation.
- The railtie code that loaded the validator.

It leaves the validation framework and the notification code.
  • Loading branch information
mike-burns committed Dec 29, 2023
1 parent c4638f6 commit 7be631f
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 71 deletions.
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
18 changes: 0 additions & 18 deletions lib/factory_bot_rails/factory_validator/active_record_validator.rb

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.

0 comments on commit 7be631f

Please sign in to comment.