factory_bot_instrumentation 1.4.1 → 1.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: d643a4b86dc1bca8a7df314258f1fee44afa9caa0f20efd84dc5694e549249da
4
- data.tar.gz: 12ad4d38793d3ecc33b5588070940a852ddd22ed1ae1a51a67773141f24fb14d
3
+ metadata.gz: 64c8bfd7239e2b0011f69809680abfd6066fa6f41fc274527fa552555f20608a
4
+ data.tar.gz: a833f35d400e028b82623f72e4248101f977afb811c4a8f0ec0224f5a916f38b
5
5
  SHA512:
6
- metadata.gz: ea18bccad8065d7b71dc50058e7ba73d970e935d8fc14bb30f2b4126e31685b64938e023d75cbab28a809414dc7d1628a1b6e0396490584c7d9f5c344b582723
7
- data.tar.gz: 26df3f123614f34d35197c305ddcda4f83a8cfb9855ced96b2917ae3a95b8f724e8fee041f48b1c57ad5082158fba05e2160edbb34f82237f8846c7e6c5b37b7
6
+ metadata.gz: 65a6f1c073c7c81e573584fade3c389a9195e5c0e8a74439d958859596cbb7d3d89754061f5ea6b9d3fc9d3857ca89d867b45fb94db90415804a7a69cb1d2aaf
7
+ data.tar.gz: 9b14f2f5d3a05f9a9523cae760e88338c3ec2823b5090b462705c86b3a0cbef71fe00ed14f9cf8a086477d392e6a27259309dd1b1813c9517deed8f11d8912d7
data/CHANGELOG.md CHANGED
@@ -2,9 +2,20 @@
2
2
 
3
3
  * TODO: Replace this bullet point with an actual description of a change.
4
4
 
