factory_bot 6.5.0 → 6.5.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44611a193b219b270cd43b7a8587718ff190b3c63162c17f02288afc362a37e9
4
- data.tar.gz: a1a3d3ce45776e1d8d228f113af1c101a64090fde8f19a46321d40bec3df0e48
3
+ metadata.gz: 9e569214d220256c1f88d64718013ed8ac59c318233e144623ea660dfd28bcca
4
+ data.tar.gz: a8156b55e0e3f82f63f851bd979310a20ec5078f0beda6167b4e733a11f8bd85
5
5
  SHA512:
6
- metadata.gz: 2e65a906e197e8e9f268440ba3ffbc0a717b211420419f0ce0f9ff0a5b5e90413d4a76b829f45fe4746541aae91869afdee8975b3171841c4655d6627979aa2b
7
- data.tar.gz: 400e0cb1dab0994f26a46674a5d7f0cb6dc89a95815faab5da8838f732c9e6ac92fac6af17270ce4aaba3f84cdcbfcf96361021a7671a37e33a9d27e77cb652b
6
+ metadata.gz: ebf041f57ee689eac93ec49a9ee1b3cf8ed9173f3f96893ff6475bd6e1c604a35c87b2a89da9ad7d883b4e8011292f75c122514b6290064521b587cc1e133fef
7
+ data.tar.gz: 80045a8952d9475cf73f4291090cb9cbba04e0d3471bc453c50acc3deb8a4ea4824fcecf3e4d0759186c903fdd26643591fc7c0eaa147940bbd47231b63a475b
data/GETTING_STARTED.md CHANGED
@@ -255,10 +255,12 @@ Factories can be defined anywhere, but will be automatically loaded after
255
255
  calling `FactoryBot.find_definitions` if factories are defined in files at the
256
256
  following locations:
257
257
 
258
+ factories.rb
259
+ factories/**/*.rb
258
260
  test/factories.rb
261
+ test/factories/**/*.rb
259
262
  spec/factories.rb
260
- test/factories/*.rb
261
- spec/factories/*.rb
263
+ spec/factories/**/*.rb
262
264
 
263
265
  ### Static Attributes
264
266
 
data/NEWS.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # News
2
2
 
3
+ ## 6.5.2 (May 30, 2025)
4
+
5
+ * Changed: Updated "verbose linting" test to allow for backtrace changes in Ruby 3.4 (CodeMeister)
6
+ * Fix: Set the same timestamps for `created_at` and `updated_at` on `build_stubbed` (Kim Emmanuel)
7
+ * Fix: Refactored sequences to ensure cloned traits use parent sequences. (CodeMeister)
8
+ * Docs: Fix definition_file_paths comment (Milo Winningham)
9
+ * Docs: Add ruby-lsp extensions to Useful Tools in README.md (johansenja)
10
+ * Docs: Fix docs about definition file paths (Ryo Nakamura)
11
+ * Docs: Update has_many-associations.md to mention that traits can use inline associations (Matthew Zagaja)
12
+ * Docs: Fix "Transitioning from Factory Girl" guide link (Neil Carvalho)
13
+
14
+ ## 6.5.1 (January 31, 2025)
15
+
16
+ * Changed: execute linting tests within ActiveRecord transactions when available (Sean Doyle)
17
+ * Fix: Random test failure when tracking compilation time (CodeMeister)
18
+ * Fix: Bump the minimum required activesupport version to 6.1 (Earlopain)
19
+ * Internal: Update development dependencies (Neil Carvalho)
20
+
3
21
  ## 6.5.0 (September 6, 2024)
4
22
 
5
23
  * fix: issue 1621 broken links in ref/factory.md by @elasticspoon in https://github.com/thoughtbot/factory_bot/pull/1623
data/README.md CHANGED
@@ -10,7 +10,7 @@ _[Interested in the history of the project name?][NAME]_
10
10
 
11
11
  ### Transitioning from factory\_girl?
12
12
 
