actionpack 7.1.3.2 → 7.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack might be problematic. Click here for more details.

Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +70 -530
  3. data/lib/abstract_controller/asset_paths.rb +2 -0
  4. data/lib/abstract_controller/base.rb +102 -98
  5. data/lib/abstract_controller/caching/fragments.rb +50 -53
  6. data/lib/abstract_controller/caching.rb +2 -0
  7. data/lib/abstract_controller/callbacks.rb +66 -64
  8. data/lib/abstract_controller/collector.rb +6 -6
  9. data/lib/abstract_controller/deprecator.rb +2 -0
  10. data/lib/abstract_controller/error.rb +2 -0
  11. data/lib/abstract_controller/helpers.rb +70 -85
  12. data/lib/abstract_controller/logger.rb +2 -0
  13. data/lib/abstract_controller/railties/routes_helpers.rb +2 -0
  14. data/lib/abstract_controller/rendering.rb +13 -12
  15. data/lib/abstract_controller/translation.rb +11 -10
  16. data/lib/abstract_controller/url_for.rb +8 -6
  17. data/lib/abstract_controller.rb +2 -0
  18. data/lib/action_controller/api/api_rendering.rb +2 -0
  19. data/lib/action_controller/api.rb +74 -72
  20. data/lib/action_controller/base.rb +155 -117
  21. data/lib/action_controller/caching.rb +15 -12
  22. data/lib/action_controller/deprecator.rb +2 -0
  23. data/lib/action_controller/form_builder.rb +20 -17
  24. data/lib/action_controller/log_subscriber.rb +3 -1
  25. data/lib/action_controller/metal/allow_browser.rb +119 -0
  26. data/lib/action_controller/metal/basic_implicit_render.rb +2 -0
  27. data/lib/action_controller/metal/conditional_get.rb +188 -174
  28. data/lib/action_controller/metal/content_security_policy.rb +25 -24
  29. data/lib/action_controller/metal/cookies.rb +4 -2
  30. data/lib/action_controller/metal/data_streaming.rb +64 -55
  31. data/lib/action_controller/metal/default_headers.rb +5 -3
  32. data/lib/action_controller/metal/etag_with_flash.rb +3 -1
  33. data/lib/action_controller/metal/etag_with_template_digest.rb +17 -15
  34. data/lib/action_controller/metal/exceptions.rb +11 -9
  35. data/lib/action_controller/metal/flash.rb +12 -10
  36. data/lib/action_controller/metal/head.rb +12 -10
  37. data/lib/action_controller/metal/helpers.rb +63 -55
  38. data/lib/action_controller/metal/http_authentication.rb +209 -201
  39. data/lib/action_controller/metal/implicit_render.rb +17 -15
  40. data/lib/action_controller/metal/instrumentation.rb +15 -12
  41. data/lib/action_controller/metal/live.rb +113 -107
  42. data/lib/action_controller/metal/logging.rb +6 -4
  43. data/lib/action_controller/metal/mime_responds.rb +151 -142
  44. data/lib/action_controller/metal/parameter_encoding.rb +34 -32
  45. data/lib/action_controller/metal/params_wrapper.rb +57 -59
  46. data/lib/action_controller/metal/permissions_policy.rb +13 -12
  47. data/lib/action_controller/metal/rate_limiting.rb +62 -0
  48. data/lib/action_controller/metal/redirecting.rb +108 -82
  49. data/lib/action_controller/metal/renderers.rb +50 -49
  50. data/lib/action_controller/metal/rendering.rb +103 -75
  51. data/lib/action_controller/metal/request_forgery_protection.rb +162 -133
  52. data/lib/action_controller/metal/rescue.rb +11 -9
  53. data/lib/action_controller/metal/streaming.rb +138 -136
  54. data/lib/action_controller/metal/strong_parameters.rb +525 -480
  55. data/lib/action_controller/metal/testing.rb +2 -0
  56. data/lib/action_controller/metal/url_for.rb +17 -15
  57. data/lib/action_controller/metal.rb +58 -57
  58. data/lib/action_controller/railtie.rb +3 -0
  59. data/lib/action_controller/railties/helpers.rb +2 -0
  60. data/lib/action_controller/renderer.rb +42 -36
  61. data/lib/action_controller/template_assertions.rb +4 -2
  62. data/lib/action_controller/test_case.rb +146 -126
  63. data/lib/action_controller.rb +10 -3
  64. data/lib/action_dispatch/constants.rb +2 -0
  65. data/lib/action_dispatch/deprecator.rb +2 -0
  66. data/lib/action_dispatch/http/cache.rb +27 -26
  67. data/lib/action_dispatch/http/content_disposition.rb +2 -0
  68. data/lib/action_dispatch/http/content_security_policy.rb +44 -38
  69. data/lib/action_dispatch/http/filter_parameters.rb +9 -5
  70. data/lib/action_dispatch/http/filter_redirect.rb +15 -1
  71. data/lib/action_dispatch/http/headers.rb +22 -22
  72. data/lib/action_dispatch/http/mime_negotiation.rb +30 -41
  73. data/lib/action_dispatch/http/mime_type.rb +29 -22
  74. data/lib/action_dispatch/http/mime_types.rb +2 -0
  75. data/lib/action_dispatch/http/parameters.rb +11 -9
  76. data/lib/action_dispatch/http/permissions_policy.rb +20 -37
  77. data/lib/action_dispatch/http/rack_cache.rb +2 -0
  78. data/lib/action_dispatch/http/request.rb +71 -71
  79. data/lib/action_dispatch/http/response.rb +61 -61
  80. data/lib/action_dispatch/http/upload.rb +18 -16
  81. data/lib/action_dispatch/http/url.rb +75 -73
  82. data/lib/action_dispatch/journey/formatter.rb +13 -6
  83. data/lib/action_dispatch/journey/gtg/builder.rb +4 -3
  84. data/lib/action_dispatch/journey/gtg/simulator.rb +2 -0
  85. data/lib/action_dispatch/journey/gtg/transition_table.rb +10 -8
  86. data/lib/action_dispatch/journey/nfa/dot.rb +2 -0
  87. data/lib/action_dispatch/journey/nodes/node.rb +6 -5
  88. data/lib/action_dispatch/journey/parser.rb +4 -3
  89. data/lib/action_dispatch/journey/parser_extras.rb +2 -0
  90. data/lib/action_dispatch/journey/path/pattern.rb +4 -1
  91. data/lib/action_dispatch/journey/route.rb +9 -7
  92. data/lib/action_dispatch/journey/router/utils.rb +16 -15
  93. data/lib/action_dispatch/journey/router.rb +4 -2
  94. data/lib/action_dispatch/journey/routes.rb +4 -2
  95. data/lib/action_dispatch/journey/scanner.rb +4 -2
  96. data/lib/action_dispatch/journey/visitors.rb +2 -0
  97. data/lib/action_dispatch/journey.rb +2 -0
  98. data/lib/action_dispatch/log_subscriber.rb +2 -0
  99. data/lib/action_dispatch/middleware/actionable_exceptions.rb +2 -0
  100. data/lib/action_dispatch/middleware/assume_ssl.rb +8 -5
  101. data/lib/action_dispatch/middleware/callbacks.rb +3 -1
  102. data/lib/action_dispatch/middleware/cookies.rb +119 -104
  103. data/lib/action_dispatch/middleware/debug_exceptions.rb +13 -5
  104. data/lib/action_dispatch/middleware/debug_locks.rb +15 -13
  105. data/lib/action_dispatch/middleware/debug_view.rb +2 -0
  106. data/lib/action_dispatch/middleware/exception_wrapper.rb +6 -11
  107. data/lib/action_dispatch/middleware/executor.rb +8 -0
  108. data/lib/action_dispatch/middleware/flash.rb +63 -51
  109. data/lib/action_dispatch/middleware/host_authorization.rb +17 -15
  110. data/lib/action_dispatch/middleware/public_exceptions.rb +8 -6
  111. data/lib/action_dispatch/middleware/reloader.rb +5 -3
  112. data/lib/action_dispatch/middleware/remote_ip.rb +77 -72
  113. data/lib/action_dispatch/middleware/request_id.rb +14 -9
  114. data/lib/action_dispatch/middleware/server_timing.rb +4 -2
  115. data/lib/action_dispatch/middleware/session/abstract_store.rb +2 -0
  116. data/lib/action_dispatch/middleware/session/cache_store.rb +13 -8
  117. data/lib/action_dispatch/middleware/session/cookie_store.rb +27 -26
  118. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +7 -3
  119. data/lib/action_dispatch/middleware/show_exceptions.rb +31 -21
  120. data/lib/action_dispatch/middleware/ssl.rb +43 -40
  121. data/lib/action_dispatch/middleware/stack.rb +11 -10
  122. data/lib/action_dispatch/middleware/static.rb +33 -31
  123. data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +1 -1
  124. data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +1 -1
  125. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +1 -1
  126. data/lib/action_dispatch/railtie.rb +2 -4
  127. data/lib/action_dispatch/request/session.rb +23 -21
  128. data/lib/action_dispatch/request/utils.rb +2 -0
  129. data/lib/action_dispatch/routing/endpoint.rb +2 -0
  130. data/lib/action_dispatch/routing/inspector.rb +5 -3
  131. data/lib/action_dispatch/routing/mapper.rb +670 -635
  132. data/lib/action_dispatch/routing/polymorphic_routes.rb +69 -62
  133. data/lib/action_dispatch/routing/redirection.rb +37 -32
  134. data/lib/action_dispatch/routing/route_set.rb +59 -45
  135. data/lib/action_dispatch/routing/routes_proxy.rb +6 -4
  136. data/lib/action_dispatch/routing/url_for.rb +130 -125
  137. data/lib/action_dispatch/routing.rb +150 -148
  138. data/lib/action_dispatch/system_test_case.rb +91 -81
  139. data/lib/action_dispatch/system_testing/browser.rb +10 -3
  140. data/lib/action_dispatch/system_testing/driver.rb +3 -1
  141. data/lib/action_dispatch/system_testing/server.rb +2 -0
  142. data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +32 -21
  143. data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +2 -0
  144. data/lib/action_dispatch/testing/assertion_response.rb +8 -6
  145. data/lib/action_dispatch/testing/assertions/response.rb +26 -23
  146. data/lib/action_dispatch/testing/assertions/routing.rb +153 -84
  147. data/lib/action_dispatch/testing/assertions.rb +2 -0
  148. data/lib/action_dispatch/testing/integration.rb +223 -222
  149. data/lib/action_dispatch/testing/request_encoder.rb +2 -0
  150. data/lib/action_dispatch/testing/test_helpers/page_dump_helper.rb +35 -0
  151. data/lib/action_dispatch/testing/test_process.rb +12 -8
  152. data/lib/action_dispatch/testing/test_request.rb +3 -1
  153. data/lib/action_dispatch/testing/test_response.rb +27 -26
  154. data/lib/action_dispatch.rb +22 -28
  155. data/lib/action_pack/gem_version.rb +6 -4
  156. data/lib/action_pack/version.rb +3 -1
  157. data/lib/action_pack.rb +17 -16
  158. metadata +30 -13
