factory_bot_instrumentation 1.4.1 → 1.5.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: d643a4b86dc1bca8a7df314258f1fee44afa9caa0f20efd84dc5694e549249da
4
- data.tar.gz: 12ad4d38793d3ecc33b5588070940a852ddd22ed1ae1a51a67773141f24fb14d
3
+ metadata.gz: 83e360c563829d80a36e5bc4210a6a3da30233958a03d6c121a0158b445cb502
4
+ data.tar.gz: ee121882322897358b90092c0c88e8d0d70e416bc5a44188c78e34386aaa07ea
5
5
  SHA512:
6
- metadata.gz: ea18bccad8065d7b71dc50058e7ba73d970e935d8fc14bb30f2b4126e31685b64938e023d75cbab28a809414dc7d1628a1b6e0396490584c7d9f5c344b582723
7
- data.tar.gz: 26df3f123614f34d35197c305ddcda4f83a8cfb9855ced96b2917ae3a95b8f724e8fee041f48b1c57ad5082158fba05e2160edbb34f82237f8846c7e6c5b37b7
6
+ metadata.gz: 4a6f7e41ffe69853ef92f6708f8540b571917b78086084f52d0c8790e3aa1222661c3bbd0dc8b70867a506a8e3d412610ebb8b364130bcfc82022052b8304cc7
7
+ data.tar.gz: 01d84146f7db621d49a04ea6542e4a6bf570676a4c5405560a4aeb56b0b92f457d72163a480b0b2c583f756adfe36ce739bb3de35875b6ed9de7229693411a5e
data/CHANGELOG.md CHANGED
@@ -2,9 +2,14 @@
2
2
 
3
3
  * TODO: Replace this bullet point with an actual description of a change.
4
4
 
5
+ ### 1.5.0 (7 January 2025)
6
+
7
+ * Switched from `ActionController::API` to `ActionController::Base` for the
8
+ engine's `ApplicationController` (#25)
9
+
5
10
  ### 1.4.1 (6 January 2025)
6
11
 
7
- * Reverted (#23) as it causes errors for unknown reasons
12
+ * Reverted (#23) as it causes errors for unknown reasons (#24)
8
13
 
9
14
  ### 1.4.0 (6 January 2025)
10
15
 
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
@@ -4,12 +4,6 @@ module FactoryBot
4
4
  module Instrumentation
5
5
  # The Instrumentation engine controller with frontend and API actions.
6
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
-
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.0'
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.0
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-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: factory_bot