factory_bot_rails 6.2.0 → 6.4.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 +23 -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 +36 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce9d8cf1fe40c932f0bdeaeacd7488dfbe5c0581c1c98b29038e870552a44b9a
|
4
|
+
data.tar.gz: '09e14df93a58faa9a3893e8605935873400f529ed8707f5ecbd10f7cbf672c26'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 781f4d1586a5e2b034ebfab8ee1d2c4a48df0dc22522c3700f183790baa8cf3c4b5a68b3891545209b56b3a9509f93832514951ae759da292533d37e2321115b
|
7
|
+
data.tar.gz: 549bd3783563c7719867505e15deee790014f54a50653415971a7c006b6e2c2da9cb6ee3e45630e000632832efa76c15f7c60ebf2965938bf380aaa8d2ba5ec7
|
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.4.0 (November 17, 2023)
|
7
|
+
|
8
|
+
* Releasing this for consistency with the factory\_bot dependency.
|
9
|
+
|
10
|
+
## 6.3.0 (November 17, 2023)
|
11
|
+
|
12
|
+
* Changed: reject sequence definitions for ActiveRecord primary keys (Sean
|
13
|
+
Doyle).
|
14
|
+
* Changed: factory\_bot dependency to ~> 6.4 (Mike Burns).
|
15
|
+
* Changed: upgrade dependencies (Daniel Colson).
|
16
|
+
* Add: `projections.json` for Rails.vim (Caleb Hearth).
|
17
|
+
* Docs: fix broken link (Edu Depetris).
|
18
|
+
* Docs: mention Rails generator in docs (Edu Depetris).
|
19
|
+
* Docs: fix typo (Yudai Takada).
|
20
|
+
* Internal: skip Spring version 2.1.1 due to a bug in that release (Christina
|
21
|
+
Entcheva, Daniel Colson).
|
22
|
+
* Internal: test against Rails 6.1 (Antonis Berkakis).
|
23
|
+
* Internal: test against Ruby 3 (Daniel Colson).
|
24
|
+
* Internal: fewer warnings in Cucumber tests (Daniel Colson).
|
25
|
+
* Internal: use GitHub Actions for CI (Mathieu Jobin).
|
26
|
+
* Internal: a whole bunch of cleanup (Daniel Colson).
|
27
|
+
* Internal: fix CI due to a Bundler output change (Mike Burns).
|
28
|
+
|
6
29
|
## 6.2.0 (May 7, 2021)
|
7
30
|
|
8
31
|
* Changed: factory\_bot dependency to ~> 6.2.0
|
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.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Ferris
|
8
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,6 +90,7 @@ 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
|
@@ -79,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
110
|
- !ruby/object:Gem::Version
|
80
111
|
version: '0'
|
81
112
|
requirements: []
|
82
|
-
rubygems_version: 3.
|
113
|
+
rubygems_version: 3.4.6
|
83
114
|
signing_key:
|
84
115
|
specification_version: 4
|
85
116
|
summary: factory_bot_rails provides integration between factory_bot and rails 5.0
|