@@ -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,10 +18,10 @@ 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.
23
25
  silence_redefinition_of_method :new_controller_thread
24
26
  def new_controller_thread # :nodoc:
25
27
  yield
@@ -29,8 +31,8 @@ module ActionController
29
31
  Buffer.queue_size = nil
30
32
  end
31
33
 
32
- # ActionController::TestCase will be deprecated and moved to a gem in the future.
33
- # Please use ActionDispatch::IntegrationTest going forward.
34
+ # ActionController::TestCase will be deprecated and moved to a gem in the
35
+ # future. Please use ActionDispatch::IntegrationTest going forward.
34
36
  class TestRequest < ActionDispatch::TestRequest # :nodoc:
35
37
  DEFAULT_ENV = ActionDispatch::TestRequest::DEFAULT_ENV.dup
36
38
  DEFAULT_ENV.delete "PATH_INFO"
@@ -232,116 +234,127 @@ module ActionController
232
234
  end
233
235
  end
234
236
 
235
- # = Action Controller Test Case
237
+ # # Action Controller Test Case
236
238
  #
237
- # Superclass for ActionController functional tests. Functional tests allow you to
238
- # test a single controller action per test method.
239
+ # Superclass for ActionController functional tests. Functional tests allow you
240
+ # to test a single controller action per test method.
239
241
  #