5
+ ### 1.5.1 (9 January 2025)
6
+
7
+ * Sometimes the classic Rails autoloader is confused our engines
8
+ `RootController` does not inherit our engines `ApplicationController`, but
9
+ the one from host application, so we specify our dependency explicitly (#26)
10
+
11
+ ### 1.5.0 (7 January 2025)
12
+
13
+ * Switched from `ActionController::API` to `ActionController::Base` for the
14
+ engine's `ApplicationController` (#25)
15
+
5
16
  ### 1.4.1 (6 January 2025)
6
17
 
7
- * Reverted (#23) as it causes errors for unknown reasons
18
+ * Reverted (#23) as it causes errors for unknown reasons (#24)
8
19
 
9
20
  ### 1.4.0 (6 January 2025)
10
21
 
data/README.md CHANGED
@@ -243,7 +243,8 @@ application. The file
243
243
  this:
244
244
 
245
245
  ```ruby
246
- class Instrumentation::AuthenticationsController < ActionController::API
246
+ class Instrumentation::AuthenticationsController \
247
+ < FactoryBot::Instrumentation::ApplicationController
247
248
  # Generate a new web app authentication URL for the given email address.
248
249
  # This endpoint creates new login URLs which are valid for 30 minutes.
249
250
  def create
@@ -271,9 +272,20 @@ routes like this:
271
272
 
272
273
  ```ruby
273
274
  Rails.application.routes.draw do
274
- unless Rails.env.production?
275
+ if ActiveModel::Type::Boolean.new.cast(ENV.fetch('INSTRUMENTATION_API',
276
+ false))
275
277
  mount FactoryBot::Instrumentation::Engine => '/instrumentation'
276
278
  end
279
+
280
+ # or with custom controllers in an namespace
281
+
282
+ if ActiveModel::Type::Boolean.new.cast(ENV.fetch('INSTRUMENTATION_API',
283
+ false))
284
+ namespace :instrumentation do
285
+ mount FactoryBot::Instrumentation::Engine => '/'
286
+ resource :authentication, only: :create
287
+ end
288
+ end
277
289
  end
278
290
  ```
279
291
 
@@ -3,12 +3,18 @@
3
3
  module FactoryBot
4
4
  module Instrumentation
5
5
  # A base engine application controller.
6
- class ApplicationController < ActionController::API
6
+ class ApplicationController < ActionController::Base
7
7
  # Extend our core functionality to support easy authentication logics
8
8
  include ActionController::HttpAuthentication::Basic::ControllerMethods
9
9
  include ActionController::HttpAuthentication::Digest::ControllerMethods
10
10
  include ActionController::HttpAuthentication::Token::ControllerMethods
11
11
 
12
+ # Rails 5.2 enabled CSRF protection by default, but this may be different
13
+ # on the host application. Therefore we cannot blindly disable it via
14
+ # +skip_forgery_protection+. We have to "enable" it for no routes, which
15
+ # eventually disables it entirely for this engine.
16
+ protect_from_forgery only: []
17
+
12
18
  # Allow the users to implement additional instrumentation-wide before
13
19
  # action logic, like authentication
14
20
  before_action do |_controller|
@@ -19,8 +25,6 @@ module FactoryBot
19
25
  end
20
26
  end
21
27
 
22
- protected
23
-
24
28
  # A simple shortcut for Basic Auth on Rails 4.2+. Just configure the
25
29
  # username and password and you're ready to check the current request.
26
30
  #
@@ -36,6 +40,53 @@ module FactoryBot
36
40
  )
37
41
  end
38
42
  end
43
+
44
+ # Unfortunately +Rails.configuration.instrumentation+ is only read once
45
+ # and do not hot-reload on changes. Thats why we read this file manually
46
+ # to get always a fresh state.
47
+ #
48
+ # @return [Hash{String => Mixed}] the instrumentation scenarios
49
+ def instrumentation
50
+ config_file = FactoryBot::Instrumentation.configuration.config_file.to_s
51
+ template = ERB.new(Pathname.new(config_file).read)
52
+ load_method = YAML.respond_to?(:unsafe_load) ? :unsafe_load : :load
53
+ YAML.send(load_method, template.result(binding))[Rails.env] || {}
54
+ end
55
+
56
+ # Map all the instrumentation scenarios into groups and pass them back.
57
+ #
58
+ # @return [Hash{String => Array}] the grouped scenarios
59
+ def scenarios
60
+ res = instrumentation['scenarios'] || []
61
+ res.each_with_object({}) do |scenario, memo|
62
+ group = scenario_group(scenario['name'])
63
+ scenario['group'] = group
64
+ memo[group] = [] unless memo.key? group
65
+ memo[group] << scenario
66
+ end
67
+ end
68
+
69
+ # Map all the configured scenario groups to a useable hash.
70
+ #
71
+ # @return [Hash{Regexp => String}] the group mapping
72
+ def groups
73
+ (instrumentation['groups'] || {}).transform_keys do |key|
74
+ Regexp.new(Regexp.quote(key))
75
+ end
76
+ end
77
+
78
+ # Fetch the group name for a given scenario name. This will utilize the
79
+ # +SCENARIO_GROUPS+ map.
80
+ #
81
+ # @param name [String] the scenario name
82
+ # @return [String] the group name
83
+ def scenario_group(name)
84
+ groups.map do |pattern, group_name|
85
+ next unless pattern.match? name
86
+
87
+ group_name
88
+ end.compact.first || 'Various'
89
+ end
39
90
  end
40
91
  end
41
92
  end
@@ -3,13 +3,7 @@
3
3
  module FactoryBot
4
4
  module Instrumentation
5
5
  # The Instrumentation engine controller with frontend and API actions.
6
- class RootController < ApplicationController
7
- # This is required to make API controllers template renderable
8
- include ActionView::Layouts
9
-
10
- # Configure the default application layout
11
- layout 'factory_bot/instrumentation/application'
12
-
6
+ class RootController < FactoryBot::Instrumentation::ApplicationController
13
7
  # Show the instrumentation frontend which features the output of
14
8
  # configured dynamic seeds scenarios. The frontend allows humans to
15
9
  # generate new seed data on the fly.
@@ -53,8 +47,6 @@ module FactoryBot
53
47
  FactoryBot::Instrumentation.configuration.render_error.call(self, e)
54
48
  end
55
49
 
56
- protected
57
-
58
50
  # Parse the given parameters from the request and build
59
51
  # a valid FactoryBot options set.
60
52
  #
@@ -79,53 +71,6 @@ module FactoryBot
79
71
  ]
80
72
  end
81
73
  # rubocop:enable Metrics/MethodLength
82
-
83
- # Unfortunately +Rails.configuration.instrumentation+ is only read once
84
- # and do not hot-reload on changes. Thats why we read this file manually
85
- # to get always a fresh state.
86
- #
87
- # @return [Hash{String => Mixed}] the instrumentation scenarios
88
- def instrumentation
89
- config_file = FactoryBot::Instrumentation.configuration.config_file.to_s
90
- template = ERB.new(Pathname.new(config_file).read)
91
- load_method = YAML.respond_to?(:unsafe_load) ? :unsafe_load : :load
92
- YAML.send(load_method, template.result(binding))[Rails.env] || {}
93
- end
94
-
95
- # Map all the instrumentation scenarios into groups and pass them back.
96
- #
97
- # @return [Hash{String => Array}] the grouped scenarios
98
- def scenarios
99
- res = instrumentation['scenarios'] || []
100
- res.each_with_object({}) do |scenario, memo|
101
- group = scenario_group(scenario['name'])
102
- scenario['group'] = group
103
- memo[group] = [] unless memo.key? group
104
- memo[group] << scenario
105
- end
106
- end
107
-
108
- # Map all the configured scenario groups to a useable hash.
109
- #
110
- # @return [Hash{Regexp => String}] the group mapping
111
- def groups
112
- (instrumentation['groups'] || {}).transform_keys do |key|
113
- Regexp.new(Regexp.quote(key))
114
- end
115
- end
116
-
117
- # Fetch the group name for a given scenario name. This will utilize the
118
- # +SCENARIO_GROUPS+ map.
119
- #
120
- # @param name [String] the scenario name
121
- # @return [String] the group name
122
- def scenario_group(name)
123
- groups.map do |pattern, group_name|
124
- next unless pattern.match? name
125
-
126
- group_name
127
- end.compact.first || 'Various'
128
- end
129
74
  end
130
75
  end
131
76
  end
@@ -5,6 +5,7 @@ module FactoryBot
5
5
  # The Instrumentation engine which can be mounted.
6
6
  class Engine < ::Rails::Engine
7
7
  isolate_namespace FactoryBot::Instrumentation
8
+ engine_name 'factory_bot_instrumentation'
8
9
 
9
10
  # Fill in some dynamic settings (application related)
10
11
  initializer 'factory_bot_instrumentation.config' do |app|
@@ -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.4.1'
7
+ VERSION = '1.5.1'
8
8
 
9
9
  class << self
10
10
  # Returns the version of gem as a string.
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.4.1
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hermann Mayer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-01-06 00:00:00.000000000 Z
11
+ date: 2025-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: factory_bot