factory_bot 6.5.0 → 6.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44611a193b219b270cd43b7a8587718ff190b3c63162c17f02288afc362a37e9
4
- data.tar.gz: a1a3d3ce45776e1d8d228f113af1c101a64090fde8f19a46321d40bec3df0e48
3
+ metadata.gz: 71c90d06521a4d6e1bbd613bdc1494919b2acde4117153524a11d8fbea53301c
4
+ data.tar.gz: 7e19bf127cf040c9f59fea525894019358e0502de695cf5957ac5eb91280e1d1
5
5
  SHA512:
6
- metadata.gz: 2e65a906e197e8e9f268440ba3ffbc0a717b211420419f0ce0f9ff0a5b5e90413d4a76b829f45fe4746541aae91869afdee8975b3171841c4655d6627979aa2b
7
- data.tar.gz: 400e0cb1dab0994f26a46674a5d7f0cb6dc89a95815faab5da8838f732c9e6ac92fac6af17270ce4aaba3f84cdcbfcf96361021a7671a37e33a9d27e77cb652b
6
+ metadata.gz: ff1b56b976b423b91d8f633fdb0d1ed2d13b5c75665547adbb4d6f1d90b15aff35459dcb2fd6479e6dccdfd98ce3a9bd2a13b1ced002704fb84c39e2d5ebb3f3
7
+ data.tar.gz: dfc7713d8511e0723ab41da77257c901ca2d5abdf04b21b8f81332bd4f6e6568d403a68fc7831529ab8cbed531c25bc068458ee28fb2b1d7f0b7ebeafda02a3a
data/NEWS.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # News
2
2
 
3
+ ## 6.5.1 (January 31, 2025)
4
+
5
+ * Changed: execute linting tests within ActiveRecord transactions when available (Sean Doyle)
6
+ * Fix: Random test failure when tracking compilation time (CodeMeinster)
7
+ * Fix: Bump the minimum required activesupport version to 6.1 (Earlopain)
8
+ * Internal: Update development dependencies (Neil Carvalho)
9
+
3
10
  ## 6.5.0 (September 6, 2024)
4
11
 
5
12
  * fix: issue 1621 broken links in ref/factory.md by @elasticspoon in https://github.com/thoughtbot/factory_bot/pull/1623
@@ -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
@@ -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
@@ -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
@@ -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.1".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.0
4
+ version: 6.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Clayton
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-09-06 00:00:00.000000000 Z
12
+ date: 2025-01-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 5.0.0
20
+ version: 6.1.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 5.0.0
27
+ version: 6.1.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: activerecord
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -81,6 +81,20 @@ dependencies:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: mutex_m
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
84
98
  - !ruby/object:Gem::Dependency
85
99
  name: rake
86
100
  requirement: !ruby/object:Gem::Requirement
@@ -253,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
253
267
  - !ruby/object:Gem::Version
254
268
  version: '0'
255
269
  requirements: []
256
- rubygems_version: 3.5.18
270
+ rubygems_version: 3.5.22
257
271
  signing_key:
258
272
  specification_version: 4
259
273
  summary: factory_bot provides a framework and DSL for defining and using model instance