240
- # == Use integration style controller tests over functional style controller tests.
242
+ # ## Use integration style controller tests over functional style controller tests.
241
243
  #
242
- # \Rails discourages the use of functional tests in favor of integration tests
244
+ # Rails discourages the use of functional tests in favor of integration tests
243
245
  # (use ActionDispatch::IntegrationTest).
244
246
  #
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.
247
+ # New Rails applications no longer generate functional style controller tests
248
+ # and they should only be used for backward compatibility. Integration style
249
+ # controller tests perform actual requests, whereas functional style controller
250
+ # tests merely simulate a request. Besides, integration tests are as fast as
251
+ # functional tests and provide lot of helpers such as `as`, `parsed_body` for
252
+ # effective testing of controller actions including even API endpoints.
250
253
  #
251
- # == Basic example
254
+ # ## Basic example
252
255
  #
253
256
  # 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.
257
+ # 1. First, one uses the `get`, `post`, `patch`, `put`, `delete`, or `head`
258
+ # method to simulate an HTTP request.
259
+ # 2. Then, one asserts whether the current state is as expected. "State" can be
260
+ # anything: the controller's HTTP response, the database contents, etc.
261
+ #
258
262
  #
259
263
  # For example:
260
264
  #
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" }})
265
+ # class BooksControllerTest < ActionController::TestCase
266
+ # def test_create
267
+ # # Simulate a POST response with the given HTTP parameters.
268
+ # post(:create, params: { book: { title: "Love Hina" }})
265
269
  #
