factory_bot 6.5.6 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5268f67c49f294395edabe86ef2bf7bdd3644db872328f0134d832b8cbfe5396
4
- data.tar.gz: 5e51702b4c819af99587ea2355b43b5770b228e1f0b81483b1bc9aa28806c630
3
+ metadata.gz: baec274935393ce2b200df3e96b5eea1bdc81955f17eee767c50e1c5538b565b
4
+ data.tar.gz: 662222ee8a0386a18262a5e726a2c6252a96ffc0364d354b1498ff62a333cb8d
5
5
  SHA512:
6
- metadata.gz: 80f08c8d63755aa32390aadfd2b5c653915a2d8920b58d56b89a6091c029a0194a007b5f6c99277f94c175a0c0c83463ce24d5849268ac8d3ab76c059379116d
7
- data.tar.gz: f092552d291c38644d02d77a73722b5966cc33397a1dcd06cb90164da65779c14f8a0352c77fd19890d30ccbe112d66a21c130865486da0b8059168e3f4a30e7
6
+ metadata.gz: 463b52e964995323501d4b1017687fb225519db1b9a073dd2289c152ccdbe14ff15eff09f8d602ec299b108a1c777f3682ad6fc4ce65c1fca298e5ba0e5786a4
7
+ data.tar.gz: 699311f5ef386653530ca631fe7f2824da7862073526abd686c18c3e2ba5431b4e67e7fab09e6a5cd1798f69f1a51122ae3ceeeacd0f382ff1f5093d3e97d60b
data/GETTING_STARTED.md CHANGED
@@ -2084,6 +2084,26 @@ config.after(:suite) do
2084
2084
  end
2085
2085
  ```
2086
2086
 
2087
+ You can also subscribe to `factory_bot.before_run_factory` to be notified
2088
+ before a factory is run. This is useful for building a factory call stack when
2089
+ debugging deeply nested associations:
2090
+
2091
+ ```ruby
2092
+ factory_call_stack = []
2093
+
2094
+ ActiveSupport::Notifications.subscribe("factory_bot.before_run_factory") do |name, start, finish, id, payload|
2095
+ factory_call_stack.push(payload[:name])
2096
+ end
2097
+
2098
+ ActiveSupport::Notifications.subscribe("factory_bot.run_factory") do |name, start, finish, id, payload|
2099
+ factory_call_stack.pop
2100
+ end
2101
+ ```
2102
+
2103
+ The payload for `factory_bot.before_run_factory` contains the same keys as
2104
+ `factory_bot.run_factory`: `:name`, `:strategy`, `:traits`, `:overrides`, and
2105
+ `:factory`.
2106
+
2087
2107
  Another example could involve tracking the attributes and traits that factories are compiled with. If you're using RSpec, you could add `before(:suite)` and `after(:suite)` blocks that subscribe to `factory_bot.compile_factory` notifications:
2088
2108
 
2089
2109
  ```ruby
data/NEWS.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # News
2
2
 
