actionpack 7.0.8.1 → 7.2.2.1

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.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +94 -500
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +2 -2
  5. data/lib/abstract_controller/asset_paths.rb +2 -0
  6. data/lib/abstract_controller/base.rb +119 -106
  7. data/lib/abstract_controller/caching/fragments.rb +51 -52
  8. data/lib/abstract_controller/caching.rb +2 -0
  9. data/lib/abstract_controller/callbacks.rb +94 -67
  10. data/lib/abstract_controller/collector.rb +6 -6
  11. data/lib/abstract_controller/deprecator.rb +9 -0
  12. data/lib/abstract_controller/error.rb +2 -0
  13. data/lib/abstract_controller/helpers.rb +121 -91
  14. data/lib/abstract_controller/logger.rb +2 -0
  15. data/lib/abstract_controller/railties/routes_helpers.rb +3 -16
  16. data/lib/abstract_controller/rendering.rb +14 -13
  17. data/lib/abstract_controller/translation.rb +12 -30
  18. data/lib/abstract_controller/url_for.rb +9 -5
  19. data/lib/abstract_controller.rb +8 -0
  20. data/lib/action_controller/api/api_rendering.rb +2 -0
  21. data/lib/action_controller/api.rb +78 -73
  22. data/lib/action_controller/base.rb +199 -141
  23. data/lib/action_controller/caching.rb +16 -11
  24. data/lib/action_controller/deprecator.rb +9 -0
  25. data/lib/action_controller/form_builder.rb +21 -16
  26. data/lib/action_controller/log_subscriber.rb +19 -5
  27. data/lib/action_controller/metal/allow_browser.rb +123 -0
  28. data/lib/action_controller/metal/basic_implicit_render.rb +2 -0
  29. data/lib/action_controller/metal/conditional_get.rb +187 -174
  30. data/lib/action_controller/metal/content_security_policy.rb +26 -25
  31. data/lib/action_controller/metal/cookies.rb +4 -2
  32. data/lib/action_controller/metal/data_streaming.rb +65 -54
  33. data/lib/action_controller/metal/default_headers.rb +6 -2
  34. data/lib/action_controller/metal/etag_with_flash.rb +4 -0
  35. data/lib/action_controller/metal/etag_with_template_digest.rb +18 -14
  36. data/lib/action_controller/metal/exceptions.rb +19 -9
  37. data/lib/action_controller/metal/flash.rb +12 -10
  38. data/lib/action_controller/metal/head.rb +20 -16
  39. data/lib/action_controller/metal/helpers.rb +64 -67
  40. data/lib/action_controller/metal/http_authentication.rb +214 -200
  41. data/lib/action_controller/metal/implicit_render.rb +21 -17
  42. data/lib/action_controller/metal/instrumentation.rb +22 -12
  43. data/lib/action_controller/metal/live.rb +125 -92
  44. data/lib/action_controller/metal/logging.rb +6 -4
  45. data/lib/action_controller/metal/mime_responds.rb +151 -142
  46. data/lib/action_controller/metal/parameter_encoding.rb +34 -32
  47. data/lib/action_controller/metal/params_wrapper.rb +58 -58
  48. data/lib/action_controller/metal/permissions_policy.rb +14 -13
  49. data/lib/action_controller/metal/rate_limiting.rb +62 -0
  50. data/lib/action_controller/metal/redirecting.rb +110 -84
  51. data/lib/action_controller/metal/renderers.rb +50 -49
  52. data/lib/action_controller/metal/rendering.rb +103 -82
  53. data/lib/action_controller/metal/request_forgery_protection.rb +279 -161
  54. data/lib/action_controller/metal/rescue.rb +12 -8
  55. data/lib/action_controller/metal/streaming.rb +174 -132
  56. data/lib/action_controller/metal/strong_parameters.rb +598 -473
  57. data/lib/action_controller/metal/testing.rb +2 -0
  58. data/lib/action_controller/metal/url_for.rb +23 -14
  59. data/lib/action_controller/metal.rb +145 -61
  60. data/lib/action_controller/railtie.rb +25 -9
  61. data/lib/action_controller/railties/helpers.rb +2 -0
  62. data/lib/action_controller/renderer.rb +105 -66
  63. data/lib/action_controller/template_assertions.rb +4 -2
  64. data/lib/action_controller/test_case.rb +157 -128
  65. data/lib/action_controller.rb +17 -3
  66. data/lib/action_dispatch/constants.rb +34 -0
  67. data/lib/action_dispatch/deprecator.rb +9 -0
  68. data/lib/action_dispatch/http/cache.rb +28 -29
  69. data/lib/action_dispatch/http/content_disposition.rb +2 -0
  70. data/lib/action_dispatch/http/content_security_policy.rb +69 -49
  71. data/lib/action_dispatch/http/filter_parameters.rb +27 -12
  72. data/lib/action_dispatch/http/filter_redirect.rb +22 -1
  73. data/lib/action_dispatch/http/headers.rb +23 -21
  74. data/lib/action_dispatch/http/mime_negotiation.rb +37 -48
  75. data/lib/action_dispatch/http/mime_type.rb +60 -30
  76. data/lib/action_dispatch/http/mime_types.rb +5 -1
  77. data/lib/action_dispatch/http/parameters.rb +12 -10
  78. data/lib/action_dispatch/http/permissions_policy.rb +32 -34
  79. data/lib/action_dispatch/http/rack_cache.rb +4 -0
  80. data/lib/action_dispatch/http/request.rb +132 -79
  81. data/lib/action_dispatch/http/response.rb +136 -103
  82. data/lib/action_dispatch/http/upload.rb +19 -15
  83. data/lib/action_dispatch/http/url.rb +75 -73
  84. data/lib/action_dispatch/journey/formatter.rb +19 -6
  85. data/lib/action_dispatch/journey/gtg/builder.rb +4 -3
  86. data/lib/action_dispatch/journey/gtg/simulator.rb +2 -0
  87. data/lib/action_dispatch/journey/gtg/transition_table.rb +10 -8
  88. data/lib/action_dispatch/journey/nfa/dot.rb +2 -0
  89. data/lib/action_dispatch/journey/nodes/node.rb +6 -5
  90. data/lib/action_dispatch/journey/parser.rb +4 -3
  91. data/lib/action_dispatch/journey/parser_extras.rb +2 -0
  92. data/lib/action_dispatch/journey/path/pattern.rb +18 -15
  93. data/lib/action_dispatch/journey/route.rb +12 -9
  94. data/lib/action_dispatch/journey/router/utils.rb +16 -15
  95. data/lib/action_dispatch/journey/router.rb +13 -10
  96. data/lib/action_dispatch/journey/routes.rb +6 -4
  97. data/lib/action_dispatch/journey/scanner.rb +4 -2
  98. data/lib/action_dispatch/journey/visitors.rb +2 -0
  99. data/lib/action_dispatch/journey.rb +2 -0
  100. data/lib/action_dispatch/log_subscriber.rb +25 -0
  101. data/lib/action_dispatch/middleware/actionable_exceptions.rb +7 -6
  102. data/lib/action_dispatch/middleware/assume_ssl.rb +27 -0
  103. data/lib/action_dispatch/middleware/callbacks.rb +4 -0
  104. data/lib/action_dispatch/middleware/cookies.rb +192 -194
  105. data/lib/action_dispatch/middleware/debug_exceptions.rb +36 -27
  106. data/lib/action_dispatch/middleware/debug_locks.rb +18 -13
  107. data/lib/action_dispatch/middleware/debug_view.rb +9 -2
  108. data/lib/action_dispatch/middleware/exception_wrapper.rb +181 -27
  109. data/lib/action_dispatch/middleware/executor.rb +9 -1
  110. data/lib/action_dispatch/middleware/flash.rb +65 -46
  111. data/lib/action_dispatch/middleware/host_authorization.rb +22 -17
  112. data/lib/action_dispatch/middleware/public_exceptions.rb +12 -8
  113. data/lib/action_dispatch/middleware/reloader.rb +9 -5
  114. data/lib/action_dispatch/middleware/remote_ip.rb +88 -83
  115. data/lib/action_dispatch/middleware/request_id.rb +15 -8
  116. data/lib/action_dispatch/middleware/server_timing.rb +8 -6
  117. data/lib/action_dispatch/middleware/session/abstract_store.rb +7 -0
  118. data/lib/action_dispatch/middleware/session/cache_store.rb +14 -7
  119. data/lib/action_dispatch/middleware/session/cookie_store.rb +32 -25
  120. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +9 -3
  121. data/lib/action_dispatch/middleware/show_exceptions.rb +42 -28
  122. data/lib/action_dispatch/middleware/ssl.rb +60 -45
  123. data/lib/action_dispatch/middleware/stack.rb +15 -9
  124. data/lib/action_dispatch/middleware/static.rb +40 -34
  125. data/lib/action_dispatch/middleware/templates/rescues/_actions.html.erb +2 -2
  126. data/lib/action_dispatch/middleware/templates/rescues/_message_and_suggestions.html.erb +4 -4
  127. data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +8 -1
  128. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +7 -7
  129. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +2 -2
  130. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +17 -0
  131. data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +16 -12
  132. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +1 -1
  133. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +3 -3
  134. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +4 -4
  135. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +1 -1
  136. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +1 -1
  137. data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +3 -0
  138. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +47 -38
  139. data/lib/action_dispatch/railtie.rb +12 -4
  140. data/lib/action_dispatch/request/session.rb +39 -27
  141. data/lib/action_dispatch/request/utils.rb +10 -3
  142. data/lib/action_dispatch/routing/endpoint.rb +2 -0
  143. data/lib/action_dispatch/routing/inspector.rb +59 -9
  144. data/lib/action_dispatch/routing/mapper.rb +686 -639
  145. data/lib/action_dispatch/routing/polymorphic_routes.rb +70 -61
  146. data/lib/action_dispatch/routing/redirection.rb +52 -38
  147. data/lib/action_dispatch/routing/route_set.rb +106 -62
  148. data/lib/action_dispatch/routing/routes_proxy.rb +16 -19
  149. data/lib/action_dispatch/routing/url_for.rb +131 -122
  150. data/lib/action_dispatch/routing.rb +152 -150
  151. data/lib/action_dispatch/system_test_case.rb +91 -81
  152. data/lib/action_dispatch/system_testing/browser.rb +27 -19
  153. data/lib/action_dispatch/system_testing/driver.rb +16 -22
  154. data/lib/action_dispatch/system_testing/server.rb +2 -0
  155. data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +53 -31
  156. data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +2 -0
  157. data/lib/action_dispatch/testing/assertion_response.rb +9 -7
  158. data/lib/action_dispatch/testing/assertions/response.rb +36 -26
  159. data/lib/action_dispatch/testing/assertions/routing.rb +203 -95
  160. data/lib/action_dispatch/testing/assertions.rb +5 -1
  161. data/lib/action_dispatch/testing/integration.rb +240 -229
  162. data/lib/action_dispatch/testing/request_encoder.rb +6 -1
  163. data/lib/action_dispatch/testing/test_helpers/page_dump_helper.rb +35 -0
  164. data/lib/action_dispatch/testing/test_process.rb +14 -9
  165. data/lib/action_dispatch/testing/test_request.rb +4 -2
  166. data/lib/action_dispatch/testing/test_response.rb +34 -19
  167. data/lib/action_dispatch.rb +52 -21
  168. data/lib/action_pack/gem_version.rb +5 -3
  169. data/lib/action_pack/version.rb +3 -1
  170. data/lib/action_pack.rb +18 -17
  171. metadata +91 -32
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionController
4
6
  module Testing