266
- # # Asserts that the controller tried to redirect us to
267
- # # the created book's URI.
268
- # assert_response :found
270
+ # # Asserts that the controller tried to redirect us to
271
+ # # the created book's URI.
272
+ # assert_response :found
269
273
  #
270
- # # Asserts that the controller really put the book in the database.
271
- # assert_not_nil Book.find_by(title: "Love Hina")
274
+ # # Asserts that the controller really put the book in the database.
275
+ # assert_not_nil Book.find_by(title: "Love Hina")
276
+ # end
272
277
  # end
273
- # end
274
278
  #
275
279
  # You can also send a real document in the simulated HTTP request.
276
280
  #
277
- # def test_create
278
- # json = {book: { title: "Love Hina" }}.to_json
279
- # post :create, body: json
280
- # end
281
+ # def test_create
282
+ # json = {book: { title: "Love Hina" }}.to_json
283
+ # post :create, body: json
284
+ # end
285
+ #
286
+ # ## Special instance variables
281
287
  #
282
- # == Special instance variables
288
+ # ActionController::TestCase will also automatically provide the following
289
+ # instance variables for use in the tests:
283
290
  #
284
- # ActionController::TestCase will also automatically provide the following instance
285
- # variables for use in the tests:
291
+ # @controller
292
+ # : The controller instance that will be tested.
286
293
  #
