actionpack 7.1.5.1 → 8.1.2

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 (177) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +308 -523
  3. data/README.rdoc +1 -1
  4. data/lib/abstract_controller/asset_paths.rb +6 -2
  5. data/lib/abstract_controller/base.rb +104 -105
  6. data/lib/abstract_controller/caching/fragments.rb +50 -53
  7. data/lib/abstract_controller/caching.rb +8 -3
  8. data/lib/abstract_controller/callbacks.rb +70 -62
  9. data/lib/abstract_controller/collector.rb +7 -7
  10. data/lib/abstract_controller/deprecator.rb +2 -0
  11. data/lib/abstract_controller/error.rb +2 -0
  12. data/lib/abstract_controller/helpers.rb +71 -84
  13. data/lib/abstract_controller/logger.rb +4 -1
  14. data/lib/abstract_controller/railties/routes_helpers.rb +2 -0
  15. data/lib/abstract_controller/rendering.rb +13 -13
  16. data/lib/abstract_controller/translation.rb +12 -13
  17. data/lib/abstract_controller/url_for.rb +8 -6
  18. data/lib/abstract_controller.rb +2 -0
  19. data/lib/action_controller/api/api_rendering.rb +2 -0
  20. data/lib/action_controller/api.rb +76 -72
  21. data/lib/action_controller/base.rb +199 -126
  22. data/lib/action_controller/caching.rb +16 -14
  23. data/lib/action_controller/deprecator.rb +2 -0
  24. data/lib/action_controller/form_builder.rb +21 -18
  25. data/lib/action_controller/log_subscriber.rb +23 -2
  26. data/lib/action_controller/metal/allow_browser.rb +133 -0
  27. data/lib/action_controller/metal/basic_implicit_render.rb +2 -0
  28. data/lib/action_controller/metal/conditional_get.rb +217 -175
  29. data/lib/action_controller/metal/content_security_policy.rb +25 -24
  30. data/lib/action_controller/metal/cookies.rb +4 -2
  31. data/lib/action_controller/metal/data_streaming.rb +72 -63
  32. data/lib/action_controller/metal/default_headers.rb +5 -3
  33. data/lib/action_controller/metal/etag_with_flash.rb +3 -1
  34. data/lib/action_controller/metal/etag_with_template_digest.rb +17 -15
  35. data/lib/action_controller/metal/exceptions.rb +16 -9
  36. data/lib/action_controller/metal/flash.rb +13 -14
  37. data/lib/action_controller/metal/head.rb +15 -11
  38. data/lib/action_controller/metal/helpers.rb +63 -55
  39. data/lib/action_controller/metal/http_authentication.rb +209 -201
  40. data/lib/action_controller/metal/implicit_render.rb +17 -15
  41. data/lib/action_controller/metal/instrumentation.rb +16 -14
  42. data/lib/action_controller/metal/live.rb +177 -128
  43. data/lib/action_controller/metal/logging.rb +6 -4
  44. data/lib/action_controller/metal/mime_responds.rb +151 -142
  45. data/lib/action_controller/metal/parameter_encoding.rb +34 -32
  46. data/lib/action_controller/metal/params_wrapper.rb +57 -59
  47. data/lib/action_controller/metal/permissions_policy.rb +22 -12
  48. data/lib/action_controller/metal/rate_limiting.rb +92 -0
  49. data/lib/action_controller/metal/redirecting.rb +213 -94
  50. data/lib/action_controller/metal/renderers.rb +78 -57
  51. data/lib/action_controller/metal/rendering.rb +111 -77
  52. data/lib/action_controller/metal/request_forgery_protection.rb +182 -143
  53. data/lib/action_controller/metal/rescue.rb +20 -9
  54. data/lib/action_controller/metal/streaming.rb +118 -195
  55. data/lib/action_controller/metal/strong_parameters.rb +720 -530
  56. data/lib/action_controller/metal/testing.rb +2 -0
  57. data/lib/action_controller/metal/url_for.rb +17 -15
  58. data/lib/action_controller/metal.rb +86 -60
  59. data/lib/action_controller/railtie.rb +36 -15
  60. data/lib/action_controller/railties/helpers.rb +2 -0
  61. data/lib/action_controller/renderer.rb +41 -36
  62. data/lib/action_controller/structured_event_subscriber.rb +116 -0
  63. data/lib/action_controller/template_assertions.rb +4 -2
  64. data/lib/action_controller/test_case.rb +160 -131
  65. data/lib/action_controller.rb +5 -1
  66. data/lib/action_dispatch/constants.rb +8 -0
  67. data/lib/action_dispatch/deprecator.rb +2 -0
  68. data/lib/action_dispatch/http/cache.rb +163 -35
  69. data/lib/action_dispatch/http/content_disposition.rb +2 -0
  70. data/lib/action_dispatch/http/content_security_policy.rb +54 -39
  71. data/lib/action_dispatch/http/filter_parameters.rb +14 -8
  72. data/lib/action_dispatch/http/filter_redirect.rb +22 -1
  73. data/lib/action_dispatch/http/headers.rb +22 -22
  74. data/lib/action_dispatch/http/mime_negotiation.rb +89 -41
  75. data/lib/action_dispatch/http/mime_type.rb +25 -21
  76. data/lib/action_dispatch/http/mime_types.rb +3 -0
  77. data/lib/action_dispatch/http/param_builder.rb +187 -0
  78. data/lib/action_dispatch/http/param_error.rb +26 -0
  79. data/lib/action_dispatch/http/parameters.rb +14 -12
  80. data/lib/action_dispatch/http/permissions_policy.rb +25 -36
  81. data/lib/action_dispatch/http/query_parser.rb +55 -0
  82. data/lib/action_dispatch/http/rack_cache.rb +2 -0
  83. data/lib/action_dispatch/http/request.rb +141 -92
  84. data/lib/action_dispatch/http/response.rb +137 -77
  85. data/lib/action_dispatch/http/upload.rb +18 -16
  86. data/lib/action_dispatch/http/url.rb +187 -89
  87. data/lib/action_dispatch/journey/formatter.rb +21 -9
  88. data/lib/action_dispatch/journey/gtg/builder.rb +4 -3
  89. data/lib/action_dispatch/journey/gtg/simulator.rb +34 -11
  90. data/lib/action_dispatch/journey/gtg/transition_table.rb +47 -53
  91. data/lib/action_dispatch/journey/nfa/dot.rb +2 -0
  92. data/lib/action_dispatch/journey/nodes/node.rb +8 -6
  93. data/lib/action_dispatch/journey/parser.rb +99 -195
  94. data/lib/action_dispatch/journey/path/pattern.rb +4 -1
  95. data/lib/action_dispatch/journey/route.rb +54 -38
  96. data/lib/action_dispatch/journey/router/utils.rb +22 -27
  97. data/lib/action_dispatch/journey/router.rb +63 -83
  98. data/lib/action_dispatch/journey/routes.rb +11 -2
  99. data/lib/action_dispatch/journey/scanner.rb +46 -42
  100. data/lib/action_dispatch/journey/visitors.rb +57 -23
  101. data/lib/action_dispatch/journey/visualizer/fsm.js +4 -6
  102. data/lib/action_dispatch/journey.rb +2 -0
  103. data/lib/action_dispatch/log_subscriber.rb +7 -1
  104. data/lib/action_dispatch/middleware/actionable_exceptions.rb +2 -0
  105. data/lib/action_dispatch/middleware/assume_ssl.rb +8 -5
  106. data/lib/action_dispatch/middleware/callbacks.rb +3 -1
  107. data/lib/action_dispatch/middleware/cookies.rb +125 -106
  108. data/lib/action_dispatch/middleware/debug_exceptions.rb +37 -8
  109. data/lib/action_dispatch/middleware/debug_locks.rb +15 -13
  110. data/lib/action_dispatch/middleware/debug_view.rb +13 -5
  111. data/lib/action_dispatch/middleware/exception_wrapper.rb +18 -23
  112. data/lib/action_dispatch/middleware/executor.rb +19 -4
  113. data/lib/action_dispatch/middleware/flash.rb +63 -51
  114. data/lib/action_dispatch/middleware/host_authorization.rb +17 -15
  115. data/lib/action_dispatch/middleware/public_exceptions.rb +14 -12
  116. data/lib/action_dispatch/middleware/reloader.rb +5 -3
  117. data/lib/action_dispatch/middleware/remote_ip.rb +87 -77
  118. data/lib/action_dispatch/middleware/request_id.rb +16 -10
  119. data/lib/action_dispatch/middleware/server_timing.rb +4 -2
  120. data/lib/action_dispatch/middleware/session/abstract_store.rb +2 -0
  121. data/lib/action_dispatch/middleware/session/cache_store.rb +30 -8
  122. data/lib/action_dispatch/middleware/session/cookie_store.rb +27 -26
  123. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +7 -3
  124. data/lib/action_dispatch/middleware/show_exceptions.rb +16 -16
  125. data/lib/action_dispatch/middleware/ssl.rb +53 -40
  126. data/lib/action_dispatch/middleware/stack.rb +11 -10
  127. data/lib/action_dispatch/middleware/static.rb +33 -31
  128. data/lib/action_dispatch/middleware/templates/rescues/_copy_button.html.erb +1 -0
  129. data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +3 -5
  130. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +9 -5
  131. data/lib/action_dispatch/middleware/templates/rescues/blocked_host.html.erb +1 -0
  132. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +1 -0
  133. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +4 -0
  134. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +3 -0
  135. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +50 -0
  136. data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +1 -0
  137. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +1 -0
  138. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +1 -0
  139. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +1 -0
  140. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +1 -0
  141. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +1 -1
  142. data/lib/action_dispatch/railtie.rb +23 -3
  143. data/lib/action_dispatch/request/session.rb +24 -21
  144. data/lib/action_dispatch/request/utils.rb +11 -3
  145. data/lib/action_dispatch/routing/endpoint.rb +2 -0
  146. data/lib/action_dispatch/routing/inspector.rb +85 -60
  147. data/lib/action_dispatch/routing/mapper.rb +1031 -851
  148. data/lib/action_dispatch/routing/polymorphic_routes.rb +69 -62
  149. data/lib/action_dispatch/routing/redirection.rb +47 -39
  150. data/lib/action_dispatch/routing/route_set.rb +79 -56
  151. data/lib/action_dispatch/routing/routes_proxy.rb +7 -4
  152. data/lib/action_dispatch/routing/url_for.rb +130 -125
  153. data/lib/action_dispatch/routing.rb +150 -148
  154. data/lib/action_dispatch/structured_event_subscriber.rb +20 -0
  155. data/lib/action_dispatch/system_test_case.rb +91 -81
  156. data/lib/action_dispatch/system_testing/browser.rb +16 -23
  157. data/lib/action_dispatch/system_testing/driver.rb +2 -0
  158. data/lib/action_dispatch/system_testing/server.rb +2 -0
  159. data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +34 -23
  160. data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +2 -0
  161. data/lib/action_dispatch/testing/assertion_response.rb +9 -7
  162. data/lib/action_dispatch/testing/assertions/response.rb +52 -25
  163. data/lib/action_dispatch/testing/assertions/routing.rb +168 -87
  164. data/lib/action_dispatch/testing/assertions.rb +2 -0
  165. data/lib/action_dispatch/testing/integration.rb +233 -223
  166. data/lib/action_dispatch/testing/request_encoder.rb +11 -9
  167. data/lib/action_dispatch/testing/test_helpers/page_dump_helper.rb +35 -0
  168. data/lib/action_dispatch/testing/test_process.rb +11 -8
  169. data/lib/action_dispatch/testing/test_request.rb +3 -1
  170. data/lib/action_dispatch/testing/test_response.rb +27 -26
  171. data/lib/action_dispatch.rb +36 -32
  172. data/lib/action_pack/gem_version.rb +6 -4
  173. data/lib/action_pack/version.rb +3 -1
  174. data/lib/action_pack.rb +17 -16
  175. metadata +36 -32
  176. data/lib/action_dispatch/journey/parser.y +0 -50
  177. data/lib/action_dispatch/journey/parser_extras.rb +0 -31
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  require "rack/session/abstract/id"
4
6
  require "active_support/core_ext/hash/conversions"
