factory_bot 6.5.1 → 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: 71c90d06521a4d6e1bbd613bdc1494919b2acde4117153524a11d8fbea53301c
4
- data.tar.gz: 7e19bf127cf040c9f59fea525894019358e0502de695cf5957ac5eb91280e1d1
3
+ metadata.gz: 9e569214d220256c1f88d64718013ed8ac59c318233e144623ea660dfd28bcca
4
+ data.tar.gz: a8156b55e0e3f82f63f851bd979310a20ec5078f0beda6167b4e733a11f8bd85
5
5
  SHA512:
6
- metadata.gz: ff1b56b976b423b91d8f633fdb0d1ed2d13b5c75665547adbb4d6f1d90b15aff35459dcb2fd6479e6dccdfd98ce3a9bd2a13b1ced002704fb84c39e2d5ebb3f3
7
- data.tar.gz: dfc7713d8511e0723ab41da77257c901ca2d5abdf04b21b8f81332bd4f6e6568d403a68fc7831529ab8cbed531c25bc068458ee28fb2b1d7f0b7ebeafda02a3a
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,9 +1,20 @@
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
+
3
14
  ## 6.5.1 (January 31, 2025)
4
15
 
5
16
  * Changed: execute linting tests within ActiveRecord transactions when available (Sean Doyle)
6
- * Fix: Random test failure when tracking compilation time (CodeMeinster)
17
+ * Fix: Random test failure when tracking compilation time (CodeMeister)
7
18
  * Fix: Bump the minimum required activesupport version to 6.1 (Earlopain)
8
19
  * Internal: Update development dependencies (Neil Carvalho)
9
20
 
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
@@ -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
@@ -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
 
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module FactoryBot
2
- VERSION = "6.5.1".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.1
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: 2025-01-31 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
@@ -252,7 +251,6 @@ licenses:
252
251
  - MIT
253
252
  metadata:
254
253
  changelog_uri: https://github.com/thoughtbot/factory_bot/blob/main/NEWS.md
255
- post_install_message:
256
254
  rdoc_options: []
257
255
  require_paths:
258
256
  - lib
@@ -267,8 +265,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
267
265
  - !ruby/object:Gem::Version
268
266
  version: '0'
269
267
  requirements: []
270
- rubygems_version: 3.5.22
271
- signing_key:
268
+ rubygems_version: 3.6.7
272
269
  specification_version: 4
273
270
  summary: factory_bot provides a framework and DSL for defining and using model instance
274
271
  factories.