287
- # <b>@controller</b>::
288
- # The controller instance that will be tested.
289
- # <b>@request</b>::
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
- # <b>@response</b>::
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.
294
+ # @request
295
+ # : An ActionController::TestRequest, representing the current HTTP request.
296
+ # You can modify this object before sending the HTTP request. For example,
297
+ # you might want to set some session properties before sending a GET
298
+ # request.
298
299
  #
299
- # == Controller is automatically inferred
300
+ # @response
301
+ # : An ActionDispatch::TestResponse object, representing the response of the
302
+ # last HTTP response. In the above example, `@response` becomes valid after
303
+ # calling `post`. If the various assert methods are not sufficient, then you
304
+ # may use this object to inspect the HTTP response in detail.
305
+ #
306
+ #
307
+ # ## Controller is automatically inferred
300
308
  #
301
309
  # ActionController::TestCase will automatically infer the controller under test
302
310
  # from the test class name. If the controller cannot be inferred from the test
303
- # class name, you can explicitly set it with +tests+.
311
+ # class name, you can explicitly set it with `tests`.
312
+ #
313
+ # class SpecialEdgeCaseWidgetsControllerTest < ActionController::TestCase
314
+ # tests WidgetController
315
+ # end
304
316
  #
305
- # class SpecialEdgeCaseWidgetsControllerTest < ActionController::TestCase
306
- # tests WidgetController
307
- # end
317
+ # ## Testing controller internals
308
318
  #
309
- # == \Testing controller internals
319
+ # In addition to these specific assertions, you also have easy access to various
320
+ # collections that the regular test/unit assertions can be used against. These
321
+ # collections are:
310
322
  #
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:
323
+ # * session: Objects being saved in the session.
324
+ # * flash: The flash objects currently in the session.
325
+ # * cookies: Cookies being sent to the user on this request.
313
326
  #
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
327
  #
318
328
  # These collections can be used just like any other hash:
319
329
  #
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
330
+ # assert_equal "Dave", cookies[:name] # makes sure that a cookie called :name was set as "Dave"
331
+ # assert flash.empty? # makes sure that there's nothing in the flash
322
332
  #
323
- # On top of the collections, you have the complete URL that a given action redirected to available in <tt>redirect_to_url</tt>.
333
+ # On top of the collections, you have the complete URL that a given action
334
+ # redirected to available in `redirect_to_url`.
324
335
  #
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.
336
+ # For redirects within the same controller, you can even call follow_redirect
337
+ # and the redirect will be followed, triggering another action call which can
338
+ # then be asserted against.
327
339
  #
328
- # == Manipulating session and cookie variables
340
+ # ## Manipulating session and cookie variables
329
341
  #
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:
342
+ # Sometimes you need to set up the session and cookie variables for a test. To
343
+ # do this just assign a value to the session or cookie collection:
332
344
  #
333
- # session[:key] = "value"
334
- # cookies[:key] = "value"
345
+ # session[:key] = "value"
346
+ # cookies[:key] = "value"
335
347
  #
336
348
  # To clear the cookies for a test just clear the cookie collection:
337
349
  #
338
- # cookies.clear
350
+ # cookies.clear
339
351
  #
340
- # == \Testing named routes
352
+ # ## Testing named routes
341
353
  #
342
- # If you're using named routes, they can be easily tested using the original named routes' methods straight in the test case.
354
+ # If you're using named routes, they can be easily tested using the original
355
+ # named routes' methods straight in the test case.
343
356
  #
344
- # assert_redirected_to page_url(title: 'foo')
357
+ # assert_redirected_to page_url(title: 'foo')
345
358
  class TestCase < ActiveSupport::TestCase
346
359
  singleton_class.attr_accessor :executor_around_each_request
347
360
 
@@ -354,12 +367,12 @@ module ActionController
354
367
  attr_reader :response, :request
355
368
 
356
369
  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.