5
7
  require "active_support/core_ext/object/to_query"
@@ -16,21 +18,31 @@ module ActionController
16
18
  end
17
19
 
18
20
  module Live
19
- # Disable controller / rendering threads in tests. User tests can access
20
- # the database on the main thread, so they could open a txn, then the
21
- # controller thread will open a new connection and try to access data
22
- # that's only visible to the main thread's txn. This is the problem in #23483.
21
+ # Disable controller / rendering threads in tests. User tests can access the
22
+ # database on the main thread, so they could open a txn, then the controller
23
+ # thread will open a new connection and try to access data that's only visible
24
+ # to the main thread's txn. This is the problem in #23483.
25
+ alias_method :original_new_controller_thread, :new_controller_thread
26
+
23
27
  silence_redefinition_of_method :new_controller_thread
24
28
  def new_controller_thread # :nodoc:
25
29
  yield
26
30
  end
27
31
 
32
+ # Because of the above, we need to prevent the clearing of thread locals, since
33
+ # no new thread is actually spawned in the test environment.
34
+ alias_method :original_clean_up_thread_locals, :clean_up_thread_locals
35
+
36
+ silence_redefinition_of_method :clean_up_thread_locals
37
+ def clean_up_thread_locals(*args) # :nodoc:
38
+ end
39
+
28
40
  # Avoid a deadlock from the queue filling up