5
7
  # Behavior specific to functional tests
@@ -1,30 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionController
4
- # Includes +url_for+ into the host class. The class has to provide a +RouteSet+ by implementing
5
- # the <tt>_routes</tt> method. Otherwise, an exception will be raised.
6
+ # # Action Controller UrlFor
7
+ #
8
+ # Includes `url_for` into the host class. The class has to provide a `RouteSet`
9
+ # by implementing the `_routes` method. Otherwise, an exception will be raised.
6
10
  #
7
- # In addition to AbstractController::UrlFor, this module accesses the HTTP layer to define
8
- # URL options like the +host+. In order to do so, this module requires the host class
9
- # to implement +env+ which needs to be Rack-compatible, and +request+ which
10
- # returns an ActionDispatch::Request instance.
11
+ # In addition to AbstractController::UrlFor, this module accesses the HTTP layer
12
+ # to define URL options like the `host`. In order to do so, this module requires
13
+ # the host class to implement `env` which needs to be Rack-compatible, and
14
+ # `request` which returns an ActionDispatch::Request instance.
11
15
  #
12
- # class RootUrl
13
- # include ActionController::UrlFor
14
- # include Rails.application.routes.url_helpers
16
+ # class RootUrl
17
+ # include ActionController::UrlFor
18
+ # include Rails.application.routes.url_helpers
15
19
  #
