factory_bot 6.4.4 → 6.6.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 +130 -87
- data/NEWS.md +465 -300
- data/README.md +22 -29
- data/lib/factory_bot/attribute_assigner.rb +75 -19
- data/lib/factory_bot/callbacks_observer.rb +19 -1
- data/lib/factory_bot/decorator.rb +5 -17
- data/lib/factory_bot/definition.rb +7 -2
- data/lib/factory_bot/definition_proxy.rb +19 -6
- data/lib/factory_bot/evaluator.rb +12 -7
- data/lib/factory_bot/factory.rb +22 -7
- data/lib/factory_bot/factory_runner.rb +2 -0
- data/lib/factory_bot/find_definitions.rb +2 -2
- data/lib/factory_bot/internal.rb +33 -0
- data/lib/factory_bot/linter.rb +13 -2
- data/lib/factory_bot/registry.rb +1 -1
- data/lib/factory_bot/sequence.rb +137 -10
- data/lib/factory_bot/strategy/build.rb +2 -0
- data/lib/factory_bot/strategy/create.rb +2 -0
- data/lib/factory_bot/strategy/stub.rb +4 -2
- data/lib/factory_bot/strategy.rb +15 -0
- data/lib/factory_bot/syntax/default.rb +2 -2
- data/lib/factory_bot/syntax/methods.rb +62 -15
- data/lib/factory_bot/trait.rb +11 -5
- data/lib/factory_bot/uri_manager.rb +63 -0
- data/lib/factory_bot/version.rb +1 -1
- data/lib/factory_bot.rb +35 -9
- metadata +24 -11
- data/lib/factory_bot/strategy_calculator.rb +0 -26
data/lib/factory_bot/sequence.rb
CHANGED
|
@@ -1,17 +1,33 @@
|
|
|
1
|
+
require "timeout"
|
|
2
|
+
|
|
1
3
|
module FactoryBot
|
|
2
4
|
# Sequences are defined using sequence within a FactoryBot.define block.
|
|
3
5
|
# Sequence values are generated using next.
|
|
4
6
|
# @api private
|
|
5
7
|
class Sequence
|
|
6
|
-
attr_reader :name
|
|
8
|
+
attr_reader :name, :uri_manager, :aliases
|
|
9
|
+
|
|
10
|
+
def self.find(*uri_parts)
|
|
11
|
+
if uri_parts.empty?
|
|
12
|
+
fail ArgumentError, "wrong number of arguments, expected 1+)"
|
|
13
|
+
else
|
|
14
|
+
find_by_uri FactoryBot::UriManager.build_uri(*uri_parts)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.find_by_uri(uri)
|
|
19
|
+
uri = uri.to_sym
|
|
20
|
+
FactoryBot::Internal.sequences.to_a.find { |seq| seq.has_uri?(uri) } ||
|
|
21
|
+
FactoryBot::Internal.inline_sequences.find { |seq| seq.has_uri?(uri) }
|
|
22
|
+
end
|
|
7
23
|
|
|
8
24
|
def initialize(name, *args, &proc)
|
|
25
|
+
options = args.extract_options!
|
|
9
26
|
@name = name
|
|
10
27
|
@proc = proc
|
|
11
|
-
|
|
12
|
-
|
|
28
|
+
@aliases = options.fetch(:aliases, []).map(&:to_sym)
|
|
29
|
+
@uri_manager = FactoryBot::UriManager.new(names, paths: options[:uri_paths])
|
|
13
30
|
@value = args.first || 1
|
|
14
|
-
@aliases = options.fetch(:aliases) { [] }
|
|
15
31
|
|
|
16
32
|
unless @value.respond_to?(:peek)
|
|
17
33
|
@value = EnumeratorAdapter.new(@value)
|
|
@@ -34,10 +50,40 @@ module FactoryBot
|
|
|
34
50
|
[@name] + @aliases
|
|
35
51
|
end
|
|
36
52
|
|
|
53
|
+
def has_name?(test_name)
|
|
54
|
+
names.include?(test_name.to_sym)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def has_uri?(uri)
|
|
58
|
+
uri_manager.include?(uri)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def for_factory?(test_factory_name)
|
|
62
|
+
FactoryBot::Internal.factory_by_name(factory_name).names.include?(test_factory_name.to_sym)
|
|
63
|
+
end
|
|
64
|
+
|
|
37
65
|
def rewind
|
|
38
66
|
@value.rewind
|
|
39
67
|
end
|
|
40
68
|
|
|
69
|
+
##
|
|
70
|
+
# If it's an Integer based sequence, set the new value directly,
|
|
71
|
+
# else rewind and seek from the beginning until a match is found.
|
|
72
|
+
#
|
|
73
|
+
def set_value(new_value)
|
|
74
|
+
if can_set_value_directly?(new_value)
|
|
75
|
+
@value.set_value(new_value)
|
|
76
|
+
elsif can_set_value_by_index?
|
|
77
|
+
set_value_by_index(new_value)
|
|
78
|
+
else
|
|
79
|
+
seek_value(new_value)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
protected
|
|
84
|
+
|
|
85
|
+
attr_reader :proc
|
|
86
|
+
|
|
41
87
|
private
|
|
42
88
|
|
|
43
89
|
def value
|
|
@@ -48,22 +94,103 @@ module FactoryBot
|
|
|
48
94
|
@value.next
|
|
49
95
|
end
|
|
50
96
|
|
|
97
|
+
def can_set_value_by_index?
|
|
98
|
+
@value.respond_to?(:find_index)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
##
|
|
102
|
+
# Set to the given value, or fail if not found
|
|
103
|
+
#
|
|
104
|
+
def set_value_by_index(value)
|
|
105
|
+
index = @value.find_index(value) || fail_value_not_found(value)
|
|
106
|
+
@value.rewind
|
|
107
|
+
index.times { @value.next }
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
##
|
|
111
|
+
# Rewind index and seek until the value is found or the max attempts
|
|
112
|
+
# have been tried. If not found, the sequence is rewound to its original value
|
|
113
|
+
#
|
|
114
|
+
def seek_value(value)
|
|
115
|
+
original_value = @value.peek
|
|
116
|
+
|
|
117
|
+
# rewind and search for the new value
|
|
118
|
+
@value.rewind
|
|
119
|
+
Timeout.timeout(FactoryBot.sequence_setting_timeout) do
|
|
120
|
+
loop do
|
|
121
|
+
return if @value.peek == value
|
|
122
|
+
increment_value
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# loop auto-recues a StopIteration error, so if we
|
|
126
|
+
# reached this point, re-raise it now
|
|
127
|
+
fail StopIteration
|
|
128
|
+
end
|
|
129
|
+
rescue Timeout::Error, StopIteration
|
|
130
|
+
reset_original_value(original_value)
|
|
131
|
+
fail_value_not_found(value)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def reset_original_value(original_value)
|
|
135
|
+
@value.rewind
|
|
136
|
+
|
|
137
|
+
until @value.peek == original_value
|
|
138
|
+
increment_value
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def can_set_value_directly?(value)
|
|
143
|
+
return false unless value.is_a?(Integer)
|
|
144
|
+
return false unless @value.is_a?(EnumeratorAdapter)
|
|
145
|
+
@value.integer_value?
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def fail_value_not_found(value)
|
|
149
|
+
fail ArgumentError, "Unable to find '#{value}' in the sequence."
|
|
150
|
+
end
|
|
151
|
+
|
|
51
152
|
class EnumeratorAdapter
|
|
52
|
-
def initialize(
|
|
53
|
-
@
|
|
54
|
-
@value = value
|
|
153
|
+
def initialize(initial_value)
|
|
154
|
+
@initial_value = initial_value
|
|
55
155
|
end
|
|
56
156
|
|
|
57
157
|
def peek
|
|
58
|
-
|
|
158
|
+
value
|
|
59
159
|
end
|
|
60
160
|
|
|
61
161
|
def next
|
|
62
|
-
@value =
|
|
162
|
+
@value = value.next
|
|
63
163
|
end
|
|
64
164
|
|
|
65
165
|
def rewind
|
|
66
|
-
@value =
|
|
166
|
+
@value = first_value
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def set_value(new_value)
|
|
170
|
+
if new_value >= first_value
|
|
171
|
+
@value = new_value
|
|
172
|
+
else
|
|
173
|
+
fail ArgumentError, "Value cannot be less than: #{@first_value}"
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def integer_value?
|
|
178
|
+
first_value.is_a?(Integer)
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
private
|
|
182
|
+
|
|
183
|
+
def first_value
|
|
184
|
+
@first_value ||= initial_value
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def value
|
|
188
|
+
@value ||= initial_value
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def initial_value
|
|
192
|
+
@value = @initial_value.respond_to?(:call) ? @initial_value.call : @initial_value
|
|
193
|
+
@first_value = @value
|
|
67
194
|
end
|
|
68
195
|
end
|
|
69
196
|
end
|
|
@@ -102,12 +102,14 @@ module FactoryBot
|
|
|
102
102
|
end
|
|
103
103
|
|
|
104
104
|
def set_timestamps(result_instance)
|
|
105
|
+
timestamp = Time.current
|
|
106
|
+
|
|
105
107
|
if missing_created_at?(result_instance)
|
|
106
|
-
result_instance.created_at =
|
|
108
|
+
result_instance.created_at = timestamp
|
|
107
109
|
end
|
|
108
110
|
|
|
109
111
|
if missing_updated_at?(result_instance)
|
|
110
|
-
result_instance.updated_at =
|
|
112
|
+
result_instance.updated_at = timestamp
|
|
111
113
|
end
|
|
112
114
|
end
|
|
113
115
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require "factory_bot/strategy/build"
|
|
2
|
+
require "factory_bot/strategy/create"
|
|
3
|
+
require "factory_bot/strategy/attributes_for"
|
|
4
|
+
require "factory_bot/strategy/stub"
|
|
5
|
+
require "factory_bot/strategy/null"
|
|
6
|
+
|
|
7
|
+
module FactoryBot
|
|
8
|
+
module Strategy
|
|
9
|
+
def self.lookup_strategy(name_or_object)
|
|
10
|
+
return name_or_object if name_or_object.is_a?(Class)
|
|
11
|
+
|
|
12
|
+
FactoryBot::Internal.strategy_by_name(name_or_object)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -83,52 +83,99 @@ module FactoryBot
|
|
|
83
83
|
# (see #strategy_method_pair)
|
|
84
84
|
# @return [Array<Hash>] pair of attribute hashes for the factory
|
|
85
85
|
|
|
86
|
-
# @!method strategy_method
|
|
86
|
+
# @!method strategy_method(name, traits_and_overrides, &block)
|
|
87
87
|
# @!visibility private
|
|
88
88
|
# @param [Symbol] name the name of the factory to build
|
|
89
89
|
# @param [Array<Symbol, Symbol, Hash>] traits_and_overrides splat args traits and a hash of overrides
|
|
90
90
|
# @param [Proc] block block to be executed
|
|
91
91
|
|
|
92
|
-
# @!method strategy_method_list
|
|
92
|
+
# @!method strategy_method_list(name, amount, traits_and_overrides, &block)
|
|
93
93
|
# @!visibility private
|
|
94
94
|
# @param [Symbol] name the name of the factory to execute
|
|
95
95
|
# @param [Integer] amount the number of instances to execute
|
|
96
96
|
# @param [Array<Symbol, Symbol, Hash>] traits_and_overrides splat args traits and a hash of overrides
|
|
97
97
|
# @param [Proc] block block to be executed
|
|
98
98
|
|
|
99
|
-
# @!method strategy_method_pair
|
|
99
|
+
# @!method strategy_method_pair(name, traits_and_overrides, &block)
|
|
100
100
|
# @!visibility private
|
|
101
101
|
# @param [Symbol] name the name of the factory to execute
|
|
102
102
|
# @param [Array<Symbol, Symbol, Hash>] traits_and_overrides splat args traits and a hash of overrides
|
|
103
103
|
# @param [Proc] block block to be executed
|
|
104
104
|
|
|
105
|
-
# Generates and returns the next value in a sequence.
|
|
105
|
+
# Generates and returns the next value in a global or factory sequence.
|
|
106
106
|
#
|
|
107
107
|
# Arguments:
|
|
108
|
-
#
|
|
109
|
-
# The
|
|
108
|
+
# context: (Array of Symbols)
|
|
109
|
+
# The definition context of the sequence, with the sequence name
|
|
110
|
+
# as the final entry
|
|
111
|
+
# scope: (object)(optional)
|
|
112
|
+
# The object the sequence should be evaluated within
|
|
110
113
|
#
|
|
111
114
|
# Returns:
|
|
112
115
|
# The next value in the sequence. (Object)
|
|
113
|
-
|
|
114
|
-
|
|
116
|
+
#
|
|
117
|
+
# Example:
|
|
118
|
+
# generate(:my_factory, :my_trair, :my_sequence)
|
|
119
|
+
#
|
|
120
|
+
def generate(*uri_parts, scope: nil)
|
|
121
|
+
uri = FactoryBot::UriManager.build_uri(uri_parts)
|
|
122
|
+
sequence = Sequence.find_by_uri(uri) ||
|
|
123
|
+
raise(KeyError,
|
|
124
|
+
"Sequence not registered: #{FactoryBot::UriManager.build_uri(uri_parts)}")
|
|
125
|
+
|
|
126
|
+
increment_sequence(sequence, scope: scope)
|
|
115
127
|
end
|
|
116
128
|
|
|
117
|
-
# Generates and returns the list of values in a sequence.
|
|
129
|
+
# Generates and returns the list of values in a global or factory sequence.
|
|
118
130
|
#
|
|
119
131
|
# Arguments:
|
|
120
|
-
#
|
|
121
|
-
# The
|
|
122
|
-
#
|
|
123
|
-
#
|
|
132
|
+
# uri_parts: (Array of Symbols)
|
|
133
|
+
# The definition context of the sequence, with the sequence name
|
|
134
|
+
# as the final entry
|
|
135
|
+
# scope: (object)(optional)
|
|
136
|
+
# The object the sequence should be evaluated within
|
|
124
137
|
#
|
|
125
138
|
# Returns:
|
|
126
139
|
# The next value in the sequence. (Object)
|
|
127
|
-
|
|
140
|
+
#
|
|
141
|
+
# Example:
|
|
142
|
+
# generate_list(:my_factory, :my_trair, :my_sequence, 5)
|
|
143
|
+
#
|
|
144
|
+
def generate_list(*uri_parts, count, scope: nil)
|
|
145
|
+
uri = FactoryBot::UriManager.build_uri(uri_parts)
|
|
146
|
+
sequence = Sequence.find_by_uri(uri) ||
|
|
147
|
+
raise(KeyError, "Sequence not registered: '#{uri}'")
|
|
148
|
+
|
|
128
149
|
(1..count).map do
|
|
129
|
-
|
|
150
|
+
increment_sequence(sequence, scope: scope)
|
|
130
151
|
end
|
|
131
152
|
end
|
|
153
|
+
|
|
154
|
+
# ======================================================================
|
|
155
|
+
# = PRIVATE
|
|
156
|
+
# ======================================================================
|
|
157
|
+
#
|
|
158
|
+
private
|
|
159
|
+
|
|
160
|
+
##
|
|
161
|
+
# Increments the given sequence and returns the value.
|
|
162
|
+
#
|
|
163
|
+
# Arguments:
|
|
164
|
+
# sequence:
|
|
165
|
+
# The sequence instance
|
|
166
|
+
# scope: (object)(optional)
|
|
167
|
+
# The object the sequence should be evaluated within
|
|
168
|
+
#
|
|
169
|
+
def increment_sequence(sequence, scope: nil)
|
|
170
|
+
value = sequence.next(scope)
|
|
171
|
+
|
|
172
|
+
raise if value.respond_to?(:start_with?) && value.start_with?("#<FactoryBot::Declaration")
|
|
173
|
+
|
|
174
|
+
value
|
|
175
|
+
rescue
|
|
176
|
+
raise ArgumentError, "Sequence '#{sequence.uri_manager.first}' failed to " \
|
|
177
|
+
"return a value. Perhaps it needs a scope to operate? (scope: <object>)"
|
|
178
|
+
end
|
|
132
179
|
end
|
|
133
180
|
end
|
|
134
181
|
end
|
data/lib/factory_bot/trait.rb
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
module FactoryBot
|
|
2
2
|
# @api private
|
|
3
3
|
class Trait
|
|
4
|
-
attr_reader :name, :definition
|
|
4
|
+
attr_reader :name, :uid, :definition
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
delegate :add_callback, :declare_attribute, :to_create, :define_trait, :constructor,
|
|
7
|
+
:callbacks, :attributes, :klass, :klass=, to: :@definition
|
|
8
|
+
|
|
9
|
+
def initialize(name, **options, &block)
|
|
7
10
|
@name = name.to_s
|
|
8
11
|
@block = block
|
|
9
|
-
@
|
|
12
|
+
@uri_manager = FactoryBot::UriManager.new(names, paths: options[:uri_paths])
|
|
13
|
+
|
|
14
|
+
@definition = Definition.new(@name, uri_manager: @uri_manager)
|
|
10
15
|
proxy = FactoryBot::DefinitionProxy.new(@definition)
|
|
11
16
|
|
|
12
17
|
if block
|
|
@@ -14,8 +19,9 @@ module FactoryBot
|
|
|
14
19
|
end
|
|
15
20
|
end
|
|
16
21
|
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
def clone
|
|
23
|
+
Trait.new(name, uri_paths: definition.uri_manager.paths, &block)
|
|
24
|
+
end
|
|
19
25
|
|
|
20
26
|
def names
|
|
21
27
|
[@name]
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
module FactoryBot
|
|
2
|
+
# @api private
|
|
3
|
+
class UriManager
|
|
4
|
+
attr_reader :endpoints, :paths, :uri_list
|
|
5
|
+
|
|
6
|
+
delegate :size, :any?, :empty?, :each?, :include?, :first, to: :@uri_list
|
|
7
|
+
delegate :build_uri, to: :class
|
|
8
|
+
|
|
9
|
+
# Concatenate the parts, sripping leading/following slashes
|
|
10
|
+
# and returning a Symbolized String or nil.
|
|
11
|
+
#
|
|
12
|
+
# Example:
|
|
13
|
+
# build_uri(:my_factory, :my_trait, :my_sequence)
|
|
14
|
+
# #=> :"myfactory/my_trait/my_sequence"
|
|
15
|
+
#
|
|
16
|
+
def self.build_uri(*parts)
|
|
17
|
+
return nil if parts.empty?
|
|
18
|
+
|
|
19
|
+
parts.join("/")
|
|
20
|
+
.sub(/\A\/+/, "")
|
|
21
|
+
.sub(/\/+\z/, "")
|
|
22
|
+
.tr(" ", "_")
|
|
23
|
+
.to_sym
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Configures the new UriManager
|
|
27
|
+
#
|
|
28
|
+
# Arguments:
|
|
29
|
+
# endpoints: (Array of Strings or Symbols)
|
|
30
|
+
# the objects endpoints.
|
|
31
|
+
#
|
|
32
|
+
# paths: (Array of Strings or Symbols)
|
|
33
|
+
# the parent URIs to prepend to each endpoint
|
|
34
|
+
#
|
|
35
|
+
def initialize(*endpoints, paths: [])
|
|
36
|
+
if endpoints.empty?
|
|
37
|
+
fail ArgumentError, "wrong number of arguments (given 0, expected 1+)"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
@uri_list = []
|
|
41
|
+
@endpoints = endpoints.flatten
|
|
42
|
+
@paths = Array(paths).flatten
|
|
43
|
+
|
|
44
|
+
build_uri_list
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def to_a
|
|
48
|
+
@uri_list.dup
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
def build_uri_list
|
|
54
|
+
@endpoints.each do |endpoint|
|
|
55
|
+
if @paths.any?
|
|
56
|
+
@paths.each { |path| @uri_list << build_uri(path, endpoint) }
|
|
57
|
+
else
|
|
58
|
+
@uri_list << build_uri(endpoint)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
data/lib/factory_bot/version.rb
CHANGED
data/lib/factory_bot.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require "set"
|
|
2
|
+
require "active_support"
|
|
2
3
|
require "active_support/core_ext/module/delegation"
|
|
3
4
|
require "active_support/core_ext/module/attribute_accessors"
|
|
4
5
|
require "active_support/deprecation"
|
|
@@ -10,12 +11,7 @@ require "factory_bot/configuration"
|
|
|
10
11
|
require "factory_bot/errors"
|
|
11
12
|
require "factory_bot/factory_runner"
|
|
12
13
|
require "factory_bot/strategy_syntax_method_registrar"
|
|
13
|
-
require "factory_bot/
|
|
14
|
-
require "factory_bot/strategy/build"
|
|
15
|
-
require "factory_bot/strategy/create"
|
|
16
|
-
require "factory_bot/strategy/attributes_for"
|
|
17
|
-
require "factory_bot/strategy/stub"
|
|
18
|
-
require "factory_bot/strategy/null"
|
|
14
|
+
require "factory_bot/strategy"
|
|
19
15
|
require "factory_bot/registry"
|
|
20
16
|
require "factory_bot/null_factory"
|
|
21
17
|
require "factory_bot/null_object"
|
|
@@ -45,6 +41,7 @@ require "factory_bot/decorator/attribute_hash"
|
|
|
45
41
|
require "factory_bot/decorator/disallows_duplicates_registry"
|
|
46
42
|
require "factory_bot/decorator/invocation_tracker"
|
|
47
43
|
require "factory_bot/decorator/new_constructor"
|
|
44
|
+
require "factory_bot/uri_manager"
|
|
48
45
|
require "factory_bot/linter"
|
|
49
46
|
require "factory_bot/version"
|
|
50
47
|
|
|
@@ -57,6 +54,9 @@ module FactoryBot
|
|
|
57
54
|
mattr_accessor :automatically_define_enum_traits, instance_accessor: false
|
|
58
55
|
self.automatically_define_enum_traits = true
|
|
59
56
|
|
|
57
|
+
mattr_accessor :sequence_setting_timeout, instance_accessor: false
|
|
58
|
+
self.sequence_setting_timeout = 3
|
|
59
|
+
|
|
60
60
|
# Look for errors in factories and (optionally) their traits.
|
|
61
61
|
# Parameters:
|
|
62
62
|
# factories - which factories to lint; omit for all factories
|
|
@@ -72,17 +72,43 @@ module FactoryBot
|
|
|
72
72
|
|
|
73
73
|
# Set the starting value for ids when using the build_stubbed strategy
|
|
74
74
|
#
|
|
75
|
-
#
|
|
76
|
-
# * starting_id +Integer+
|
|
77
|
-
# The new starting id value.
|
|
75
|
+
# @param [Integer] starting_id The new starting id value.
|
|
78
76
|
def self.build_stubbed_starting_id=(starting_id)
|
|
79
77
|
Strategy::Stub.next_id = starting_id - 1
|
|
80
78
|
end
|
|
81
79
|
|
|
82
80
|
class << self
|
|
81
|
+
# @!method rewind_sequence(*uri_parts)
|
|
82
|
+
# Rewind an individual global or inline sequence.
|
|
83
|
+
#
|
|
84
|
+
# @param [Array<Symbol>, String] uri_parts The components of the sequence URI.
|
|
85
|
+
#
|
|
86
|
+
# @example Rewinding a sequence by its URI parts
|
|
87
|
+
# rewind_sequence(:factory_name, :trait_name, :sequence_name)
|
|
88
|
+
#
|
|
89
|
+
# @example Rewinding a sequence by its URI string
|
|
90
|
+
# rewind_sequence("factory_name/trait_name/sequence_name")
|
|
91
|
+
#
|
|
92
|
+
# @!method set_sequence(*uri_parts, value)
|
|
93
|
+
# Set the sequence to a specific value, providing the new value is within
|
|
94
|
+
# the sequence set.
|
|
95
|
+
#
|
|
96
|
+
# @param [Array<Symbol>, String] uri_parts The components of the sequence URI.
|
|
97
|
+
# @param [Object] value The new value for the sequence. This must be a value that is
|
|
98
|
+
# within the sequence definition. For example, you cannot set
|
|
99
|
+
# a String sequence to an Integer value.
|
|
100
|
+
#
|
|
101
|
+
# @example
|
|
102
|
+
# set_sequence(:factory_name, :trait_name, :sequence_name, 450)
|
|
103
|
+
# @example
|
|
104
|
+
# set_sequence([:factory_name, :trait_name, :sequence_name], 450)
|
|
105
|
+
# @example
|
|
106
|
+
# set_sequence("factory_name/trait_name/sequence_name", 450)
|
|
83
107
|
delegate :factories,
|
|
84
108
|
:register_strategy,
|
|
85
109
|
:rewind_sequences,
|
|
110
|
+
:rewind_sequence,
|
|
111
|
+
:set_sequence,
|
|
86
112
|
:strategy_by_name,
|
|
87
113
|
to: Internal
|
|
88
114
|
end
|
metadata
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: factory_bot
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 6.
|
|
4
|
+
version: 6.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Josh Clayton
|
|
8
8
|
- Joe Ferris
|
|
9
|
-
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
|
15
14
|
name: activesupport
|
|
@@ -17,14 +16,14 @@ dependencies:
|
|
|
17
16
|
requirements:
|
|
18
17
|
- - ">="
|
|
19
18
|
- !ruby/object:Gem::Version
|
|
20
|
-
version:
|
|
19
|
+
version: 6.1.0
|
|
21
20
|
type: :runtime
|
|
22
21
|
prerelease: false
|
|
23
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
24
23
|
requirements:
|
|
25
24
|
- - ">="
|
|
26
25
|
- !ruby/object:Gem::Version
|
|
27
|
-
version:
|
|
26
|
+
version: 6.1.0
|
|
28
27
|
- !ruby/object:Gem::Dependency
|
|
29
28
|
name: activerecord
|
|
30
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -68,7 +67,21 @@ dependencies:
|
|
|
68
67
|
- !ruby/object:Gem::Version
|
|
69
68
|
version: '0'
|
|
70
69
|
- !ruby/object:Gem::Dependency
|
|
71
|
-
name:
|
|
70
|
+
name: mutex_m
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: ostruct
|
|
72
85
|
requirement: !ruby/object:Gem::Requirement
|
|
73
86
|
requirements:
|
|
74
87
|
- - ">="
|
|
@@ -220,25 +233,26 @@ files:
|
|
|
220
233
|
- lib/factory_bot/registry.rb
|
|
221
234
|
- lib/factory_bot/reload.rb
|
|
222
235
|
- lib/factory_bot/sequence.rb
|
|
236
|
+
- lib/factory_bot/strategy.rb
|
|
223
237
|
- lib/factory_bot/strategy/attributes_for.rb
|
|
224
238
|
- lib/factory_bot/strategy/build.rb
|
|
225
239
|
- lib/factory_bot/strategy/create.rb
|
|
226
240
|
- lib/factory_bot/strategy/null.rb
|
|
227
241
|
- lib/factory_bot/strategy/stub.rb
|
|
228
|
-
- lib/factory_bot/strategy_calculator.rb
|
|
229
242
|
- lib/factory_bot/strategy_syntax_method_registrar.rb
|
|
230
243
|
- lib/factory_bot/syntax.rb
|
|
231
244
|
- lib/factory_bot/syntax/default.rb
|
|
232
245
|
- lib/factory_bot/syntax/methods.rb
|
|
233
246
|
- lib/factory_bot/syntax_runner.rb
|
|
234
247
|
- lib/factory_bot/trait.rb
|
|
248
|
+
- lib/factory_bot/uri_manager.rb
|
|
235
249
|
- lib/factory_bot/version.rb
|
|
236
250
|
homepage: https://github.com/thoughtbot/factory_bot
|
|
237
251
|
licenses:
|
|
238
252
|
- MIT
|
|
239
253
|
metadata:
|
|
240
254
|
changelog_uri: https://github.com/thoughtbot/factory_bot/blob/main/NEWS.md
|
|
241
|
-
|
|
255
|
+
rubygems_mfa_required: 'true'
|
|
242
256
|
rdoc_options: []
|
|
243
257
|
require_paths:
|
|
244
258
|
- lib
|
|
@@ -246,15 +260,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
246
260
|
requirements:
|
|
247
261
|
- - ">="
|
|
248
262
|
- !ruby/object:Gem::Version
|
|
249
|
-
version:
|
|
263
|
+
version: 3.0.0
|
|
250
264
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
251
265
|
requirements:
|
|
252
266
|
- - ">="
|
|
253
267
|
- !ruby/object:Gem::Version
|
|
254
268
|
version: '0'
|
|
255
269
|
requirements: []
|
|
256
|
-
rubygems_version:
|
|
257
|
-
signing_key:
|
|
270
|
+
rubygems_version: 4.0.3
|
|
258
271
|
specification_version: 4
|
|
259
272
|
summary: factory_bot provides a framework and DSL for defining and using model instance
|
|
260
273
|
factories.
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
module FactoryBot
|
|
2
|
-
# @api private
|
|
3
|
-
class StrategyCalculator
|
|
4
|
-
def initialize(name_or_object)
|
|
5
|
-
@name_or_object = name_or_object
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def strategy
|
|
9
|
-
if strategy_is_object?
|
|
10
|
-
@name_or_object
|
|
11
|
-
else
|
|
12
|
-
strategy_name_to_object
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
def strategy_is_object?
|
|
19
|
-
@name_or_object.is_a?(Class)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def strategy_name_to_object
|
|
23
|
-
FactoryBot::Internal.strategy_by_name(@name_or_object)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|