29
41
  Buffer.queue_size = nil
30
42
  end
31
43
 
32
- # ActionController::TestCase will be deprecated and moved to a gem in the future.
33
- # Please use ActionDispatch::IntegrationTest going forward.
44
+ # ActionController::TestCase will be deprecated and moved to a gem in the
45
+ # future. Please use ActionDispatch::IntegrationTest going forward.
34
46
  class TestRequest < ActionDispatch::TestRequest # :nodoc:
35
47
  DEFAULT_ENV = ActionDispatch::TestRequest::DEFAULT_ENV.dup
36
48
  DEFAULT_ENV.delete "PATH_INFO"
@@ -104,7 +116,7 @@ module ActionController
104
116
  set_header k, "application/x-www-form-urlencoded"
105
117
  end
106
118
 
107
- case content_mime_type.to_sym
119
+ case content_mime_type&.to_sym
108
120
  when nil
109
121
  raise "Unknown Content-Type: #{content_type}"
110
122
  when :json
@@ -119,7 +131,7 @@ module ActionController
119
131
  end
120
132
  end
121
133
 
122
- data_stream = StringIO.new(data)
134
+ data_stream = StringIO.new(data.b)
123
135
  set_header "CONTENT_LENGTH", data_stream.length.to_s
124
136
  set_header "rack.input", data_stream