16
- # delegate :env, :request, to: :controller
20
+ # delegate :env, :request, to: :controller
17
21
  #
18
- # def initialize(controller)
19
- # @controller = controller
20
- # @url = root_path # named route from the application.
22
+ # def initialize(controller)
23
+ # @controller = controller
24
+ # @url = root_path # named route from the application.
25
+ # end
21
26
  # end
22
- # end
23
27
  module UrlFor
24
28
  extend ActiveSupport::Concern
25
29
 
26
30
  include AbstractController::UrlFor
27
31
 
32
+ def initialize(...)
33
+ super
34
+ @_url_options = nil
35
+ end
36
+
28
37
  def url_options
29
38
  @_url_options ||= {
30
39
  host: request.host,
@@ -1,15 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  require "active_support/core_ext/array/extract_options"
4
6
  require "action_dispatch/middleware/stack"
5
7
 
6
8
  module ActionController
7
- # Extend ActionDispatch middleware stack to make it aware of options
8
- # allowing the following syntax in controllers:
9
+ # # Action Controller MiddlewareStack
10
+ #
11
+ # Extend ActionDispatch middleware stack to make it aware of options allowing
12
+ # the following syntax in controllers:
9
13
  #
10
- # class PostsController < ApplicationController
11
- # use AuthenticationMiddleware, except: [:index, :show]
12
- # end
14
+ # class PostsController < ApplicationController
15
+ # use AuthenticationMiddleware, except: [:index, :show]
16
+ # end
13
17
  #
14
18
  class MiddlewareStack < ActionDispatch::MiddlewareStack # :nodoc:
15
19
  class Middleware < ActionDispatch::MiddlewareStack::Middleware # :nodoc:
@@ -58,71 +62,71 @@ module ActionController
58
62
  end
59
63
  end
60
64
 
61
- # <tt>ActionController::Metal</tt> is the simplest possible controller, providing a
65
+ # # Action Controller Metal
66
+ #
67
+ # `ActionController::Metal` is the simplest possible controller, providing a
62
68
  # valid Rack interface without the additional niceties provided by
63
69
  # ActionController::Base.
64
70
  #
65
71
  # A sample metal controller might look like this:
66
72
  #
67
- # class HelloController < ActionController::Metal
68
- # def index
69
- # self.response_body = "Hello World!"
73
+ # class HelloController < ActionController::Metal
74
+ # def index
75
+ # self.response_body = "Hello World!"
76
+ # end
70
77
  # end
71
- # end
72
78
  #
73
- # And then to route requests to your metal controller, you would add
74
- # something like this to <tt>config/routes.rb</tt>:
79
+ # And then to route requests to your metal controller, you would add something
80
+ # like this to `config/routes.rb`:
75
81
  #
76
- # get 'hello', to: HelloController.action(:index)
82
+ # get 'hello', to: HelloController.action(:index)
77
83
  #
78
- # The +action+ method returns a valid Rack application for the \Rails
79
- # router to dispatch to.
84
+ # The ::action method returns a valid Rack application for the Rails router to
85
+ # dispatch to.
80
86
  #
81
- # == Rendering Helpers
87
+ # ## Rendering Helpers
82
88
  #
83
- # <tt>ActionController::Metal</tt> by default provides no utilities for rendering
84
- # views, partials, or other responses aside from explicitly calling of
85
- # <tt>response_body=</tt>, <tt>content_type=</tt>, and <tt>status=</tt>. To
86
- # add the render helpers you're used to having in a normal controller, you
87
- # can do the following:
89
+ # By default, `ActionController::Metal` provides no utilities for rendering
90
+ # views, partials, or other responses aside from some low-level setters such
91
+ # as #response_body=, #content_type=, and #status=. To add the render helpers
92
+ # you're used to having in a normal controller, you can do the following:
88
93
  #
89
- # class HelloController < ActionController::Metal
90
- # include AbstractController::Rendering
91
- # include ActionView::Layouts
92
- # append_view_path "#{Rails.root}/app/views"
94
+ # class HelloController < ActionController::Metal
95
+ # include AbstractController::Rendering
96
+ # include ActionView::Layouts
97
+ # append_view_path "#{Rails.root}/app/views"
93
98
  #
94
- # def index
95
- # render "hello/index"
99
+ # def index
100
+ # render "hello/index"
101
+ # end
96
102
  # end
97
- # end
98
103
  #
99
- # == Redirection Helpers
104
+ # ## Redirection Helpers
100
105
  #
101
106
  # To add redirection helpers to your metal controller, do the following:
102
107
  #
103
- # class HelloController < ActionController::Metal
104
- # include ActionController::Redirecting
105
- # include Rails.application.routes.url_helpers
108
+ # class HelloController < ActionController::Metal
109
+ # include ActionController::Redirecting
110
+ # include Rails.application.routes.url_helpers
106
111
  #
107
- # def index
108
- # redirect_to root_url
112
+ # def index
113
+ # redirect_to root_url
114
+ # end
109
115
  # end
110
- # end
111
- #
112
- # == Other Helpers
113
116
  #
114
- # You can refer to the modules included in ActionController::Base to see
115
- # other features you can bring into your metal controller.
117
+ # ## Other Helpers
116
118
  #
119
+ # You can refer to the modules included in ActionController::Base to see other
120
+ # features you can bring into your metal controller.
117
121
  class Metal < AbstractController::Base
118
122
  abstract!
119
123
 
120
- # Returns the last part of the controller's name, underscored, without the ending
121
- # <tt>Controller</tt>. For instance, PostsController returns <tt>posts</tt>.
122
- # Namespaces are left out, so Admin::PostsController returns <tt>posts</tt> as well.
124
+ # Returns the last part of the controller's name, underscored, without the
125
+ # ending `Controller`. For instance, `PostsController` returns `posts`.
126
+ # Namespaces are left out, so `Admin::PostsController` returns `posts` as well.
123
127
  #
124
- # ==== Returns
125
- # * <tt>string</tt>
128
+ # #### Returns
129
+ # * `string`
126
130
  def self.controller_name
127
131
  @controller_name ||= (name.demodulize.delete_suffix("Controller").underscore unless anonymous?)
128
132
  end
@@ -137,20 +141,78 @@ module ActionController
137
141
  false
138
142
  end
139
143
 
144
+ class << self
145
+ private
146
+ def inherited(subclass)
147
+ super
148
+ subclass.middleware_stack = middleware_stack.dup
149
+ subclass.class_eval do
150
+ @controller_name = nil
151
+ end
152
+ end
153
+ end
154
+
140
155
  # Delegates to the class's ::controller_name.
141
156
  def controller_name
142
157
  self.class.controller_name
143
158
  end
144
159
 
145
- attr_internal :response, :request
160
+ ##
161
+ # :attr_reader: request
162
+ #
163
+ # The ActionDispatch::Request instance for the current request.
164
+ attr_internal :request
165
+
166
+ ##
167
+ # :attr_reader: response
168
+ #
169
+ # The ActionDispatch::Response instance for the current response.
170
+ attr_internal_reader :response
171
+
172
+ ##
173
+ # The ActionDispatch::Request::Session instance for the current request.
174
+ # See further details in the
175
+ # [Active Controller Session guide](https://guides.rubyonrails.org/action_controller_overview.html#session).
146
176
  delegate :session, to: "@_request"
147
- delegate :headers, :status=, :location=, :content_type=,
148
- :status, :location, :content_type, :media_type, to: "@_response"
177
+
178
+ ##
179
+ # Delegates to ActionDispatch::Response#headers.
180
+ delegate :headers, to: "@_response"
181
+
182
+ ##
183
+ # Delegates to ActionDispatch::Response#status=
184
+ delegate :status=, to: "@_response"
185
+
186
+ ##
187
+ # Delegates to ActionDispatch::Response#location=
188
+ delegate :location=, to: "@_response"
189
+
190
+ ##
191
+ # Delegates to ActionDispatch::Response#content_type=
192
+ delegate :content_type=, to: "@_response"
193
+
194
+ ##
195
+ # Delegates to ActionDispatch::Response#status
196
+ delegate :status, to: "@_response"
197
+
198
+ ##
199
+ # Delegates to ActionDispatch::Response#location
200
+ delegate :location, to: "@_response"
201
+
202
+ ##
203
+ # Delegates to ActionDispatch::Response#content_type
204
+ delegate :content_type, to: "@_response"
205
+
206
+ ##
207
+ # Delegates to ActionDispatch::Response#media_type
208
+ delegate :media_type, to: "@_response"
149
209
 
150
210
  def initialize
151
211
  @_request = nil
152
212
  @_response = nil
213
+ @_response_body = nil
153
214
  @_routes = nil
215
+ @_params = nil
154
216
  super
155
217
  end
156
218
 
@@ -164,17 +226,19 @@ module ActionController
164
226
 
165
227
  alias :response_code :status # :nodoc:
166
228
 
167
- # Basic url_for that can be overridden for more robust functionality.
229
+ # Basic `url_for` that can be overridden for more robust functionality.
168
230
  def url_for(string)
169
231
  string
170
232
  end
171
233
 
172
234
  def response_body=(body)
173
- body = [body] unless body.nil? || body.respond_to?(:each)
174
- response.reset_body!
175
- return unless body
176
- response.body = body
177
- super
235
+ if body
236
+ body = [body] if body.is_a?(String)
237
+ response.body = body
238
+ super
239
+ else
240
+ response.reset_body!
241
+ end
178
242
  end
179
243
 
180
244
  # Tests if render or redirect has already happened.
@@ -191,9 +255,23 @@ module ActionController
191
255
  end
192
256
 
193
257
  def set_response!(response) # :nodoc:
258
+ if @_response
259
+ _, _, body = @_response
260
+ body.close if body.respond_to?(:close)
261
+ end
262
+
194
263
  @_response = response
195
264
  end
196
265
 
266
+ # Assign the response and mark it as committed. No further processing will
267
+ # occur.
268
+ def response=(response)
269
+ set_response!(response)
270
+
271
+ # Force `performed?` to return true:
272
+ @_response_body = true
273
+ end
274
+
197
275
  def set_request!(request) # :nodoc:
198
276
  @_request = request
199
277
  @_request.controller_instance = self
@@ -209,11 +287,6 @@ module ActionController
209
287
 
210
288
  class_attribute :middleware_stack, default: ActionController::MiddlewareStack.new
211
289
 
212
- def self.inherited(base) # :nodoc:
213
- base.middleware_stack = middleware_stack.dup
214
- super
215
- end
216
-
217
290
  class << self
218
291
  # Pushes the given Rack middleware and its arguments to the bottom of the
219
292
  # middleware stack.
@@ -222,7 +295,18 @@ module ActionController
222
295
  end
223
296
  end
224
297
 
225
- # Alias for +middleware_stack+.
298
+ # The middleware stack used by this controller.
299
+ #
300
+ # By default uses a variation of ActionDispatch::MiddlewareStack which allows
301
+ # for the following syntax:
302
+ #
303
+ # class PostsController < ApplicationController
304
+ # use AuthenticationMiddleware, except: [:index, :show]
305
+ # end
306
+ #
307
+ # Read more about [Rails middleware stack]
308
+ # (https://guides.rubyonrails.org/rails_on_rack.html#action-dispatcher-middleware-stack)
309
+ # in the guides.
226
310
  def self.middleware
227
311
  middleware_stack
228
312
  end
@@ -242,8 +326,8 @@ module ActionController
242
326
  end
243
327
  end
244
328
 
245
- # Direct dispatch to the controller. Instantiates the controller, then
246
- # executes the action named +name+.
329
+ # Direct dispatch to the controller. Instantiates the controller, then executes
330
+ # the action named `name`.
247
331
  def self.dispatch(name, req, res)
248
332
  if middleware_stack.any?
249
333
  middleware_stack.build(name) { |env| new.dispatch(name, req, res) }.call req.env
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  require "rails"
4
6
  require "action_controller"
5
7
  require "action_dispatch/railtie"
@@ -14,8 +16,13 @@ module ActionController
14
16
  config.action_controller.log_query_tags_around_actions = true
15
17
  config.action_controller.wrap_parameters_by_default = false
16
18
 
19
+ config.eager_load_namespaces << AbstractController
17
20
  config.eager_load_namespaces << ActionController
18
21
 
22
+ initializer "action_controller.deprecator", before: :load_environment_config do |app|
23
+ app.deprecators[:action_controller] = ActionController.deprecator
24
+ end
25
+
19
26
  initializer "action_controller.assets_config", group: :all do |app|
20
27
  app.config.action_controller.assets_dir ||= app.config.paths["public"].first
21
28
  end
@@ -37,10 +44,15 @@ module ActionController
37
44
  action_on_unpermitted_parameters = options.action_on_unpermitted_parameters
38
45
 
39
46
  if action_on_unpermitted_parameters.nil?
40
- action_on_unpermitted_parameters = (Rails.env.test? || Rails.env.development?) ? :log : false
47
+ action_on_unpermitted_parameters = Rails.env.local? ? :log : false
41
48
  end
42
49
 
43
50
  ActionController::Parameters.action_on_unpermitted_parameters = action_on_unpermitted_parameters
51
+
52
+ unless options.allow_deprecated_parameters_hash_equality.nil?
53
+ ActionController::Parameters.allow_deprecated_parameters_hash_equality =
54
+ options.allow_deprecated_parameters_hash_equality
55
+ end
44
56
  end
45
57
  end
46
58
 
@@ -67,11 +79,13 @@ module ActionController
67
79
 
68
80
  # Configs used in other initializers
69
81
  filtered_options = options.except(
82
+ :default_protect_from_forgery,
70
83
  :log_query_tags_around_actions,
71
84
  :permit_all_parameters,
72
85
  :action_on_unpermitted_parameters,
73
86
  :always_permitted_parameters,
74
- :wrap_parameters_by_default
87
+ :wrap_parameters_by_default,
88
+ :allow_deprecated_parameters_hash_equality
75
89
  )
76
90
 
77
91
  filtered_options.each do |k, v|
@@ -99,12 +113,6 @@ module ActionController
99
113
  end
100
114
  end
101
115
 
102
- initializer "action_controller.eager_load_actions" do
103
- ActiveSupport.on_load(:after_initialize) do
104
- ActionController::Metal.descendants.each(&:action_methods) if config.eager_load
105
- end
106
- end
107
-
108
116
  initializer "action_controller.query_log_tags" do |app|
109
117
  query_logs_tags_enabled = app.config.respond_to?(:active_record) &&
110
118
  app.config.active_record.query_log_tags_enabled &&
@@ -118,7 +126,15 @@ module ActionController
118
126
  ActiveRecord::QueryLogs.taggings.merge!(
119
127
  controller: ->(context) { context[:controller]&.controller_name },
120
128
  action: ->(context) { context[:controller]&.action_name },
121
- namespaced_controller: ->(context) { context[:controller].class.name if context[:controller] }
129
+ namespaced_controller: ->(context) {
130
+ if context[:controller]
131
+ controller_class = context[:controller].class
132
+ # based on ActionController::Metal#controller_name, but does not demodulize
133
+ unless controller_class.anonymous?
134
+ controller_class.name.delete_suffix("Controller").underscore
135
+ end
136
+ end
137
+ }
122
138
  )
123
139
  end
124
140
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionController
4
6
  module Railties
5
7
  module Helpers