3
+ ## 6.6.0 (May 4, 2026)
4
+
5
+ * Feat: Added `factory_bot.before_run_factory` instrumentation event
6
+ * Add workflow to prepare a release PR by @neilvcarvalho in [#1816](https://github.com/thoughtbot/factory_bot/pull/1816)
7
+ * Add gem release workflow with GitHub release notes from changelog by @neilvcarvalho in [#1815](https://github.com/thoughtbot/factory_bot/pull/1815)
8
+ * Require MFA for gem pushes by @MatheusRich in [#1814](https://github.com/thoughtbot/factory_bot/pull/1814)
9
+ * Add `factory_bot.before_run_factory` instrumentation event by @hammadxcm in [#1795](https://github.com/thoughtbot/factory_bot/pull/1795)
10
+ * Remove CodeClimate badge from README by @hammadxcm in [#1794](https://github.com/thoughtbot/factory_bot/pull/1794)
11
+ * Update CI matrix by @berkos in [#1793](https://github.com/thoughtbot/factory_bot/pull/1793)
12
+ * Bump actions/checkout from 5 to 6 by @app/dependabot in [#1791](https://github.com/thoughtbot/factory_bot/pull/1791)
13
+ * Ensure linting transactions don't interfere with ActiveRecord lifecycle by @NikolasPilavakis in [#1790](https://github.com/thoughtbot/factory_bot/pull/1790)
14
+ * removes @doodlingdev by @DoodlingDev in [#1789](https://github.com/thoughtbot/factory_bot/pull/1789)
15
+ * DefinitionProxy#method_missing: Forward given block to #association by @grekko in [#1579](https://github.com/thoughtbot/factory_bot/pull/1579)
16
+
3
17
  ## 6.5.6 (October 22, 2025)
4
18
 
5
19
  * Fix: Enforce association override precedence over trait foreign keys by @JinOketani in [#1768](https://github.com/thoughtbot/factory_bot/pull/1768)
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # factory_bot
2
2
 
3
- [![Build Status][ci-image]][ci] [![Code Climate][grade-image]][grade] [![Gem Version][version-image]][version]
3
+ [![Build Status][ci-image]][ci] [![Gem Version][version-image]][version]
4
4
 
5
5
  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.
6
6
 
@@ -93,8 +93,6 @@ We are [available for hire][hire].
93
93
 
94
94
  [ci-image]: https://github.com/thoughtbot/factory_bot/actions/workflows/build.yml/badge.svg?branch=main
95
95
  [ci]: https://github.com/thoughtbot/factory_bot/actions?query=workflow%3ABuild+branch%3Amain
96
- [grade-image]: https://codeclimate.com/github/thoughtbot/factory_bot/badges/gpa.svg
97
- [grade]: https://codeclimate.com/github/thoughtbot/factory_bot
98
96
  [version-image]: https://badge.fury.io/rb/factory_bot.svg
99
97
  [version]: https://badge.fury.io/rb/factory_bot
100
98
  [hound-badge-image]: https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg
@@ -94,7 +94,7 @@ module FactoryBot
94
94
  if association_options.nil?
95
95
  __declare_attribute__(name, block)
96
96
  elsif __valid_association_options?(association_options)
97
- association(name, association_options)
97
+ association(name, association_options, &block)
98
98
  else
99
99
  raise NoMethodError.new(<<~MSG)
100
100
  undefined method '#{name}' in '#{@definition.name}' factory
@@ -25,6 +25,8 @@ module FactoryBot
25
25
  factory: factory
26
26
  }
27
27
 
28
+ ActiveSupport::Notifications.instrument("factory_bot.before_run_factory", instrumentation_payload)
29
+
28
30
  ActiveSupport::Notifications.instrument("factory_bot.run_factory", instrumentation_payload) do
29
31
  factory.run(runner_strategy, @overrides, &block)
30
32
  end
@@ -109,7 +109,7 @@ module FactoryBot
109
109
 
110
110
  def in_transaction
111
111
  if defined?(ActiveRecord::Base)
112
- ActiveRecord::Base.transaction do
112
+ ActiveRecord::Base.transaction(joinable: false) do
113
113
  yield
114
114
  raise ActiveRecord::Rollback
115
115
  end
@@ -1,3 +1,3 @@
1
1
  module FactoryBot
2
- VERSION = "6.5.6".freeze
2
+ VERSION = "6.6.0".freeze
3
3
  end
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.5.6
4
+ version: 6.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Clayton
@@ -252,6 +252,7 @@ licenses:
252
252
  - MIT
253
253
  metadata:
254
254
  changelog_uri: https://github.com/thoughtbot/factory_bot/blob/main/NEWS.md
255
+ rubygems_mfa_required: 'true'
255
256
  rdoc_options: []
256
257
  require_paths:
257
258
  - lib
@@ -266,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
267
  - !ruby/object:Gem::Version
267
268
  version: '0'
268
269
  requirements: []
269
- rubygems_version: 3.7.1
270
+ rubygems_version: 4.0.3
270
271
  specification_version: 4
271
272
  summary: factory_bot provides a framework and DSL for defining and using model instance
272
273
  factories.