125
137
  end
@@ -232,116 +244,127 @@ module ActionController
232
244
  end
233
245
  end
234
246
 
235
- # = Action Controller Test Case
247
+ # # Action Controller Test Case
236
248
  #
237
- # Superclass for ActionController functional tests. Functional tests allow you to
238
- # test a single controller action per test method.
249
+ # Superclass for ActionController functional tests. Functional tests allow you
250
+ # to test a single controller action per test method.
239
251
  #
240
- # == Use integration style controller tests over functional style controller tests.
252
+ # ## Use integration style controller tests over functional style controller tests.
241
253
  #
242
- # \Rails discourages the use of functional tests in favor of integration tests
254
+ # Rails discourages the use of functional tests in favor of integration tests
243
255
  # (use ActionDispatch::IntegrationTest).
244
256
  #
245
- # New \Rails applications no longer generate functional style controller tests and they should
246
- # only be used for backward compatibility. Integration style controller tests perform actual
247
- # requests, whereas functional style controller tests merely simulate a request. Besides,
248
- # integration tests are as fast as functional tests and provide lot of helpers such as +as+,
249
- # +parsed_body+ for effective testing of controller actions including even API endpoints.
257
+ # New Rails applications no longer generate functional style controller tests
258
+ # and they should only be used for backward compatibility. Integration style
259
+ # controller tests perform actual requests, whereas functional style controller
260
+ # tests merely simulate a request. Besides, integration tests are as fast as
261
+ # functional tests and provide lot of helpers such as `as`, `parsed_body` for
262
+ # effective testing of controller actions including even API endpoints.
250
263
  #
251
- # == Basic example
264
+ # ## Basic example
252
265
  #
253
266
  # Functional tests are written as follows:
254
- # 1. First, one uses the +get+, +post+, +patch+, +put+, +delete+, or +head+ method to simulate
255
- # an HTTP request.
256
- # 2. Then, one asserts whether the current state is as expected. "State" can be anything:
257
- # the controller's HTTP response, the database contents, etc.
267
+ # 1. First, one uses the `get`, `post`, `patch`, `put`, `delete`, or `head`
268
+ # method to simulate an HTTP request.
269
+ # 2. Then, one asserts whether the current state is as expected. "State" can be
270
+ # anything: the controller's HTTP response, the database contents, etc.
271
+ #
258
272
  #