13
- Check out the [guide](https://github.com/thoughtbot/factory_bot/blob/4-9-0-stable/UPGRADE_FROM_FACTORY_GIRL.md).
13
+ Check out the [guide](https://github.com/thoughtbot/factory_bot/blob/v4.9.0/UPGRADE_FROM_FACTORY_GIRL.md).
14
14
 
15
15
 
16
16
  Documentation
@@ -62,6 +62,7 @@ Useful Tools
62
62
  ------------
63
63
 
64
64
  * [FactoryTrace](https://github.com/djezzzl/factory_trace) - helps to find unused factories and traits.
65
+ * [ruby-lsp-factory_bot](https://github.com/donny741/ruby-lsp-factory_bot) / [ruby-lsp-rails-factory-bot](https://github.com/johansenja/ruby-lsp-rails-factory-bot) - integration with [ruby-lsp](https://github.com/Shopify/ruby-lsp) to provide intellisense
65
66
 
66
67
  Contributing
67
68
  ------------
@@ -96,7 +97,6 @@ We are [available for hire][hire].
96
97
  [community]: https://thoughtbot.com/community?utm_source=github
97
98
  [hire]: https://thoughtbot.com/hire-us?utm_source=github
98
99
 
99
-
100
100
  <!-- END /templates/footer.md -->
101
101
 
102
102
  [ci-image]: https://github.com/thoughtbot/factory_bot/actions/workflows/build.yml/badge.svg?branch=main
@@ -95,6 +95,10 @@ module FactoryBot
95
95
  @defined_traits.add(trait)
96
96
  end
97
97
 
98
+ def defined_traits_names
99
+ @defined_traits.map(&:name)
100
+ end
101
+
98
102
  def register_enum(enum)
99
103
  @registered_enums << enum
100
104
  end
@@ -120,9 +120,9 @@ module FactoryBot
120
120
  #
121
121
  # Except that no globally available sequence will be defined.
122
122
  def sequence(name, ...)
123
- sequence = Sequence.new(name, ...)
124
- FactoryBot::Internal.register_inline_sequence(sequence)
125
- add_attribute(name) { increment_sequence(sequence) }
123
+ new_sequence = Sequence.new(name, ...)
124
+ registered_sequence = __fetch_or_register_sequence(new_sequence)
125
+ add_attribute(name) { increment_sequence(registered_sequence) }
126
126
  end
127
127
 
128
128
  # Adds an attribute that builds an association. The associated instance will
@@ -252,5 +252,19 @@ module FactoryBot
252
252
  def __valid_association_options?(options)
253
253
  options.respond_to?(:has_key?) && options.has_key?(:factory)
254
254
  end
255
+
256
+ ##
257
+ # If the sequence has already been registered by a parent, return that one,
258
+ # otherwise register and return the given sequence
259
+ #
260
+ def __fetch_or_register_sequence(sequence)
261
+ FactoryBot::Internal.inline_sequences
262
+ .each do |registered_sequence|
263
+ return registered_sequence if registered_sequence.matches?(sequence)
264
+ end
265
+
266
+ FactoryBot::Internal.register_inline_sequence(sequence)
267
+ sequence
268
+ end
255
269
  end
256
270
  end
@@ -17,7 +17,8 @@ module FactoryBot
17
17
  end
18
18
 
19
19
  delegate :add_callback, :declare_attribute, :to_create, :define_trait, :constructor,
20
- :defined_traits, :inherit_traits, :append_traits, to: :@definition
20
+ :defined_traits, :defined_traits_names, :inherit_traits, :append_traits,
21
+ to: :@definition
21
22
 
22
23
  def build_class
23
24
  @build_class ||= if class_name.is_a? Class
@@ -85,7 +86,7 @@ module FactoryBot
85
86
  def compile
86
87
  unless @compiled
87
88
  parent.compile
88
- parent.defined_traits.each { |trait| define_trait(trait) }
89
+ inherit_parent_traits
89
90
  @definition.compile(build_class)
90
91
  build_hierarchy
91
92
  @compiled = true
@@ -153,6 +154,13 @@ module FactoryBot
153
154
  end
154
155
  end
155
156
 
157
+ def inherit_parent_traits
158
+ parent.defined_traits.each do |trait|
159
+ next if defined_traits_names.include?(trait.name)
160
+ define_trait(trait.clone)
161
+ end
162
+ end
163
+
156
164
  def initialize_copy(source)
157
165
  super
158
166
  @definition = @definition.clone
@@ -2,8 +2,8 @@ module FactoryBot
2
2
  class << self
3
3
  # An Array of strings specifying locations that should be searched for
4
4
  # factory definitions. By default, factory_bot will attempt to require
5
- # "factories", "test/factories" and "spec/factories". Only the first
6
- # existing file will be loaded.
5
+ # "factories.rb", "factories/**/*.rb", "test/factories.rb",
6
+ # "test/factories/**.rb", "spec/factories.rb", and "spec/factories/**.rb".
7
7
  attr_accessor :definition_file_paths
8
8
  end
9
9
 
@@ -70,7 +70,7 @@ module FactoryBot
70
70
  def lint_factory(factory)
71
71
  result = []
72
72
  begin
73
- FactoryBot.public_send(factory_strategy, factory.name)
73
+ in_transaction { FactoryBot.public_send(factory_strategy, factory.name) }
74
74
  rescue => e
75
75
  result |= [FactoryError.new(e, factory)]
76
76
  end
@@ -80,7 +80,7 @@ module FactoryBot
80
80
  def lint_traits(factory)
81
81
  result = []
82
82
  factory.definition.defined_traits.map(&:name).each do |trait_name|
83
- FactoryBot.public_send(factory_strategy, factory.name, trait_name)
83
+ in_transaction { FactoryBot.public_send(factory_strategy, factory.name, trait_name) }
84
84
  rescue => e
85
85
  result |= [FactoryTraitError.new(e, factory, trait_name)]
86
86
  end
@@ -106,5 +106,16 @@ module FactoryBot
106
106
  :message
107
107
  end
108
108
  end
109
+
110
+ def in_transaction
111
+ if defined?(ActiveRecord::Base)
112
+ ActiveRecord::Base.transaction do
113
+ yield
114
+ raise ActiveRecord::Rollback
115
+ end
116
+ else
117
+ yield
118
+ end
119
+ end
109
120
  end
110
121
  end
@@ -38,6 +38,17 @@ module FactoryBot
38
38
  @value.rewind
39
39
  end
40
40
 
41
+ def matches?(test_sequence)
42
+ return false unless name == test_sequence.name
43
+ return false unless proc.source_location == test_sequence.proc.source_location
44
+
45
+ proc.parameters == test_sequence.proc.parameters
46
+ end
47
+
48
+ protected
49
+
50
+ attr_reader :proc
51
+
41
52
  private
42
53
 
43
54
  def value
@@ -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 = Time.current
108
+ result_instance.created_at = timestamp
107
109
  end
108
110
 
109
111
  if missing_updated_at?(result_instance)
110
- result_instance.updated_at = Time.current
112
+ result_instance.updated_at = timestamp
111
113
  end
112
114
  end
113
115
 
@@ -14,6 +14,10 @@ module FactoryBot
14
14
  end
15
15
  end
16
16
 
17
+ def clone
18
+ Trait.new(name, &block)
19
+ end
20
+
17
21
  delegate :add_callback, :declare_attribute, :to_create, :define_trait, :constructor,
18
22
  :callbacks, :attributes, :klass, :klass=, to: :@definition
19
23
 
@@ -1,3 +1,3 @@
1
1
  module FactoryBot
2
- VERSION = "6.5.0".freeze
2
+ VERSION = "6.5.2".freeze
3
3
  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.0
4
+ version: 6.5.2
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: 2024-09-06 00:00:00.000000000 Z
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: 5.0.0
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: 5.0.0
26
+ version: 6.1.0
28
27
  - !ruby/object:Gem::Dependency
29
28
  name: activerecord
30
29
  requirement: !ruby/object:Gem::Requirement
@@ -81,6 +80,20 @@ dependencies:
81
80
  - - ">="
82
81
  - !ruby/object:Gem::Version
83
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mutex_m
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
84
97
  - !ruby/object:Gem::Dependency
85
98
  name: rake
86
99
  requirement: !ruby/object:Gem::Requirement
@@ -238,7 +251,6 @@ licenses:
238
251
  - MIT
239
252
  metadata:
240
253
  changelog_uri: https://github.com/thoughtbot/factory_bot/blob/main/NEWS.md
241
- post_install_message:
242
254
  rdoc_options: []
243
255
  require_paths:
244
256
  - lib
@@ -253,8 +265,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
253
265
  - !ruby/object:Gem::Version
254
266
  version: '0'
255
267
  requirements: []
256
- rubygems_version: 3.5.18
257
- signing_key:
268
+ rubygems_version: 3.6.7
258
269
  specification_version: 4
259
270
  summary: factory_bot provides a framework and DSL for defining and using model instance
260
271
  factories.