370
+ # Sets the controller class name. Useful if the name can't be inferred from test
371
+ # class. Normalizes `controller_class` before using.
359
372
  #
360
- # tests WidgetController
361
- # tests :widget
362
- # tests 'widget'
373
+ # tests WidgetController
374
+ # tests :widget
375
+ # tests 'widget'
363
376
  def tests(controller_class)
364
377
  case controller_class
365
378
  when String, Symbol
@@ -392,21 +405,24 @@ module ActionController
392
405
 
393
406
  # Simulate a GET request with the given parameters.
394
407
  #
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+.
408
+ # * `action`: The controller action to call.
409
+ # * `params`: The hash with HTTP parameters that you want to pass. This may be
410
+ # `nil`.
411
+ # * `body`: The request body with a string that is appropriately encoded
412
+ # (`application/x-www-form-urlencoded` or `multipart/form-data`).
413
+ # * `session`: A hash of parameters to store in the session. This may be
414
+ # `nil`.
415
+ # * `flash`: A hash of parameters to store in the flash. This may be `nil`.
416
+ #
401
417
  #
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:
418
+ # You can also simulate POST, PATCH, PUT, DELETE, and HEAD requests with `post`,
419
+ # `patch`, `put`, `delete`, and `head`. Example sending parameters, session, and
420
+ # setting a flash message:
405
421
  #
406
- # get :show,
407
- # params: { id: 7 },
408
- # session: { user_id: 1 },
409
- # flash: { notice: 'This is flash message' }
422
+ # get :show,
423
+ # params: { id: 7 },
424
+ # session: { user_id: 1 },
425
+ # flash: { notice: 'This is flash message' }
410
426
  #
411
427
  # Note that the request method is not verified. The different methods are
412
428
  # available to make the tests more expressive.
@@ -417,67 +433,71 @@ module ActionController
417
433
  end
418
434
 
419
435
  # Simulate a POST request with the given parameters and set/volley the response.
420
- # See +get+ for more details.
436
+ # See `get` for more details.
421
437
  def post(action, **args)
422
438
  process(action, method: "POST", **args)
423
439
  end
424
440
 
425
- # Simulate a PATCH request with the given parameters and set/volley the response.
426
- # See +get+ for more details.
441
+ # Simulate a PATCH request with the given parameters and set/volley the
442
+ # response. See `get` for more details.
427
443
  def patch(action, **args)
428
444
  process(action, method: "PATCH", **args)
429
445
  end
430
446
 
431
447
  # Simulate a PUT request with the given parameters and set/volley the response.
432
- # See +get+ for more details.
448
+ # See `get` for more details.
433
449
  def put(action, **args)
434
450
  process(action, method: "PUT", **args)
435
451
  end
436
452
 
437
- # Simulate a DELETE request with the given parameters and set/volley the response.
438
- # See +get+ for more details.
453
+ # Simulate a DELETE request with the given parameters and set/volley the
454
+ # response. See `get` for more details.
439
455
  def delete(action, **args)
440
456
  process(action, method: "DELETE", **args)
441
457
  end
442
458
 
443
459
  # Simulate a HEAD request with the given parameters and set/volley the response.
444
- # See +get+ for more details.
460
+ # See `get` for more details.
445
461
  def head(action, **args)
446
462
  process(action, method: "HEAD", **args)
447
463
  end
448
464
 
449
- # Simulate an HTTP request to +action+ by specifying request method,
450
- # parameters and set/volley the response.
465
+ # Simulate an HTTP request to `action` by specifying request method, parameters
466
+ # and set/volley the response.
467
+ #
468
+ # * `action`: The controller action to call.
469
+ # * `method`: Request method used to send the HTTP request. Possible values
470
+ # are `GET`, `POST`, `PATCH`, `PUT`, `DELETE`, `HEAD`. Defaults to `GET`.
471
+ # Can be a symbol.
472
+ # * `params`: The hash with HTTP parameters that you want to pass. This may be
473
+ # `nil`.
474
+ # * `body`: The request body with a string that is appropriately encoded
475
+ # (`application/x-www-form-urlencoded` or `multipart/form-data`).
476
+ # * `session`: A hash of parameters to store in the session. This may be
477
+ # `nil`.
478
+ # * `flash`: A hash of parameters to store in the flash. This may be `nil`.
479
+ # * `format`: Request format. Defaults to `nil`. Can be string or symbol.
480
+ # * `as`: Content type. Defaults to `nil`. Must be a symbol that corresponds
481
+ # to a mime type.
451
482
  #
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
483
  #