259
273
  # For example:
260
274
  #
261
- # class BooksControllerTest < ActionController::TestCase
262
- # def test_create
263
- # # Simulate a POST response with the given HTTP parameters.
264
- # post(:create, params: { book: { title: "Love Hina" }})
275
+ # class BooksControllerTest < ActionController::TestCase
276
+ # def test_create
277
+ # # Simulate a POST response with the given HTTP parameters.
278
+ # post(:create, params: { book: { title: "Love Hina" }})
265
279
  #
266
- # # Asserts that the controller tried to redirect us to
267
- # # the created book's URI.
268
- # assert_response :found
280
+ # # Asserts that the controller tried to redirect us to
281
+ # # the created book's URI.
282
+ # assert_response :found
269
283
  #
270
- # # Asserts that the controller really put the book in the database.
271
- # assert_not_nil Book.find_by(title: "Love Hina")
284
+ # # Asserts that the controller really put the book in the database.
285
+ # assert_not_nil Book.find_by(title: "Love Hina")
286
+ # end
272
287
  # end
273
- # end
274
288
  #
275
289
  # You can also send a real document in the simulated HTTP request.
276
290
  #
277
- # def test_create
278
- # json = {book: { title: "Love Hina" }}.to_json
279
- # post :create, body: json
280
- # end
291
+ # def test_create
292
+ # json = {book: { title: "Love Hina" }}.to_json
293
+ # post :create, body: json
294
+ # end
295
+ #
296
+ # ## Special instance variables
297
+ #
298
+ # ActionController::TestCase will also automatically provide the following
299
+ # instance variables for use in the tests:
300
+ #
301
+ # @controller
302
+ # : The controller instance that will be tested.
281
303
  #
282
- # == Special instance variables
304
+ # @request
305
+ # : An ActionController::TestRequest, representing the current HTTP request.
306
+ # You can modify this object before sending the HTTP request. For example,
307
+ # you might want to set some session properties before sending a GET
308
+ # request.
283
309
  #
284
- # ActionController::TestCase will also automatically provide the following instance
285
- # variables for use in the tests:
310
+ # @response
311
+ # : An ActionDispatch::TestResponse object, representing the response of the
312
+ # last HTTP response. In the above example, `@response` becomes valid after
313
+ # calling `post`. If the various assert methods are not sufficient, then you
314
+ # may use this object to inspect the HTTP response in detail.
286
315
  #
287
- # @controller::
288
- # The controller instance that will be tested.
289
- # @request::
290
- # An ActionController::TestRequest, representing the current HTTP
291
- # request. You can modify this object before sending the HTTP request. For example,
292
- # you might want to set some session properties before sending a GET request.
293
- # @response::
294
- # An ActionDispatch::TestResponse object, representing the response
295
- # of the last HTTP response. In the above example, <tt>@response</tt> becomes valid
296
- # after calling +post+. If the various assert methods are not sufficient, then you
297
- # may use this object to inspect the HTTP response in detail.
298
316
  #
299
- # == Controller is automatically inferred
317
+ # ## Controller is automatically inferred
300
318
  #
301
319
  # ActionController::TestCase will automatically infer the controller under test
302
320
  # from the test class name. If the controller cannot be inferred from the test
303
- # class name, you can explicitly set it with +tests+.
321
+ # class name, you can explicitly set it with `tests`.
304
322
  #
305
- # class SpecialEdgeCaseWidgetsControllerTest < ActionController::TestCase
306
- # tests WidgetController
307
- # end
323
+ # class SpecialEdgeCaseWidgetsControllerTest < ActionController::TestCase
324
+ # tests WidgetController
325
+ # end
326
+ #
327
+ # ## Testing controller internals
308
328
  #
309
- # == \Testing controller internals
329
+ # In addition to these specific assertions, you also have easy access to various
330
+ # collections that the regular test/unit assertions can be used against. These
331
+ # collections are:
310
332
  #
311
- # In addition to these specific assertions, you also have easy access to various collections that the regular test/unit assertions
312
- # can be used against. These collections are:
333
+ # * session: Objects being saved in the session.
334
+ # * flash: The flash objects currently in the session.
335
+ # * cookies: Cookies being sent to the user on this request.
313
336
  #
314
- # * session: Objects being saved in the session.
315
- # * flash: The flash objects currently in the session.
316
- # * cookies: \Cookies being sent to the user on this request.
317
337
  #
