factory_bot 6.5.1 → 6.5.5
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 +24 -2
- data/NEWS.md +421 -323
- data/README.md +2 -2
- data/lib/factory_bot/attribute_assigner.rb +25 -8
- data/lib/factory_bot/callbacks_observer.rb +19 -1
- data/lib/factory_bot/definition.rb +3 -2
- data/lib/factory_bot/definition_proxy.rb +19 -6
- data/lib/factory_bot/evaluator.rb +9 -3
- data/lib/factory_bot/factory.rb +8 -2
- data/lib/factory_bot/find_definitions.rb +2 -2
- data/lib/factory_bot/internal.rb +33 -0
- 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/syntax/methods.rb +59 -12
- data/lib/factory_bot/trait.rb +9 -7
- data/lib/factory_bot/uri_manager.rb +63 -0
- data/lib/factory_bot/version.rb +1 -1
- data/lib/factory_bot.rb +33 -3
- metadata +4 -6
@@ -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
@@ -46,6 +46,7 @@ require "factory_bot/decorator/attribute_hash"
|
|
46
46
|
require "factory_bot/decorator/disallows_duplicates_registry"
|
47
47
|
require "factory_bot/decorator/invocation_tracker"
|
48
48
|
require "factory_bot/decorator/new_constructor"
|
49
|
+
require "factory_bot/uri_manager"
|
49
50
|
require "factory_bot/linter"
|
50
51
|
require "factory_bot/version"
|
51
52
|
|
@@ -58,6 +59,9 @@ module FactoryBot
|
|
58
59
|
mattr_accessor :automatically_define_enum_traits, instance_accessor: false
|
59
60
|
self.automatically_define_enum_traits = true
|
60
61
|
|
62
|
+
mattr_accessor :sequence_setting_timeout, instance_accessor: false
|
63
|
+
self.sequence_setting_timeout = 3
|
64
|
+
|
61
65
|
# Look for errors in factories and (optionally) their traits.
|
62
66
|
# Parameters:
|
63
67
|
# factories - which factories to lint; omit for all factories
|
@@ -73,17 +77,43 @@ module FactoryBot
|
|
73
77
|
|
74
78
|
# Set the starting value for ids when using the build_stubbed strategy
|
75
79
|
#
|
76
|
-
#
|
77
|
-
# * starting_id +Integer+
|
78
|
-
# The new starting id value.
|
80
|
+
# @param [Integer] starting_id The new starting id value.
|
79
81
|
def self.build_stubbed_starting_id=(starting_id)
|
80
82
|
Strategy::Stub.next_id = starting_id - 1
|
81
83
|
end
|
82
84
|
|
83
85
|
class << self
|
86
|
+
# @!method rewind_sequence(*uri_parts)
|
87
|
+
# Rewind an individual global or inline sequence.
|
88
|
+
#
|
89
|
+
# @param [Array<Symbol>, String] uri_parts The components of the sequence URI.
|
90
|
+
#
|
91
|
+
# @example Rewinding a sequence by its URI parts
|
92
|
+
# rewind_sequence(:factory_name, :trait_name, :sequence_name)
|
93
|
+
#
|
94
|
+
# @example Rewinding a sequence by its URI string
|
95
|
+
# rewind_sequence("factory_name/trait_name/sequence_name")
|
96
|
+
#
|
97
|
+
# @!method set_sequence(*uri_parts, value)
|
98
|
+
# Set the sequence to a specific value, providing the new value is within
|
99
|
+
# the sequence set.
|
100
|
+
#
|
101
|
+
# @param [Array<Symbol>, String] uri_parts The components of the sequence URI.
|
102
|
+
# @param [Object] value The new value for the sequence. This must be a value that is
|
103
|
+
# within the sequence definition. For example, you cannot set
|
104
|
+
# a String sequence to an Integer value.
|
105
|
+
#
|
106
|
+
# @example
|
107
|
+
# set_sequence(:factory_name, :trait_name, :sequence_name, 450)
|
108
|
+
# @example
|
109
|
+
# set_sequence([:factory_name, :trait_name, :sequence_name], 450)
|
110
|
+
# @example
|
111
|
+
# set_sequence("factory_name/trait_name/sequence_name", 450)
|
84
112
|
delegate :factories,
|
85
113
|
:register_strategy,
|
86
114
|
:rewind_sequences,
|
115
|
+
:rewind_sequence,
|
116
|
+
:set_sequence,
|
87
117
|
:strategy_by_name,
|
88
118
|
to: Internal
|
89
119
|
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.5.
|
4
|
+
version: 6.5.5
|
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: 2025-
|
11
|
+
date: 2025-08-15 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activesupport
|
@@ -246,13 +245,13 @@ files:
|
|
246
245
|
- lib/factory_bot/syntax/methods.rb
|
247
246
|
- lib/factory_bot/syntax_runner.rb
|
248
247
|
- lib/factory_bot/trait.rb
|
248
|
+
- lib/factory_bot/uri_manager.rb
|
249
249
|
- lib/factory_bot/version.rb
|
250
250
|
homepage: https://github.com/thoughtbot/factory_bot
|
251
251
|
licenses:
|
252
252
|
- MIT
|
253
253
|
metadata:
|
254
254
|
changelog_uri: https://github.com/thoughtbot/factory_bot/blob/main/NEWS.md
|
255
|
-
post_install_message:
|
256
255
|
rdoc_options: []
|
257
256
|
require_paths:
|
258
257
|
- lib
|
@@ -267,8 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
267
266
|
- !ruby/object:Gem::Version
|
268
267
|
version: '0'
|
269
268
|
requirements: []
|
270
|
-
rubygems_version: 3.
|
271
|
-
signing_key:
|
269
|
+
rubygems_version: 3.6.2
|
272
270
|
specification_version: 4
|
273
271
|
summary: factory_bot provides a framework and DSL for defining and using model instance
|
274
272
|
factories.
|