464
- # Example calling +create+ action and sending two params:
484
+ # Example calling `create` action and sending two params:
465
485
  #
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' }
486
+ # process :create,
487
+ # method: 'POST',
488
+ # params: {
489
+ # user: { name: 'Gaurish Sharma', email: 'user@example.com' }
490
+ # },
491
+ # session: { user_id: 1 },
492
+ # flash: { notice: 'This is flash message' }
473
493
  #
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.
494
+ # To simulate `GET`, `POST`, `PATCH`, `PUT`, `DELETE`, and `HEAD` requests
495
+ # prefer using #get, #post, #patch, #put, #delete and #head methods respectively
496
+ # which will make tests more expressive.
477
497
  #
478
498
  # It's not recommended to make more than one request in the same test. Instance
479
499
  # 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
500
+ # but it's not guaranteed that all Rails internal state will be reset. Prefer
481
501
  # ActionDispatch::IntegrationTest for making multiple requests in the same test.
482
502
  #
483
503
  # Note that the request method is not verified.
@@ -654,8 +674,8 @@ module ActionController
654
674
  end
655
675
 
656
676
  def check_required_ivars
657
- # Check for required instance variables so we can give an
658
- # understandable error message.
677
+ # Check for required instance variables so we can give an understandable error
678
+ # message.
659
679
  [:@routes, :@controller, :@request, :@response].each do |iv_name|
660
680
  if !instance_variable_defined?(iv_name) || instance_variable_get(iv_name).nil?
661
681
  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
@@ -62,8 +66,11 @@ module ActionController
62
66
  autoload :ApiRendering
63
67
  end
64
68
 
65
- autoload :TestCase, "action_controller/test_case"
66
- autoload :TemplateAssertions, "action_controller/test_case"
69
+ autoload_at "action_controller/test_case" do
70
+ autoload :TestCase
71
+ autoload :TestRequest
72
+ autoload :TemplateAssertions
73
+ end
67
74
  end
68
75
 
69
76
  # Common Active Support usage in Action Controller
@@ -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
@@ -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
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionDispatch
4
6
  module Http
5
7
  module Cache
@@ -32,8 +34,8 @@ module ActionDispatch
32
34
  end
33
35
  end
34
36
 
35
- # Check response freshness (+Last-Modified+ and ETag) against request
36
- # +If-Modified-Since+ and +If-None-Match+ conditions. If both headers are
37
+ # Check response freshness (`Last-Modified` and ETag) against request
38
+ # `If-Modified-Since` and `If-None-Match` conditions. If both headers are
37
39
  # supplied, both must match, or the request is not considered fresh.
38
40
  def fresh?(response)
39
41
  last_modified = if_modified_since
@@ -79,25 +81,24 @@ module ActionDispatch
79
81
  set_header DATE, utc_time.httpdate
80
82
  end
81
83
 
82
- # This method sets a weak ETag validator on the response so browsers
83
- # and proxies may cache the response, keyed on the ETag. On subsequent
84
- # requests, the +If-None-Match+ header is set to the cached ETag. If it
85
- # matches the current ETag, we can return a <tt>304 Not Modified</tt> response
86
- # with no body, letting the browser or proxy know that their cache is
87
- # current. Big savings in request time and network bandwidth.
84
+ # This method sets a weak ETag validator on the response so browsers and proxies
85
+ # may cache the response, keyed on the ETag. On subsequent requests, the
86
+ # `If-None-Match` header is set to the cached ETag. If it matches the current
87
+ # ETag, we can return a `304 Not Modified` response with no body, letting the
88
+ # browser or proxy know that their cache is current. Big savings in request time
89
+ # and network bandwidth.
88
90
  #