318
338
  # These collections can be used just like any other hash:
319
339
  #
320
- # assert_equal "Dave", cookies[:name] # makes sure that a cookie called :name was set as "Dave"
321
- # assert flash.empty? # makes sure that there's nothing in the flash
340
+ # assert_equal "Dave", cookies[:name] # makes sure that a cookie called :name was set as "Dave"
341
+ # assert flash.empty? # makes sure that there's nothing in the flash
322
342
  #
323
- # On top of the collections, you have the complete URL that a given action redirected to available in <tt>redirect_to_url</tt>.
343
+ # On top of the collections, you have the complete URL that a given action
344
+ # redirected to available in `redirect_to_url`.
324
345
  #
325
- # For redirects within the same controller, you can even call follow_redirect and the redirect will be followed, triggering another
326
- # action call which can then be asserted against.
346
+ # For redirects within the same controller, you can even call follow_redirect
347
+ # and the redirect will be followed, triggering another action call which can
348
+ # then be asserted against.
327
349
  #
328
- # == Manipulating session and cookie variables
350
+ # ## Manipulating session and cookie variables
329
351
  #
330
- # Sometimes you need to set up the session and cookie variables for a test.
331
- # To do this just assign a value to the session or cookie collection:
352
+ # Sometimes you need to set up the session and cookie variables for a test. To
353
+ # do this just assign a value to the session or cookie collection:
332
354
  #
333
- # session[:key] = "value"
334
- # cookies[:key] = "value"
355
+ # session[:key] = "value"
356
+ # cookies[:key] = "value"
335
357
  #
336
358
  # To clear the cookies for a test just clear the cookie collection:
337
359
  #
338
- # cookies.clear
360
+ # cookies.clear
339
361
  #
340
- # == \Testing named routes
362
+ # ## Testing named routes
341
363
  #
342
- # If you're using named routes, they can be easily tested using the original named routes' methods straight in the test case.
364
+ # If you're using named routes, they can be easily tested using the original
365
+ # named routes' methods straight in the test case.
343
366
  #
344
- # assert_redirected_to page_url(title: 'foo')
367
+ # assert_redirected_to page_url(title: 'foo')
345
368
  class TestCase < ActiveSupport::TestCase
346
369
  singleton_class.attr_accessor :executor_around_each_request
347
370
 
@@ -354,12 +377,12 @@ module ActionController
354
377
  attr_reader :response, :request
355
378
 
356
379
  module ClassMethods
357
- # Sets the controller class name. Useful if the name can't be inferred from test class.
358
- # Normalizes +controller_class+ before using.
380
+ # Sets the controller class name. Useful if the name can't be inferred from test
381
+ # class. Normalizes `controller_class` before using.
359
382
  #
360
- # tests WidgetController
361
- # tests :widget
362
- # tests 'widget'
383
+ # tests WidgetController
384
+ # tests :widget
385
+ # tests 'widget'
363
386
  def tests(controller_class)
364
387
  case controller_class
365
388
  when String, Symbol
@@ -392,92 +415,97 @@ module ActionController
392
415
 
393
416
  # Simulate a GET request with the given parameters.
394
417
  #
395
- # - +action+: The controller action to call.
396
- # - +params+: The hash with HTTP parameters that you want to pass. This may be +nil+.
397
- # - +body+: The request body with a string that is appropriately encoded
398
- # (<tt>application/x-www-form-urlencoded</tt> or <tt>multipart/form-data</tt>).
399
- # - +session+: A hash of parameters to store in the session. This may be +nil+.
400
- # - +flash+: A hash of parameters to store in the flash. This may be +nil+.
418
+ # * `action`: The controller action to call.
419
+ # * `params`: The hash with HTTP parameters that you want to pass. This may be
420
+ # `nil`.
421
+ # * `body`: The request body with a string that is appropriately encoded
422
+ # (`application/x-www-form-urlencoded` or `multipart/form-data`).
423
+ # * `session`: A hash of parameters to store in the session. This may be
424
+ # `nil`.
425
+ # * `flash`: A hash of parameters to store in the flash. This may be `nil`.
401
426
  #
402
- # You can also simulate POST, PATCH, PUT, DELETE, and HEAD requests with
403
- # +post+, +patch+, +put+, +delete+, and +head+.
404
- # Example sending parameters, session, and setting a flash message:
405
427
  #
