factory_bot 6.2.0 → 6.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/GETTING_STARTED.md +41 -1
- data/NEWS.md +6 -0
- data/lib/factory_bot/aliases.rb +1 -1
- data/lib/factory_bot/attribute_assigner.rb +3 -2
- data/lib/factory_bot/decorator.rb +1 -1
- data/lib/factory_bot/definition_proxy.rb +1 -1
- data/lib/factory_bot/evaluator.rb +2 -2
- data/lib/factory_bot/strategy/attributes_for.rb +4 -0
- data/lib/factory_bot/strategy/build.rb +4 -0
- data/lib/factory_bot/strategy/create.rb +4 -0
- data/lib/factory_bot/strategy/null.rb +4 -0
- data/lib/factory_bot/strategy/stub.rb +4 -0
- data/lib/factory_bot/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bcbbd8bee01abdb25a5cfdbbbbca29396f587236f0c20f8300adbf6e32f783c
|
4
|
+
data.tar.gz: 94d8e73507ae61edba7fb3129ee74c4fe9998a8fb78614ecba9966199561c8e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e97d9530810f0de00f6e0129df37db52722ee8d430f7b118ffdcebdc0eecc1e1532356b7c8e01cc85265c04f18eb174d3d5ff09fe235c5f30ceb7b5e16432508
|
7
|
+
data.tar.gz: 71b77c30b16c89588d6946505be547374321597e8e16f89673766cda94b22188dc28070a34144ae126dad93042de0173e1d92173237ae1e929a3131e85569a51
|
data/GETTING_STARTED.md
CHANGED
@@ -592,7 +592,7 @@ Attribute overrides can be used to link associated objects:
|
|
592
592
|
```ruby
|
593
593
|
FactoryBot.define do
|
594
594
|
factory :author do
|
595
|
-
|
595
|
+
name { 'Taylor' }
|
596
596
|
end
|
597
597
|
|
598
598
|
factory :post do
|
@@ -1013,6 +1013,15 @@ factory :post do
|
|
1013
1013
|
end
|
1014
1014
|
```
|
1015
1015
|
|
1016
|
+
Please note, that the value for the sequence could be any Enumerable instance,
|
1017
|
+
as long as it responds to `#next`:
|
1018
|
+
|
1019
|
+
```ruby
|
1020
|
+
factory :task do
|
1021
|
+
sequence :priority, %i[low medium high urgent].cycle
|
1022
|
+
end
|
1023
|
+
```
|
1024
|
+
|
1016
1025
|
### Aliases
|
1017
1026
|
|
1018
1027
|
Sequences can also have aliases. The sequence aliases share the same counter:
|
@@ -1187,6 +1196,28 @@ factory :user do
|
|
1187
1196
|
end
|
1188
1197
|
```
|
1189
1198
|
|
1199
|
+
### As mixins
|
1200
|
+
|
1201
|
+
Traits can be defined outside of factories and used as mixins to compose shared attributes
|
1202
|
+
|
1203
|
+
```ruby
|
1204
|
+
FactoryBot.define do
|
1205
|
+
trait :timestamps do
|
1206
|
+
created_at { 8.days.ago }
|
1207
|
+
updated_at { 4.days.ago }
|
1208
|
+
end
|
1209
|
+
|
1210
|
+
factory :user, traits: [:timestamps] do
|
1211
|
+
username { "john_doe" }
|
1212
|
+
end
|
1213
|
+
|
1214
|
+
factory :post do
|
1215
|
+
timestamps
|
1216
|
+
title { "Traits rock" }
|
1217
|
+
end
|
1218
|
+
end
|
1219
|
+
```
|
1220
|
+
|
1190
1221
|
### Using traits
|
1191
1222
|
|
1192
1223
|
Traits can also be passed in as a list of symbols when you construct an instance
|
@@ -1574,6 +1605,15 @@ twenty_somethings = build_list(:user, 10) do |user, i|
|
|
1574
1605
|
end
|
1575
1606
|
```
|
1576
1607
|
|
1608
|
+
`create_list` passes saved instances into the block. If you modify the instance, you must save it again:
|
1609
|
+
|
1610
|
+
```ruby
|
1611
|
+
twenty_somethings = create_list(:user, 10) do |user, i|
|
1612
|
+
user.date_of_birth = (20 + i).years.ago
|
1613
|
+
user.save!
|
1614
|
+
end
|
1615
|
+
```
|
1616
|
+
|
1577
1617
|
`build_stubbed_list` will give you fully stubbed out instances:
|
1578
1618
|
|
1579
1619
|
```ruby
|
data/NEWS.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# News
|
2
2
|
|
3
|
+
## 6.2.1 (March 8, 2022)
|
4
|
+
* Added: CI testing against truffleruby
|
5
|
+
* Changed: Documentation improvements for sequences and traits
|
6
|
+
* Fixed: ActiveSupport::Notifications reporting strategy through associations now report as symbols
|
7
|
+
* Fixed: `add_attribute` with reserved keywords assigns values correctly
|
8
|
+
|
3
9
|
## 6.2.0 (May 7, 2021)
|
4
10
|
* Added: support for Ruby 3.0
|
5
11
|
* Changed: Include factory or trait name in error messages for missing traits. d05a9a3c
|
data/lib/factory_bot/aliases.rb
CHANGED
@@ -37,8 +37,9 @@ module FactoryBot
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def decorated_evaluator
|
40
|
-
Decorator::
|
41
|
-
Decorator::
|
40
|
+
Decorator::NewConstructor.new(
|
41
|
+
Decorator::InvocationTracker.new(@evaluator),
|
42
|
+
@build_class
|
42
43
|
)
|
43
44
|
end
|
44
45
|
|
@@ -17,7 +17,7 @@ module FactoryBot
|
|
17
17
|
end
|
18
18
|
RUBY
|
19
19
|
else
|
20
|
-
def method_missing(name, *args, &block) # rubocop:disable Style/
|
20
|
+
def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondToMissing
|
21
21
|
@component.send(name, *args, &block)
|
22
22
|
end
|
23
23
|
|
@@ -88,7 +88,7 @@ module FactoryBot
|
|
88
88
|
# end
|
89
89
|
#
|
90
90
|
# are equivalent.
|
91
|
-
def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondToMissing
|
91
|
+
def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondToMissing
|
92
92
|
association_options = args.first
|
93
93
|
|
94
94
|
if association_options.nil?
|
@@ -24,7 +24,7 @@ module FactoryBot
|
|
24
24
|
def association(factory_name, *traits_and_overrides)
|
25
25
|
overrides = traits_and_overrides.extract_options!
|
26
26
|
strategy_override = overrides.fetch(:strategy) {
|
27
|
-
FactoryBot.use_parent_strategy ? @build_strategy.
|
27
|
+
FactoryBot.use_parent_strategy ? @build_strategy.to_sym : :create
|
28
28
|
}
|
29
29
|
|
30
30
|
traits_and_overrides += [overrides.except(:strategy)]
|
@@ -35,7 +35,7 @@ module FactoryBot
|
|
35
35
|
|
36
36
|
attr_accessor :instance
|
37
37
|
|
38
|
-
def method_missing(method_name, *args, &block)
|
38
|
+
def method_missing(method_name, *args, &block)
|
39
39
|
if @instance.respond_to?(method_name)
|
40
40
|
@instance.send(method_name, *args, &block)
|
41
41
|
else
|
data/lib/factory_bot/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factory_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.2.
|
4
|
+
version: 6.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Clayton
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-03-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -252,7 +252,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
252
252
|
- !ruby/object:Gem::Version
|
253
253
|
version: '0'
|
254
254
|
requirements: []
|
255
|
-
rubygems_version: 3.
|
255
|
+
rubygems_version: 3.1.6
|
256
256
|
signing_key:
|
257
257
|
specification_version: 4
|
258
258
|
summary: factory_bot provides a framework and DSL for defining and using model instance
|