89
- # Weak ETags are considered to be semantically equivalent but not
90
- # byte-for-byte identical. This is perfect for browser caching of HTML
91
- # pages where we don't care about exact equality, just what the user
92
- # is viewing.
91
+ # Weak ETags are considered to be semantically equivalent but not byte-for-byte
92
+ # identical. This is perfect for browser caching of HTML pages where we don't
93
+ # care about exact equality, just what the user is viewing.
93
94
  #
94
- # Strong ETags are considered byte-for-byte identical. They allow a
95
- # browser or proxy cache to support +Range+ requests, useful for paging
96
- # through a PDF file or scrubbing through a video. Some CDNs only
97
- # support strong ETags and will ignore weak ETags entirely.
95
+ # Strong ETags are considered byte-for-byte identical. They allow a browser or
96
+ # proxy cache to support `Range` requests, useful for paging through a PDF file
97
+ # or scrubbing through a video. Some CDNs only support strong ETags and will
98
+ # ignore weak ETags entirely.
98
99
  #
99
- # Weak ETags are what we almost always need, so they're the default.
100
- # Check out #strong_etag= to provide a strong ETag validator.
100
+ # Weak ETags are what we almost always need, so they're the default. Check out
101
+ # #strong_etag= to provide a strong ETag validator.
101
102
  def etag=(weak_validators)
102
103
  self.weak_etag = weak_validators
103
104
  end
@@ -112,12 +113,13 @@ module ActionDispatch
112
113
 
113
114
  def etag?; etag; end
114
115
 
115
- # True if an ETag is set, and it's a weak validator (preceded with <tt>W/</tt>).
116
+ # True if an ETag is set, and it's a weak validator (preceded with `W/`).
116
117
  def weak_etag?
117
118
  etag? && etag.start_with?('W/"')
118
119
  end
119
120
 
120
- # True if an ETag is set, and it isn't a weak validator (not preceded with <tt>W/</tt>).
121
+ # True if an ETag is set, and it isn't a weak validator (not preceded with
122
+ # `W/`).
121
123
  def strong_etag?
122
124
  etag? && !weak_etag?
123
125
  end
@@ -171,10 +173,9 @@ module ActionDispatch
171
173
  MUST_REVALIDATE = "must-revalidate"
172
174
 
173
175
  def handle_conditional_get!
174
- # Normally default cache control setting is handled by ETag
175
- # middleware. But, if an etag is already set, the middleware
176
- # defaults to `no-cache` unless a default `Cache-Control` value is
177
- # previously set. So, set a default one here.
176
+ # Normally default cache control setting is handled by ETag middleware. But, if
177
+ # an etag is already set, the middleware defaults to `no-cache` unless a default
178
+ # `Cache-Control` value is previously set. So, set a default one here.
178
179
  if (etag? || last_modified?) && !self._cache_control
179
180
  self._cache_control = DEFAULT_CACHE_CONTROL
180
181
  end
@@ -186,8 +187,8 @@ module ActionDispatch
186
187
  return if control.empty? && cache_control.empty? # Let middleware handle default behavior
187
188
 
188
189
  if cache_control.any?
189
- # Any caching directive coming from a controller overrides
190
- # no-cache/no-store in the default Cache-Control header.
190
+ # Any caching directive coming from a controller overrides no-cache/no-store in
191
+ # the default Cache-Control header.
191
192
  control.delete(:no_cache)
192
193
  control.delete(:no_store)
193
194
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionDispatch
4
6
  module Http
5
7
  class ContentDisposition # :nodoc: