factory_bot_rails 6.1.0 → 6.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +1 -1
- data/NEWS.md +27 -0
- data/README.md +24 -4
- data/lib/factory_bot_rails/factory_validator/active_record_validator.rb +18 -0
- data/lib/factory_bot_rails/factory_validator.rb +39 -0
- data/lib/factory_bot_rails/generators/null_generator.rb +1 -1
- data/lib/factory_bot_rails/railtie.rb +14 -0
- data/lib/generators/factory_bot.rb +1 -1
- data/lib/rails/projections.json +26 -0
- metadata +39 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5742c3086e009bf4ba09d13c5f912e547b06b71552747f9c2a8c8da26680025c
|
4
|
+
data.tar.gz: d789dd365195a302bd7888d2d927b34b797280f06614fa0e73d22b7d3f446755
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09f24e068c621baa9d6e2721abdaa54df0f4eeb88b3b258f394cdd7a6f1366bb66e8d0d7cf3ab000f86c7e1d93e0e3f333f1ac16158f9f789a5b80e7893549b9'
|
7
|
+
data.tar.gz: 6d5c4d46d035618cfb995db650b27cabc9f67439a0eabaf974e805dd9a989eb80d04082eebad64bf1a7575151a8062f91bea0f5d0b30123771da035198745177
|
data/CONTRIBUTING.md
CHANGED
@@ -35,5 +35,5 @@ Some things that will increase the chance that your pull request is accepted:
|
|
35
35
|
* Follow our [style guide][style].
|
36
36
|
* Write a [good commit message][commit].
|
37
37
|
|
38
|
-
[style]: https://github.com/thoughtbot/guides/tree/
|
38
|
+
[style]: https://github.com/thoughtbot/guides/tree/main/general
|
39
39
|
[commit]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
|
data/NEWS.md
CHANGED
@@ -3,6 +3,29 @@ there might not be any notable changes in new versions of this project.
|
|
3
3
|
|
4
4
|
# NEWS
|
5
5
|
|
6
|
+
## 6.3.0 (November 17, 2023)
|
7
|
+
|
8
|
+
* Changed: reject sequence definitions for ActiveRecord primary keys (Sean
|
9
|
+
Doyle).
|
10
|
+
* Changed: factory\_bot dependency to ~> 6.4 (Mike Burns).
|
11
|
+
* Changed: upgrade dependencies (Daniel Colson).
|
12
|
+
* Add: `projections.json` for Rails.vim (Caleb Hearth).
|
13
|
+
* Docs: fix broken link (Edu Depetris).
|
14
|
+
* Docs: mention Rails generator in docs (Edu Depetris).
|
15
|
+
* Docs: fix typo (Yudai Takada).
|
16
|
+
* Internal: skip Spring version 2.1.1 due to a bug in that release (Christina
|
17
|
+
Entcheva, Daniel Colson).
|
18
|
+
* Internal: test against Rails 6.1 (Antonis Berkakis).
|
19
|
+
* Internal: test against Ruby 3 (Daniel Colson).
|
20
|
+
* Internal: fewer warnings in Cucumber tests (Daniel Colson).
|
21
|
+
* Internal: use GitHub Actions for CI (Mathieu Jobin).
|
22
|
+
* Internal: a whole bunch of cleanup (Daniel Colson).
|
23
|
+
* Internal: fix CI due to a Bundler output change (Mike Burns).
|
24
|
+
|
25
|
+
## 6.2.0 (May 7, 2021)
|
26
|
+
|
27
|
+
* Changed: factory\_bot dependency to ~> 6.2.0
|
28
|
+
|
6
29
|
## 6.1.0 (July 8, 2020)
|
7
30
|
|
8
31
|
* Changed: factory\_bot dependency to ~> 6.1.0
|
@@ -15,6 +38,10 @@ there might not be any notable changes in new versions of this project.
|
|
15
38
|
reloader after application initialization
|
16
39
|
* Removed: support for EOL versions of Ruby (2.3, 2.4) and Rails (4.2)
|
17
40
|
|
41
|
+
## 5.2.0 (April 26, 2020)
|
42
|
+
|
43
|
+
* Changed: factory\_bot dependency to ~> 5.2.0
|
44
|
+
|
18
45
|
## 5.1.1 (September 24, 2019)
|
19
46
|
|
20
47
|
* Fixed: Ensure definitions do not load before I18n is initialized
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# factory_bot_rails [![
|
1
|
+
# factory_bot_rails [![Code Climate][grade-image]][grade] [![Gem Version][version-image]][version]
|
2
2
|
|
3
3
|
[factory_bot][fb] is a fixtures replacement with a straightforward definition
|
4
4
|
syntax, support for multiple build strategies (saved instances, unsaved
|
@@ -15,7 +15,7 @@ Check out the [guide](https://github.com/thoughtbot/factory_bot/blob/4-9-0-stabl
|
|
15
15
|
factory\_bot\_rails provides Rails integration for [factory_bot][fb].
|
16
16
|
|
17
17
|
Supported Rails versions are listed in [`Appraisals`](Appraisals). Supported
|
18
|
-
Ruby versions are listed in [`.
|
18
|
+
Ruby versions are listed in [`.github/workflows/build.yml`](.github/workflows/build.yml).
|
19
19
|
|
20
20
|
## Download
|
21
21
|
|
@@ -144,8 +144,30 @@ Note that factory\_bot\_rails will only use this custom template if you are
|
|
144
144
|
generating each factory in a separate file; it will have no effect if you are
|
145
145
|
generating all of your factories in `test/factories.rb` or `spec/factories.rb`.
|
146
146
|
|
147
|
+
Factory\_bot\_rails will add a custom generator:
|
148
|
+
|
149
|
+
```shell
|
150
|
+
rails generate factory_bot:model NAME [field:type field:type] [options]
|
151
|
+
```
|
152
|
+
|
147
153
|
[default factory template]: https://github.com/thoughtbot/factory_bot_rails/tree/master/lib/generators/factory_bot/model/templates/factories.erb
|
148
154
|
|
155
|
+
### Active Record Configuration
|
156
|
+
|
157
|
+
By default, FactoryBot will refuse to generate Active Record primary key
|
158
|
+
columns. Without additional configuration, an Active Record model treats a
|
159
|
+
column named `id` as its primary key.
|
160
|
+
|
161
|
+
For example, defining an `id` attribute with `add_attribute(:id)`, `id { ... }`,
|
162
|
+
or `sequence(:id)` will raise a `FactoryBot::AttributeDefinitionError`.
|
163
|
+
|
164
|
+
You can disable this behavior by adding the following to `config/application.rb`
|
165
|
+
or the appropriate environment configuration in `config/environments`:
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
config.factory_bot.reject_primary_key_attributes = false
|
169
|
+
```
|
170
|
+
|
149
171
|
## Contributing
|
150
172
|
|
151
173
|
Please see [CONTRIBUTING.md](CONTRIBUTING.md).
|
@@ -171,8 +193,6 @@ See [our other projects][community].
|
|
171
193
|
We are [available for hire][hire].
|
172
194
|
|
173
195
|
[fb]: https://github.com/thoughtbot/factory_bot
|
174
|
-
[ci]: http://travis-ci.org/thoughtbot/factory_bot_rails?branch=master
|
175
|
-
[ci-image]: https://secure.travis-ci.org/thoughtbot/factory_bot_rails.svg
|
176
196
|
[grade]: https://codeclimate.com/github/thoughtbot/factory_bot_rails
|
177
197
|
[grade-image]: https://codeclimate.com/github/thoughtbot/factory_bot_rails.svg
|
178
198
|
[community]: https://thoughtbot.com/community?utm_source=github
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module FactoryBotRails
|
2
|
+
class FactoryValidator
|
3
|
+
class ActiveRecordValidator
|
4
|
+
def validate!(payload)
|
5
|
+
attributes, for_class = payload.values_at(:attributes, :class)
|
6
|
+
attributes.each do |attribute|
|
7
|
+
if for_class < ActiveRecord::Base && for_class.primary_key == attribute.name.to_s
|
8
|
+
raise FactoryBot::AttributeDefinitionError, <<~ERROR
|
9
|
+
Attribute generates #{for_class.primary_key.inspect} primary key for #{for_class.name}"
|
10
|
+
|
11
|
+
Do not define #{for_class.primary_key.inspect}. Instead, rely on the database to generate it.
|
12
|
+
ERROR
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module FactoryBotRails
|
2
|
+
class FactoryValidator
|
3
|
+
def initialize(validators = [])
|
4
|
+
@validators = Array(validators)
|
5
|
+
end
|
6
|
+
|
7
|
+
def add_validator(validator)
|
8
|
+
@validators << validator
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
ActiveSupport::Notifications.subscribe("factory_bot.compile_factory", &validate_compiled_factory)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def validate_compiled_factory
|
18
|
+
if Rails.version >= "6.0"
|
19
|
+
rails_6_0_support
|
20
|
+
else
|
21
|
+
rails_5_2_support
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def rails_6_0_support
|
26
|
+
proc do |event|
|
27
|
+
@validators.each { |validator| validator.validate!(event.payload) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def rails_5_2_support
|
32
|
+
proc do |*notification_event_arguments|
|
33
|
+
event = ActiveSupport::Notifications::Event.new(*notification_event_arguments)
|
34
|
+
|
35
|
+
rails_6_0_support.call(event)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -3,12 +3,15 @@
|
|
3
3
|
require "factory_bot"
|
4
4
|
require "factory_bot_rails/generator"
|
5
5
|
require "factory_bot_rails/reloader"
|
6
|
+
require "factory_bot_rails/factory_validator"
|
6
7
|
require "rails"
|
7
8
|
|
8
9
|
module FactoryBotRails
|
9
10
|
class Railtie < Rails::Railtie
|
10
11
|
config.factory_bot = ActiveSupport::OrderedOptions.new
|
11
12
|
config.factory_bot.definition_file_paths = FactoryBot.definition_file_paths
|
13
|
+
config.factory_bot.reject_primary_key_attributes = true
|
14
|
+
config.factory_bot.validator = FactoryBotRails::FactoryValidator.new
|
12
15
|
|
13
16
|
initializer "factory_bot.set_fixture_replacement" do
|
14
17
|
Generator.new(config).run
|
@@ -18,9 +21,20 @@ module FactoryBotRails
|
|
18
21
|
FactoryBot.definition_file_paths = definition_file_paths
|
19
22
|
end
|
20
23
|
|
24
|
+
ActiveSupport.on_load :active_record do
|
25
|
+
config = Rails.configuration.factory_bot
|
26
|
+
|
27
|
+
if config.reject_primary_key_attributes
|
28
|
+
require "factory_bot_rails/factory_validator/active_record_validator"
|
29
|
+
|
30
|
+
config.validator.add_validator FactoryValidator::ActiveRecordValidator.new
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
21
34
|
config.after_initialize do |app|
|
22
35
|
FactoryBot.find_definitions
|
23
36
|
Reloader.new(app).run
|
37
|
+
app.config.factory_bot.validator.run
|
24
38
|
end
|
25
39
|
|
26
40
|
private
|
@@ -0,0 +1,26 @@
|
|
1
|
+
{
|
2
|
+
"spec/factories/*.rb": {
|
3
|
+
"alternate": "app/models/{singular}.rb",
|
4
|
+
"collection": "model",
|
5
|
+
"command": "factory",
|
6
|
+
"template": [
|
7
|
+
"FactoryBot.define do",
|
8
|
+
" factory :{singular} do",
|
9
|
+
" end",
|
10
|
+
"end"
|
11
|
+
],
|
12
|
+
"test": "spec/models/{singular}_spec.rb"
|
13
|
+
},
|
14
|
+
"test/factories/*.rb": {
|
15
|
+
"alternate": "app/models/{singular}.rb",
|
16
|
+
"collection": "model",
|
17
|
+
"command": "factory",
|
18
|
+
"template": [
|
19
|
+
"FactoryBot.define do",
|
20
|
+
" factory :{singular} do",
|
21
|
+
" end",
|
22
|
+
"end"
|
23
|
+
],
|
24
|
+
"test": "test/models/{singular}_test.rb"
|
25
|
+
}
|
26
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factory_bot_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Ferris
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: factory_bot
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 6.
|
19
|
+
version: '6.4'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 6.
|
26
|
+
version: '6.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: railties
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 5.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 5.0.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 5.0.0
|
41
69
|
description: factory_bot_rails provides integration between factory_bot and rails
|
42
70
|
5.0 or newer
|
43
71
|
email: jferris@thoughtbot.com
|
@@ -51,6 +79,8 @@ files:
|
|
51
79
|
- README.md
|
52
80
|
- lib/factory_bot_rails.rb
|
53
81
|
- lib/factory_bot_rails/definition_file_paths.rb
|
82
|
+
- lib/factory_bot_rails/factory_validator.rb
|
83
|
+
- lib/factory_bot_rails/factory_validator/active_record_validator.rb
|
54
84
|
- lib/factory_bot_rails/generator.rb
|
55
85
|
- lib/factory_bot_rails/generators/non_rspec_generator.rb
|
56
86
|
- lib/factory_bot_rails/generators/null_generator.rb
|
@@ -60,11 +90,12 @@ files:
|
|
60
90
|
- lib/generators/factory_bot.rb
|
61
91
|
- lib/generators/factory_bot/model/model_generator.rb
|
62
92
|
- lib/generators/factory_bot/model/templates/factories.erb
|
93
|
+
- lib/rails/projections.json
|
63
94
|
homepage: https://github.com/thoughtbot/factory_bot_rails
|
64
95
|
licenses:
|
65
96
|
- MIT
|
66
97
|
metadata: {}
|
67
|
-
post_install_message:
|
98
|
+
post_install_message:
|
68
99
|
rdoc_options: []
|
69
100
|
require_paths:
|
70
101
|
- lib
|
@@ -79,8 +110,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
110
|
- !ruby/object:Gem::Version
|
80
111
|
version: '0'
|
81
112
|
requirements: []
|
82
|
-
rubygems_version: 3.
|
83
|
-
signing_key:
|
113
|
+
rubygems_version: 3.4.6
|
114
|
+
signing_key:
|
84
115
|
specification_version: 4
|
85
116
|
summary: factory_bot_rails provides integration between factory_bot and rails 5.0
|
86
117
|
or newer
|