406
- # get :show,
407
- # params: { id: 7 },
408
- # session: { user_id: 1 },
409
- # flash: { notice: 'This is flash message' }
428
+ # You can also simulate POST, PATCH, PUT, DELETE, and HEAD requests with `post`,
429
+ # `patch`, `put`, `delete`, and `head`. Example sending parameters, session, and
430
+ # setting a flash message:
431
+ #
432
+ # get :show,
433
+ # params: { id: 7 },
434
+ # session: { user_id: 1 },
435
+ # flash: { notice: 'This is flash message' }
410
436
  #
411
437
  # Note that the request method is not verified. The different methods are
412
438
  # available to make the tests more expressive.
413
439
  def get(action, **args)
414
- res = process(action, method: "GET", **args)
415
- cookies.update res.cookies
416
- res
440
+ process(action, method: "GET", **args)
417
441
  end
418
442
 
419
443
  # Simulate a POST request with the given parameters and set/volley the response.
420
- # See +get+ for more details.
444
+ # See `get` for more details.
421
445
  def post(action, **args)
422
446
  process(action, method: "POST", **args)
423
447
  end
424
448
 
425
- # Simulate a PATCH request with the given parameters and set/volley the response.
426
- # See +get+ for more details.
449
+ # Simulate a PATCH request with the given parameters and set/volley the
450
+ # response. See `get` for more details.
427
451
  def patch(action, **args)
428
452
  process(action, method: "PATCH", **args)
429
453
  end
430
454
 
431
455
  # Simulate a PUT request with the given parameters and set/volley the response.
432
- # See +get+ for more details.
456
+ # See `get` for more details.
433
457
  def put(action, **args)
434
458
  process(action, method: "PUT", **args)
435
459
  end
436
460
 
437
- # Simulate a DELETE request with the given parameters and set/volley the response.
438
- # See +get+ for more details.
461
+ # Simulate a DELETE request with the given parameters and set/volley the
462
+ # response. See `get` for more details.
439
463
  def delete(action, **args)
440
464
  process(action, method: "DELETE", **args)
441
465
  end
442
466
 
443
467
  # Simulate a HEAD request with the given parameters and set/volley the response.
444
- # See +get+ for more details.
468
+ # See `get` for more details.
445
469
  def head(action, **args)
446
470
  process(action, method: "HEAD", **args)
447
471
  end
448
472
 
449
- # Simulate an HTTP request to +action+ by specifying request method,
450
- # parameters and set/volley the response.
473
+ # Simulate an HTTP request to `action` by specifying request method, parameters
474
+ # and set/volley the response.
475
+ #
476
+ # * `action`: The controller action to call.
477
+ # * `method`: Request method used to send the HTTP request. Possible values
478
+ # are `GET`, `POST`, `PATCH`, `PUT`, `DELETE`, `HEAD`. Defaults to `GET`.
479
+ # Can be a symbol.
480
+ # * `params`: The hash with HTTP parameters that you want to pass. This may be
481
+ # `nil`.
482
+ # * `body`: The request body with a string that is appropriately encoded
483
+ # (`application/x-www-form-urlencoded` or `multipart/form-data`).
484
+ # * `session`: A hash of parameters to store in the session. This may be
485
+ # `nil`.
486
+ # * `flash`: A hash of parameters to store in the flash. This may be `nil`.
487
+ # * `format`: Request format. Defaults to `nil`. Can be string or symbol.
488
+ # * `as`: Content type. Defaults to `nil`. Must be a symbol that corresponds
489
+ # to a mime type.
451
490
  #
452
- # - +action+: The controller action to call.
453
- # - +method+: Request method used to send the HTTP request. Possible values
454
- # are +GET+, +POST+, +PATCH+, +PUT+, +DELETE+, +HEAD+. Defaults to +GET+. Can be a symbol.
455
- # - +params+: The hash with HTTP parameters that you want to pass. This may be +nil+.
456
- # - +body+: The request body with a string that is appropriately encoded
457
- # (<tt>application/x-www-form-urlencoded</tt> or <tt>multipart/form-data</tt>).
458
- # - +session+: A hash of parameters to store in the session. This may be +nil+.
459
- # - +flash+: A hash of parameters to store in the flash. This may be +nil+.
460
- # - +format+: Request format. Defaults to +nil+. Can be string or symbol.
461
- # - +as+: Content type. Defaults to +nil+. Must be a symbol that corresponds
462
- # to a mime type.
463
491
  #
