factory_bot_instrumentation 1.0.0 → 1.0.2

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: 8fad506387bc8c52339b3868ba4026a436bb3b4602747eabd30dcf3f41ecd855
4
- data.tar.gz: a6c8adffc73924cbea80296c721ed264ba9378bba8f7bee7a1ec296871f17b79
3
+ metadata.gz: df9495f96882f162c18ca1c8467d09c34d8dc40981ed1a7ba541a7d5200867a9
4
+ data.tar.gz: 2ae4e05a4dbd3e729d56ffbfeafb2c14aeef6b6a8e825a6b94023bb6fa379823
5
5
  SHA512:
6
- metadata.gz: 24790a2a645d22cc50edefb2ee19c3215cfd173ac88bf3bced467a1b71ec73a984ae28e88e57d09f6ff938266c38d89262dfec1596a55516b74449e6e6de0437
7
- data.tar.gz: 741ac435c5ed84bcc622ac327598be7b37e1b98757772ee189eb5f01446ae766ee8b443380dbc97767d240b6ba329416d988f6d8dd1e1a8420b7ea83345a598f
6
+ metadata.gz: c598dcbc2cf1cfc4f7e7c6d9a1e0389f7c9583e9208ae008db35cf320ba740232a9038fb6c00b92b06d95ca5483fee5663b88e70b39c6e7371624494d337f21f
7
+ data.tar.gz: dd88ab7d48335f79c874005ea50ee76a6878af89cc3ebbb5333ade70059f084654c20ae83a2200d1d6c2730ced8e58859a4358c8934703f19fa2dfe5f29e766b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ### 1.0.2
2
+
3
+ * When used in combination with the `factory_bot_rails` gem (>= 6.0) we do not
4
+ force a `FactoryBot.reload` at Rails engine initialization as it breaks with
5
+ an `FactoryBot::DuplicateDefinitionError` (#14)
6
+
7
+ ### 1.0.1
8
+
9
+ * Added a retry logic to the FactoryBot reloading on the POST/create endpoint
10
+ in order to handle parallel requests properly (#13)
11
+
1
12
  ### 1.0.0
2
13
 
3
14
  * Bundler >= 2.3 is from now on required as minimal version (#12)
@@ -37,8 +37,11 @@ module FactoryBot
37
37
  #
38
38
  # The result is the API v1 representation of the created entity.
39
39
  def create
40
- # Reload the factories to improve the test development experience
41
- FactoryBot.reload
40
+ # Reload the factories to improve the test development experience.
41
+ # In parallel request conditions this may lead to +Factory already
42
+ # registered+ errors as this call is not thread safe as it seems,
43
+ # so we retry it multiple times.
44
+ with_retries(max_tries: 15) { FactoryBot.reload }
42
45
  # Call the factory construction with the user given parameters
43
46
  entity = FactoryBot.create(*factory_params)
44
47
  # Render the resulting entity with the configured rendering block
@@ -35,10 +35,12 @@ Gem::Specification.new do |spec|
35
35
 
36
36
  spec.add_runtime_dependency 'factory_bot', '~> 6.2'
37
37
  spec.add_runtime_dependency 'rails', '>= 5.2'
38
+ spec.add_runtime_dependency 'retries', '>= 0.0.5'
38
39
 
39
40
  spec.add_development_dependency 'appraisal', '~> 2.4'
40
41
  spec.add_development_dependency 'bundler', '~> 2.3'
41
42
  spec.add_development_dependency 'countless', '~> 1.1'
43
+ spec.add_development_dependency 'factory_bot_rails', '~> 6.2'
42
44
  spec.add_development_dependency 'guard-rspec', '~> 4.7'
43
45
  spec.add_development_dependency 'railties', '>= 5.2'
44
46
  spec.add_development_dependency 'rspec-rails', '~> 5.1'
@@ -7,11 +7,16 @@ module FactoryBot
7
7
  isolate_namespace FactoryBot::Instrumentation
8
8
 
9
9
  # Fill in some dynamic settings (application related)
10
- initializer 'factory_bot_instrumentation.config' do
11
- # Ensure the FactoryBot gem loads its factories to ensure they are
12
- # also available in the rails console and other places in the app
13
- # and not only via instrumentation frontend.
14
- FactoryBot.reload
10
+ initializer 'factory_bot_instrumentation.config' do |app|
11
+ # Ensure the FactoryBot gem loads its factories to ensure they are also
12
+ # available in the rails console and other places in the app and not
13
+ # only via instrumentation frontend. We skip this step as in
14
+ # combination with the +factory_bot_rails+ gem (>=6.0) the FactoryBot
15
+ # initializing occurs after the Rails application initializing, which
16
+ # leads to +FactoryBot::DuplicateDefinitionError+s.
17
+ initializer_names = app.initializers.map(&:name).map(&:to_s)
18
+ FactoryBot.reload \
19
+ if initializer_names.grep(/^factory_bot\./).count.zero?
15
20
 
16
21
  FactoryBot::Instrumentation.configure do |conf|
17
22
  # Set the application name dynamically
@@ -4,7 +4,7 @@ module FactoryBot
4
4
  # The gem version details.
5
5
  module Instrumentation
6
6
  # The version of the +factory_bot_instrumentation+ gem
7
- VERSION = '1.0.0'
7
+ VERSION = '1.0.2'
8
8
 
9
9
  class << self
10
10
  # Returns the version of gem as a string.
@@ -7,6 +7,7 @@ require 'active_support/cache'
7
7
  require 'active_support/core_ext/hash'
8
8
  require 'active_support/time'
9
9
  require 'active_support/time_with_zone'
10
+ require 'retries'
10
11
 
11
12
  require 'factory_bot'
12
13
  require 'factory_bot/instrumentation/configuration'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factory_bot_instrumentation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hermann Mayer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-18 00:00:00.000000000 Z
11
+ date: 2023-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: factory_bot
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '5.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: retries
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.0.5
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.0.5
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: appraisal
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
96
  version: '1.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: factory_bot_rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '6.2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '6.2'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: guard-rspec
85
113
  requirement: !ruby/object:Gem::Requirement