factory_bot 6.0.2 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/GETTING_STARTED.md +17 -0
- data/NEWS.md +8 -0
- data/README.md +2 -8
- data/lib/factory_bot/declaration/association.rb +23 -6
- data/lib/factory_bot/decorator.rb +18 -6
- data/lib/factory_bot/decorator/invocation_tracker.rb +10 -3
- data/lib/factory_bot/evaluator.rb +16 -6
- data/lib/factory_bot/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe33ad3bb5d907e38ceac543f969484fb0ec67a4708a701cdfea0696d4a292c4
|
4
|
+
data.tar.gz: 54cdb44f4ac7782360c8e9efd02ac46f40336d00c34a5767d5d7fc0f86f8d7a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdc3ec9def71e797058fb13cff95b911eceb61d1488f193ef1bfb6bdf12c6c7835d1f67dc1885d5539e6da7135f04e4a417a16fbc60cbc0c4d60056a1948c89d
|
7
|
+
data.tar.gz: 2f04ab1a184266a86cf8510be688b8a01b0dd570615d25e314176b4492f9635053596636aa4ec9ab8133e86e4c9f630acdb52468c01ea1bfd2fb8777fc27b2ab
|
data/GETTING_STARTED.md
CHANGED
@@ -52,6 +52,7 @@ Getting Started
|
|
52
52
|
+ [Without a block](#without-a-block)
|
53
53
|
+ [Aliases](#aliases-1)
|
54
54
|
+ [Rewinding](#rewinding)
|
55
|
+
+ [Uniqueness](#uniqueness)
|
55
56
|
* [Traits](#traits)
|
56
57
|
+ [Defining traits](#defining-traits)
|
57
58
|
+ [As implicit attributes](#as-implicit-attributes-1)
|
@@ -878,6 +879,22 @@ generate(:email) # "person1@example.com"
|
|
878
879
|
|
879
880
|
This rewinds all registered sequences.
|
880
881
|
|
882
|
+
### Uniqueness
|
883
|
+
|
884
|
+
When working with uniqueness constraints, be careful not to pass in override values that will conflict with the generated sequence values.
|
885
|
+
|
886
|
+
In this example the email will be the same for both users. If email must be unique, this code will error:
|
887
|
+
|
888
|
+
```rb
|
889
|
+
factory :user do
|
890
|
+
sequence(:email) { |n| "person#{n}@example.com" }
|
891
|
+
end
|
892
|
+
|
893
|
+
FactoryBot.create(:user, email: "person1@example.com")
|
894
|
+
FactoryBot.create(:user)
|
895
|
+
```
|
896
|
+
|
897
|
+
|
881
898
|
Traits
|
882
899
|
------
|
883
900
|
|
data/NEWS.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# News
|
2
2
|
|
3
|
+
## 6.1.0 (July 8, 2020)
|
4
|
+
* Added: public reader for the evaluation instance, helpful for building interrelated associations
|
5
|
+
* Changed: raise a more helpful error when passing an invalid argument to an association
|
6
|
+
* Fixed: Ruby 2.7 kwarg deprecation warnings
|
7
|
+
|
3
8
|
## 6.0.2 (June 19, 2020)
|
4
9
|
* Fixed: bug causing traits to consume more memory each time they were used
|
5
10
|
|
@@ -8,6 +13,9 @@
|
|
8
13
|
|
9
14
|
## 6.0.0 (June 18, 2020)
|
10
15
|
* Added: automatic definition of traits for Active Record enum attributes, enabled by default
|
16
|
+
(Note that this required changing where factory_bot constantizes the build
|
17
|
+
class, which may affect applications that were using abstract factories for
|
18
|
+
inheritance. See issue #1409.)
|
11
19
|
* Added: `traits_for_enum` method to define traits for non-Active Record enums
|
12
20
|
* Added: `build_stubbed_starting_id=` option to define the starting id for `build_stubbed`
|
13
21
|
* Removed: deprecated methods on the top-level `FactoryBot` module meant only for internal use
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# factory_bot [![Build Status][ci-image]][ci] [![Code Climate][grade-image]][grade] [![Gem Version][version-image]][version]
|
1
|
+
# factory_bot [![Build Status][ci-image]][ci] [![Code Climate][grade-image]][grade] [![Gem Version][version-image]][version]
|
2
2
|
|
3
3
|
factory_bot is a fixtures replacement with a straightforward definition syntax, support for multiple build strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class (user, admin_user, and so on), including factory inheritance.
|
4
4
|
|
@@ -43,13 +43,7 @@ gem install factory_bot
|
|
43
43
|
Supported Ruby versions
|
44
44
|
-----------------------
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
The factory_bot 3.x+ series supports MRI Ruby 1.9. Additionally, factory_bot
|
49
|
-
3.6+ supports JRuby 1.6.7.2+ while running in 1.9 mode. See [GETTING_STARTED]
|
50
|
-
for more information on configuring the JRuby environment.
|
51
|
-
|
52
|
-
For versions of Ruby prior to 1.9, please use factory_bot 2.x.
|
46
|
+
Supported Ruby versions are listed in [`.travis.yml`](https://github.com/thoughtbot/factory_bot/blob/master/.travis.yml)
|
53
47
|
|
54
48
|
More Information
|
55
49
|
----------------
|
@@ -6,6 +6,7 @@ module FactoryBot
|
|
6
6
|
super(name, false)
|
7
7
|
@options = options.dup
|
8
8
|
@overrides = options.extract_options!
|
9
|
+
@factory_name = @overrides.delete(:factory) || name
|
9
10
|
@traits = options
|
10
11
|
end
|
11
12
|
|
@@ -21,20 +22,36 @@ module FactoryBot
|
|
21
22
|
|
22
23
|
private
|
23
24
|
|
25
|
+
attr_reader :factory_name, :overrides, :traits
|
26
|
+
|
24
27
|
def build
|
25
|
-
|
28
|
+
raise_if_arguments_are_declarations!
|
26
29
|
|
27
|
-
|
28
|
-
|
30
|
+
[
|
31
|
+
Attribute::Association.new(
|
32
|
+
name,
|
33
|
+
factory_name,
|
34
|
+
[traits, overrides].flatten
|
35
|
+
)
|
36
|
+
]
|
29
37
|
end
|
30
38
|
|
31
|
-
def
|
32
|
-
if
|
39
|
+
def raise_if_arguments_are_declarations!
|
40
|
+
if factory_name.is_a?(Declaration)
|
33
41
|
raise ArgumentError.new(<<~MSG)
|
34
42
|
Association '#{name}' received an invalid factory argument.
|
35
|
-
Did you mean? 'factory: :#{
|
43
|
+
Did you mean? 'factory: :#{factory_name.name}'
|
36
44
|
MSG
|
37
45
|
end
|
46
|
+
|
47
|
+
overrides.each do |attribute, value|
|
48
|
+
if value.is_a?(Declaration)
|
49
|
+
raise ArgumentError.new(<<~MSG)
|
50
|
+
Association '#{name}' received an invalid attribute override.
|
51
|
+
Did you mean? '#{attribute}: :#{value.name}'
|
52
|
+
MSG
|
53
|
+
end
|
54
|
+
end
|
38
55
|
end
|
39
56
|
end
|
40
57
|
end
|
@@ -6,18 +6,30 @@ module FactoryBot
|
|
6
6
|
@component = component
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
if ::Gem::Version.new(::RUBY_VERSION) >= ::Gem::Version.new("2.7")
|
10
|
+
class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
|
11
|
+
def method_missing(...) # rubocop:disable Style/MethodMissingSuper, Style/MissingRespondToMissing
|
12
|
+
@component.send(...)
|
13
|
+
end
|
14
|
+
|
15
|
+
def send(...)
|
16
|
+
__send__(...)
|
17
|
+
end
|
18
|
+
RUBY
|
19
|
+
else
|
20
|
+
def method_missing(name, *args, &block) # rubocop:disable Style/MethodMissingSuper, Style/MissingRespondToMissing
|
21
|
+
@component.send(name, *args, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def send(symbol, *args, &block)
|
25
|
+
__send__(symbol, *args, &block)
|
26
|
+
end
|
11
27
|
end
|
12
28
|
|
13
29
|
def respond_to_missing?(name, include_private = false)
|
14
30
|
@component.respond_to?(name, true) || super
|
15
31
|
end
|
16
32
|
|
17
|
-
def send(symbol, *args, &block)
|
18
|
-
__send__(symbol, *args, &block)
|
19
|
-
end
|
20
|
-
|
21
33
|
def self.const_missing(name)
|
22
34
|
::Object.const_get(name)
|
23
35
|
end
|
@@ -6,9 +6,16 @@ module FactoryBot
|
|
6
6
|
@invoked_methods = []
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
if ::Gem::Version.new(::RUBY_VERSION) >= ::Gem::Version.new("2.7")
|
10
|
+
def method_missing(name, *args, **kwargs, &block) # rubocop:disable Style/MissingRespondToMissing
|
11
|
+
@invoked_methods << name
|
12
|
+
super
|
13
|
+
end
|
14
|
+
else
|
15
|
+
def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondToMissing
|
16
|
+
@invoked_methods << name
|
17
|
+
super
|
18
|
+
end
|
12
19
|
end
|
13
20
|
|
14
21
|
def __invoked_methods__
|
@@ -33,13 +33,23 @@ module FactoryBot
|
|
33
33
|
@build_strategy.association(runner)
|
34
34
|
end
|
35
35
|
|
36
|
-
|
36
|
+
attr_accessor :instance
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
@instance.
|
41
|
-
|
42
|
-
|
38
|
+
if ::Gem::Version.new(::RUBY_VERSION) >= ::Gem::Version.new("2.7")
|
39
|
+
def method_missing(method_name, *args, **kwargs, &block) # rubocop:disable Style/MethodMissingSuper, Style/MissingRespondToMissing
|
40
|
+
if @instance.respond_to?(method_name)
|
41
|
+
@instance.send(method_name, *args, **kwargs, &block)
|
42
|
+
else
|
43
|
+
SyntaxRunner.new.send(method_name, *args, **kwargs, &block)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
else
|
47
|
+
def method_missing(method_name, *args, &block) # rubocop:disable Style/MethodMissingSuper, Style/MissingRespondToMissing
|
48
|
+
if @instance.respond_to?(method_name)
|
49
|
+
@instance.send(method_name, *args, &block)
|
50
|
+
else
|
51
|
+
SyntaxRunner.new.send(method_name, *args, &block)
|
52
|
+
end
|
43
53
|
end
|
44
54
|
end
|
45
55
|
|
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.0
|
4
|
+
version: 6.1.0
|
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: 2020-
|
12
|
+
date: 2020-07-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|