464
- # Example calling +create+ action and sending two params:
492
+ # Example calling `create` action and sending two params:
465
493
  #
466
- # process :create,
467
- # method: 'POST',
468
- # params: {
469
- # user: { name: 'Gaurish Sharma', email: 'user@example.com' }
470
- # },
471
- # session: { user_id: 1 },
472
- # flash: { notice: 'This is flash message' }
494
+ # process :create,
495
+ # method: 'POST',
496
+ # params: {
497
+ # user: { name: 'Gaurish Sharma', email: 'user@example.com' }
498
+ # },
499
+ # session: { user_id: 1 },
500
+ # flash: { notice: 'This is flash message' }
473
501
  #
474
- # To simulate +GET+, +POST+, +PATCH+, +PUT+, +DELETE+, and +HEAD+ requests
475
- # prefer using #get, #post, #patch, #put, #delete and #head methods
476
- # respectively which will make tests more expressive.
502
+ # To simulate `GET`, `POST`, `PATCH`, `PUT`, `DELETE`, and `HEAD` requests
503
+ # prefer using #get, #post, #patch, #put, #delete and #head methods respectively
504
+ # which will make tests more expressive.
477
505
  #
478
506
  # It's not recommended to make more than one request in the same test. Instance
479
507
  # variables that are set in one request will not persist to the next request,
480
- # but it's not guaranteed that all \Rails internal state will be reset. Prefer
508
+ # but it's not guaranteed that all Rails internal state will be reset. Prefer
481
509
  # ActionDispatch::IntegrationTest for making multiple requests in the same test.
482
510
  #
483
511
  # Note that the request method is not verified.
@@ -617,6 +645,7 @@ module ActionController
617
645
  unless @request.cookie_jar.committed?
618
646
  @request.cookie_jar.write(@response)
619
647
  cookies.update(@request.cookie_jar.instance_variable_get(:@cookies))
648
+ cookies.update(@response.cookies)
620
649
  end
621
650
  end
622
651
  @response.prepare!
@@ -654,8 +683,8 @@ module ActionController
654
683
  end
655
684
 
656
685
  def check_required_ivars
657
- # Check for required instance variables so we can give an
658
- # understandable error message.
686
+ # Check for required instance variables so we can give an understandable error
687
+ # message.
659
688
  [:@routes, :@controller, :@request, :@response].each do |iv_name|
660
689
  if !instance_variable_defined?(iv_name) || instance_variable_get(iv_name).nil?
661
690
  raise "#{iv_name} is nil: make sure you set it in your test's setup method."
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  require "abstract_controller"
4
6
  require "action_dispatch"
5
7
  require "action_controller/deprecator"
6
8
  require "action_controller/metal/strong_parameters"
7
9
  require "action_controller/metal/exceptions"
8
10
 
9
- # = Action Controller
11
+ # # Action Controller
10
12
  #
11
13
  # Action Controller is a module of Action Pack.
12
14
  #
@@ -27,6 +29,7 @@ module ActionController
27
29
  end
28
30
 
29
31
  autoload_under "metal" do
32
+ autoload :AllowBrowser
30
33
  autoload :ConditionalGet
31
34
  autoload :ContentSecurityPolicy
32
35
  autoload :Cookies
@@ -46,6 +49,7 @@ module ActionController
46
49
  autoload :Logging
47
50
  autoload :MimeResponds
48
51
  autoload :ParamsWrapper
52
+ autoload :RateLimiting
49
53
  autoload :Redirecting
50
54
  autoload :Renderers
51
55
  autoload :Rendering
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  require "rack/version"
4
6
 
5
7
  module ActionDispatch
@@ -28,5 +30,11 @@ module ActionDispatch
28
30
  SERVER_TIMING = "server-timing"
29
31
  STRICT_TRANSPORT_SECURITY = "strict-transport-security"
30
32
  end
33
+
34
+ if Gem::Version.new(Rack::RELEASE) < Gem::Version.new("3.1")
35
+ UNPROCESSABLE_CONTENT = :unprocessable_entity
36
+ else
37
+ UNPROCESSABLE_CONTENT = :unprocessable_content
38
+ end
31
39
  end
32
40
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionDispatch
4
6
  def self.deprecator # :nodoc:
5
7
  @deprecator ||= ActiveSupport::Deprecation.new