actionpack 5.2.1 → 7.0.2.4

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 (167) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +264 -220
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +6 -6
  5. data/lib/abstract_controller/asset_paths.rb +1 -1
  6. data/lib/abstract_controller/base.rb +24 -4
  7. data/lib/abstract_controller/caching/fragments.rb +8 -24
  8. data/lib/abstract_controller/caching.rb +2 -2
  9. data/lib/abstract_controller/callbacks.rb +34 -8
  10. data/lib/abstract_controller/collector.rb +5 -4
  11. data/lib/abstract_controller/error.rb +1 -1
  12. data/lib/abstract_controller/helpers.rb +107 -90
  13. data/lib/abstract_controller/logger.rb +1 -1
  14. data/lib/abstract_controller/railties/routes_helpers.rb +19 -1
  15. data/lib/abstract_controller/rendering.rb +9 -9
  16. data/lib/abstract_controller/translation.rb +12 -5
  17. data/lib/abstract_controller/url_for.rb +4 -6
  18. data/lib/abstract_controller.rb +2 -0
  19. data/lib/action_controller/api.rb +5 -4
  20. data/lib/action_controller/base.rb +6 -9
  21. data/lib/action_controller/caching.rb +1 -3
  22. data/lib/action_controller/log_subscriber.rb +13 -9
  23. data/lib/action_controller/metal/basic_implicit_render.rb +1 -1
  24. data/lib/action_controller/metal/conditional_get.rb +57 -6
  25. data/lib/action_controller/metal/content_security_policy.rb +2 -3
  26. data/lib/action_controller/metal/cookies.rb +4 -2
  27. data/lib/action_controller/metal/data_streaming.rb +9 -18
  28. data/lib/action_controller/metal/default_headers.rb +17 -0
  29. data/lib/action_controller/metal/etag_with_template_digest.rb +4 -6
  30. data/lib/action_controller/metal/exceptions.rb +55 -12
  31. data/lib/action_controller/metal/flash.rb +10 -6
  32. data/lib/action_controller/metal/head.rb +7 -4
  33. data/lib/action_controller/metal/helpers.rb +15 -6
  34. data/lib/action_controller/metal/http_authentication.rb +41 -39
  35. data/lib/action_controller/metal/implicit_render.rb +5 -15
  36. data/lib/action_controller/metal/instrumentation.rb +59 -55
  37. data/lib/action_controller/metal/live.rb +80 -33
  38. data/lib/action_controller/metal/logging.rb +20 -0
  39. data/lib/action_controller/metal/mime_responds.rb +22 -7
  40. data/lib/action_controller/metal/parameter_encoding.rb +35 -4
  41. data/lib/action_controller/metal/params_wrapper.rb +50 -31
  42. data/lib/action_controller/metal/permissions_policy.rb +46 -0
  43. data/lib/action_controller/metal/redirecting.rb +93 -23
  44. data/lib/action_controller/metal/renderers.rb +4 -4
  45. data/lib/action_controller/metal/rendering.rb +14 -9
  46. data/lib/action_controller/metal/request_forgery_protection.rb +160 -58
  47. data/lib/action_controller/metal/rescue.rb +2 -2
  48. data/lib/action_controller/metal/streaming.rb +1 -4
  49. data/lib/action_controller/metal/strong_parameters.rb +236 -88
  50. data/lib/action_controller/metal/testing.rb +9 -2
  51. data/lib/action_controller/metal/url_for.rb +1 -1
  52. data/lib/action_controller/metal.rb +16 -17
  53. data/lib/action_controller/railtie.rb +49 -6
  54. data/lib/action_controller/railties/helpers.rb +1 -1
  55. data/lib/action_controller/renderer.rb +37 -13
  56. data/lib/action_controller/template_assertions.rb +1 -1
  57. data/lib/action_controller/test_case.rb +98 -68
  58. data/lib/action_controller.rb +4 -5
  59. data/lib/action_dispatch/http/cache.rb +45 -32
  60. data/lib/action_dispatch/http/content_disposition.rb +45 -0
  61. data/lib/action_dispatch/http/content_security_policy.rb +69 -56
  62. data/lib/action_dispatch/http/filter_parameters.rb +14 -8
  63. data/lib/action_dispatch/http/filter_redirect.rb +2 -3
  64. data/lib/action_dispatch/http/headers.rb +4 -4
  65. data/lib/action_dispatch/http/mime_negotiation.rb +44 -16
  66. data/lib/action_dispatch/http/mime_type.rb +47 -30
  67. data/lib/action_dispatch/http/parameters.rb +18 -27
  68. data/lib/action_dispatch/http/permissions_policy.rb +173 -0
  69. data/lib/action_dispatch/http/request.rb +49 -35
  70. data/lib/action_dispatch/http/response.rb +34 -26
  71. data/lib/action_dispatch/http/upload.rb +9 -1
  72. data/lib/action_dispatch/http/url.rb +86 -94
  73. data/lib/action_dispatch/journey/formatter.rb +55 -31
  74. data/lib/action_dispatch/journey/gtg/builder.rb +30 -46
  75. data/lib/action_dispatch/journey/gtg/simulator.rb +15 -8
  76. data/lib/action_dispatch/journey/gtg/transition_table.rb +78 -21
  77. data/lib/action_dispatch/journey/nfa/dot.rb +0 -11
  78. data/lib/action_dispatch/journey/nodes/node.rb +83 -16
  79. data/lib/action_dispatch/journey/parser.rb +13 -13
  80. data/lib/action_dispatch/journey/parser.y +1 -1
  81. data/lib/action_dispatch/journey/path/pattern.rb +42 -34
  82. data/lib/action_dispatch/journey/route.rb +14 -31
  83. data/lib/action_dispatch/journey/router/utils.rb +16 -14
  84. data/lib/action_dispatch/journey/router.rb +27 -35
  85. data/lib/action_dispatch/journey/routes.rb +3 -5
  86. data/lib/action_dispatch/journey/scanner.rb +10 -4
  87. data/lib/action_dispatch/journey/visitors.rb +1 -4
  88. data/lib/action_dispatch/journey/visualizer/fsm.js +49 -24
  89. data/lib/action_dispatch/journey/visualizer/index.html.erb +1 -1
  90. data/lib/action_dispatch/journey.rb +0 -2
  91. data/lib/action_dispatch/middleware/actionable_exceptions.rb +45 -0
  92. data/lib/action_dispatch/middleware/callbacks.rb +2 -4
  93. data/lib/action_dispatch/middleware/cookies.rb +136 -113
  94. data/lib/action_dispatch/middleware/debug_exceptions.rb +47 -68
  95. data/lib/action_dispatch/middleware/debug_locks.rb +8 -8
  96. data/lib/action_dispatch/middleware/debug_view.rb +66 -0
  97. data/lib/action_dispatch/middleware/exception_wrapper.rb +79 -30
  98. data/lib/action_dispatch/middleware/executor.rb +4 -1
  99. data/lib/action_dispatch/middleware/flash.rb +10 -12
  100. data/lib/action_dispatch/middleware/host_authorization.rb +159 -0
  101. data/lib/action_dispatch/middleware/public_exceptions.rb +6 -3
  102. data/lib/action_dispatch/middleware/remote_ip.rb +30 -20
  103. data/lib/action_dispatch/middleware/request_id.rb +5 -6
  104. data/lib/action_dispatch/middleware/server_timing.rb +33 -0
  105. data/lib/action_dispatch/middleware/session/abstract_store.rb +16 -3
  106. data/lib/action_dispatch/middleware/session/cache_store.rb +11 -6
  107. data/lib/action_dispatch/middleware/session/cookie_store.rb +24 -19
  108. data/lib/action_dispatch/middleware/show_exceptions.rb +20 -11
  109. data/lib/action_dispatch/middleware/ssl.rb +20 -15
  110. data/lib/action_dispatch/middleware/stack.rb +79 -7
  111. data/lib/action_dispatch/middleware/static.rb +150 -94
  112. data/lib/action_dispatch/middleware/templates/rescues/_actions.html.erb +13 -0
  113. data/lib/action_dispatch/middleware/templates/rescues/_actions.text.erb +0 -0
  114. data/lib/action_dispatch/middleware/templates/rescues/_message_and_suggestions.html.erb +22 -0
  115. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +6 -11
  116. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +1 -1
  117. data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +4 -2
  118. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +46 -36
  119. data/lib/action_dispatch/middleware/templates/rescues/blocked_host.html.erb +8 -0
  120. data/lib/action_dispatch/middleware/templates/rescues/blocked_host.text.erb +7 -0
  121. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +25 -6
  122. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +1 -1
  123. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +9 -6
  124. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +4 -1
  125. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +121 -15
  126. data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +19 -0
  127. data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.text.erb +3 -0
  128. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +5 -5
  129. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +4 -4
  130. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +5 -5
  131. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +4 -4
  132. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +16 -2
  133. data/lib/action_dispatch/railtie.rb +16 -4
  134. data/lib/action_dispatch/request/session.rb +59 -22
  135. data/lib/action_dispatch/request/utils.rb +28 -2
  136. data/lib/action_dispatch/routing/inspector.rb +102 -54
  137. data/lib/action_dispatch/routing/mapper.rb +184 -156
  138. data/lib/action_dispatch/routing/polymorphic_routes.rb +21 -19
  139. data/lib/action_dispatch/routing/redirection.rb +4 -6
  140. data/lib/action_dispatch/routing/route_set.rb +83 -73
  141. data/lib/action_dispatch/routing/routes_proxy.rb +1 -1
  142. data/lib/action_dispatch/routing/url_for.rb +2 -3
  143. data/lib/action_dispatch/routing.rb +23 -22
  144. data/lib/action_dispatch/system_test_case.rb +65 -16
  145. data/lib/action_dispatch/system_testing/browser.rb +43 -16
  146. data/lib/action_dispatch/system_testing/driver.rb +42 -10
  147. data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +58 -12
  148. data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +3 -10
  149. data/lib/action_dispatch/testing/assertion_response.rb +0 -1
  150. data/lib/action_dispatch/testing/assertions/response.rb +4 -7
  151. data/lib/action_dispatch/testing/assertions/routing.rb +20 -8
  152. data/lib/action_dispatch/testing/assertions.rb +3 -6
  153. data/lib/action_dispatch/testing/integration.rb +61 -30
  154. data/lib/action_dispatch/testing/request_encoder.rb +2 -2
  155. data/lib/action_dispatch/testing/test_process.rb +8 -6
  156. data/lib/action_dispatch/testing/test_request.rb +3 -3
  157. data/lib/action_dispatch/testing/test_response.rb +4 -32
  158. data/lib/action_dispatch.rb +15 -7
  159. data/lib/action_pack/gem_version.rb +4 -4
  160. data/lib/action_pack.rb +1 -1
  161. metadata +44 -25
  162. data/lib/action_controller/metal/force_ssl.rb +0 -99
  163. data/lib/action_dispatch/http/parameter_filter.rb +0 -86
  164. data/lib/action_dispatch/journey/nfa/builder.rb +0 -78
  165. data/lib/action_dispatch/journey/nfa/simulator.rb +0 -49
  166. data/lib/action_dispatch/journey/nfa/transition_table.rb +0 -120
  167. data/lib/action_dispatch/system_testing/test_helpers/undef_methods.rb +0 -26
@@ -9,6 +9,11 @@ module ActionDispatch
9
9
  module Assertions
10
10
  # Suite of assertions to test routes generated by \Rails and the handling of requests made to them.
11
11
  module RoutingAssertions
12
+ def setup # :nodoc:
13
+ @routes ||= nil
14
+ super
15
+ end
16
+
12
17
  # Asserts that the routing of the given +path+ was handled correctly and that the parsed options (given in the +expected_options+ hash)
13
18
  # match +path+. Basically, it asserts that \Rails recognizes the route given by +expected_options+.
14
19
  #
@@ -78,15 +83,14 @@ module ActionDispatch
78
83
  # # Asserts that the generated route gives us our custom route
79
84
  # assert_generates "changesets/12", { controller: 'scm', action: 'show_diff', revision: "12" }
80
85
  def assert_generates(expected_path, options, defaults = {}, extras = {}, message = nil)
81
- if expected_path =~ %r{://}
86
+ if %r{://}.match?(expected_path)
82
87
  fail_on(URI::InvalidURIError, message) do
83
88
  uri = URI.parse(expected_path)
84
89
  expected_path = uri.path.to_s.empty? ? "/" : uri.path
85
90
  end
86
91
  else
87
- expected_path = "/#{expected_path}" unless expected_path.first == "/"
92
+ expected_path = "/#{expected_path}" unless expected_path.start_with?("/")
88
93
  end
89
- # Load routes.rb if it hasn't been loaded.
90
94
 
91
95
  options = options.clone
92
96
  generated_path, query_string_keys = @routes.generate_extras(options, defaults)
@@ -155,9 +159,16 @@ module ActionDispatch
155
159
  @controller.singleton_class.include(_routes.url_helpers)
156
160
 
157
161
  if @controller.respond_to? :view_context_class
158
- @controller.view_context_class = Class.new(@controller.view_context_class) do
162
+ view_context_class = Class.new(@controller.view_context_class) do
159
163
  include _routes.url_helpers
160
164
  end
165
+
166
+ custom_view_context = Module.new {
167
+ define_method(:view_context_class) do
168
+ view_context_class
169
+ end
170
+ }
171
+ @controller.extend(custom_view_context)
161
172
  end
162
173
  end
163
174
  yield @routes
@@ -171,7 +182,7 @@ module ActionDispatch
171
182
  # ROUTES TODO: These assertions should really work in an integration context
172
183
  def method_missing(selector, *args, &block)
173
184
  if defined?(@controller) && @controller && defined?(@routes) && @routes && @routes.named_routes.route_defined?(selector)
174
- @controller.send(selector, *args, &block)
185
+ @controller.public_send(selector, *args, &block)
175
186
  else
176
187
  super
177
188
  end
@@ -187,9 +198,10 @@ module ActionDispatch
187
198
  method = :get
188
199
  end
189
200
 
190
- request = ActionController::TestRequest.create @controller.class
201
+ controller = @controller if defined?(@controller)
202
+ request = ActionController::TestRequest.create controller&.class
191
203
 
192
- if path =~ %r{://}
204
+ if %r{://}.match?(path)
193
205
  fail_on(URI::InvalidURIError, msg) do
194
206
  uri = URI.parse(path)
195
207
  request.env["rack.url_scheme"] = uri.scheme || "http"
@@ -198,7 +210,7 @@ module ActionDispatch
198
210
  request.path = uri.path.to_s.empty? ? "/" : uri.path
199
211
  end
200
212
  else
201
- path = "/#{path}" unless path.first == "/"
213
+ path = "/#{path}" unless path.start_with?("/")
202
214
  request.path = path
203
215
  end
204
216
 
@@ -1,20 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "rails-dom-testing"
4
+ require "action_dispatch/testing/assertions/response"
5
+ require "action_dispatch/testing/assertions/routing"
4
6
 
5
7
  module ActionDispatch
6
8
  module Assertions
7
- autoload :ResponseAssertions, "action_dispatch/testing/assertions/response"
8
- autoload :RoutingAssertions, "action_dispatch/testing/assertions/routing"
9
-
10
- extend ActiveSupport::Concern
11
-
12
9
  include ResponseAssertions
13
10
  include RoutingAssertions
14
11
  include Rails::Dom::Testing::Assertions
15
12
 
16
13
  def html_document
17
- @html_document ||= if @response.content_type.to_s.end_with?("xml")
14
+ @html_document ||= if @response.media_type&.end_with?("xml")
18
15
  Nokogiri::XML::Document.parse(@response.body)
19
16
  else
20
17
  Nokogiri::HTML::Document.parse(@response.body)
@@ -2,15 +2,13 @@
2
2
 
3
3
  require "stringio"
4
4
  require "uri"
5
- require "active_support/core_ext/kernel/singleton_class"
6
- require "active_support/core_ext/object/try"
7
5
  require "rack/test"
8
6
  require "minitest"
9
7
 
10
8
  require "action_dispatch/testing/request_encoder"
11
9
 
12
10
  module ActionDispatch
13
- module Integration #:nodoc:
11
+ module Integration # :nodoc:
14
12
  module RequestHelpers
15
13
  # Performs a GET request with the given parameters. See ActionDispatch::Integration::Session#process
16
14
  # for more details.
@@ -44,16 +42,33 @@ module ActionDispatch
44
42
 
45
43
  # Performs a HEAD request with the given parameters. See ActionDispatch::Integration::Session#process
46
44
  # for more details.
47
- def head(path, *args)
48
- process(:head, path, *args)
45
+ def head(path, **args)
46
+ process(:head, path, **args)
47
+ end
48
+
49
+ # Performs an OPTIONS request with the given parameters. See ActionDispatch::Integration::Session#process
50
+ # for more details.
51
+ def options(path, **args)
52
+ process(:options, path, **args)
49
53
  end
50
54
 
51
55
  # Follow a single redirect response. If the last response was not a
52
56
  # redirect, an exception will be raised. Otherwise, the redirect is
53
- # performed on the location header.
54
- def follow_redirect!
57
+ # performed on the location header. If the redirection is a 307 or 308 redirect,
58
+ # the same HTTP verb will be used when redirecting, otherwise a GET request
59
+ # will be performed. Any arguments are passed to the
60
+ # underlying request.
61
+ def follow_redirect!(**args)
55
62
  raise "not a redirect! #{status} #{status_message}" unless redirect?
56
- get(response.location)
63
+
64
+ method =
65
+ if [307, 308].include?(response.status)
66
+ request.method.downcase
67
+ else
68
+ :get
69
+ end
70
+
71
+ public_send(method, response.location, **args)
57
72
  status
58
73
  end
59
74
  end
@@ -72,13 +87,8 @@ module ActionDispatch
72
87
  include Minitest::Assertions
73
88
  include TestProcess, RequestHelpers, Assertions
74
89
 
75
- %w( status status_message headers body redirect? ).each do |method|
76
- delegate method, to: :response, allow_nil: true
77
- end
78
-
79
- %w( path ).each do |method|
80
- delegate method, to: :request, allow_nil: true
81
- end
90
+ delegate :status, :status_message, :headers, :body, :redirect?, to: :response, allow_nil: true
91
+ delegate :path, to: :request, allow_nil: true
82
92
 
83
93
  # The hostname used in the last request.
84
94
  def host
@@ -122,7 +132,7 @@ module ActionDispatch
122
132
 
123
133
  def url_options
124
134
  @url_options ||= default_url_options.dup.tap do |url_options|
125
- url_options.reverse_merge!(controller.url_options) if controller
135
+ url_options.reverse_merge!(controller.url_options) if controller.respond_to?(:url_options)
126
136
 
127
137
  if @app.respond_to?(:routes)
128
138
  url_options.reverse_merge!(@app.routes.default_url_options)
@@ -189,6 +199,12 @@ module ActionDispatch
189
199
  # merged into the Rack env hash.
190
200
  # - +env+: Additional env to pass, as a Hash. The headers will be
191
201
  # merged into the Rack env hash.
202
+ # - +xhr+: Set to +true+ if you want to make an Ajax request.
203
+ # Adds request headers characteristic of XMLHttpRequest e.g. HTTP_X_REQUESTED_WITH.
204
+ # The headers will be merged into the Rack env hash.
205
+ # - +as+: Used for encoding the request with different content type.
206
+ # Supports +:json+ by default and will set the appropriate request headers.
207
+ # The headers will be merged into the Rack env hash.
192
208
  #
193
209
  # This method is rarely used directly. Use +#get+, +#post+, or other standard
194
210
  # HTTP methods in integration tests. +#process+ is only required when using a
@@ -210,7 +226,7 @@ module ActionDispatch
210
226
  method = :post
211
227
  end
212
228
 
213
- if path =~ %r{://}
229
+ if %r{://}.match?(path)
214
230
  path = build_expanded_path(path) do |location|
215
231
  https! URI::HTTPS === location if location.scheme
216
232
 
@@ -303,6 +319,7 @@ module ActionDispatch
303
319
  APP_SESSIONS = {}
304
320
 
305
321
  attr_reader :app
322
+ attr_accessor :root_session # :nodoc:
306
323
 
307
324
  def initialize(*args, &blk)
308
325
  super(*args, &blk)
@@ -328,7 +345,7 @@ module ActionDispatch
328
345
  klass = APP_SESSIONS[app] ||= Class.new(Integration::Session) {
329
346
  # If the app is a Rails app, make url_helpers available on the session.
330
347
  # This makes app.url_for and app.foo_path available in the console.
331
- if app.respond_to?(:routes)
348
+ if app.respond_to?(:routes) && app.routes.is_a?(ActionDispatch::Routing::RouteSet)
332
349
  include app.routes.url_helpers
333
350
  include app.routes.mounted_helpers
334
351
  end
@@ -341,16 +358,20 @@ module ActionDispatch
341
358
  end
342
359
 
343
360
  %w(get post patch put head delete cookies assigns follow_redirect!).each do |method|
344
- define_method(method) do |*args|
345
- # reset the html_document variable, except for cookies/assigns calls
346
- unless method == "cookies" || method == "assigns"
347
- @html_document = nil
348
- end
361
+ # reset the html_document variable, except for cookies/assigns calls
362
+ unless method == "cookies" || method == "assigns"
363
+ reset_html_document = "@html_document = nil"
364
+ end
365
+
366
+ module_eval <<~RUBY, __FILE__, __LINE__ + 1
367
+ def #{method}(...)
368
+ #{reset_html_document}
349
369
 
350
- integration_session.__send__(method, *args).tap do
370
+ result = integration_session.#{method}(...)
351
371
  copy_session_variables!
372
+ result
352
373
  end
353
- end
374
+ RUBY
354
375
  end
355
376
 
356
377
  # Open a new session instance. If a block is given, the new session is
@@ -366,13 +387,22 @@ module ActionDispatch
366
387
  def open_session
367
388
  dup.tap do |session|
368
389
  session.reset!
390
+ session.root_session = self.root_session || self
369
391
  yield session if block_given?
370
392
  end
371
393
  end
372
394
 
395
+ def assertions # :nodoc:
396
+ root_session ? root_session.assertions : super
397
+ end
398
+
399
+ def assertions=(assertions) # :nodoc:
400
+ root_session ? root_session.assertions = assertions : super
401
+ end
402
+
373
403
  # Copy the instance variables from the current session instance into the
374
404
  # test instance.
375
- def copy_session_variables! #:nodoc:
405
+ def copy_session_variables! # :nodoc:
376
406
  @controller = @integration_session.controller
377
407
  @response = @integration_session.response
378
408
  @request = @integration_session.request
@@ -401,6 +431,7 @@ module ActionDispatch
401
431
  super
402
432
  end
403
433
  end
434
+ ruby2_keywords(:method_missing)
404
435
  end
405
436
  end
406
437
 
@@ -484,7 +515,7 @@ module ActionDispatch
484
515
  #
485
516
  # A simple integration test that exercises multiple controllers:
486
517
  #
487
- # require 'test_helper'
518
+ # require "test_helper"
488
519
  #
489
520
  # class UserFlowsTest < ActionDispatch::IntegrationTest
490
521
  # test "login and browse site" do
@@ -513,7 +544,7 @@ module ActionDispatch
513
544
  #
514
545
  # Here's an example of multiple sessions and custom DSL in an integration test
515
546
  #
516
- # require 'test_helper'
547
+ # require "test_helper"
517
548
  #
518
549
  # class UserFlowsTest < ActionDispatch::IntegrationTest
519
550
  # test "login and browse site" do
@@ -633,8 +664,8 @@ module ActionDispatch
633
664
  @@app = app
634
665
  end
635
666
 
636
- def register_encoder(*args)
637
- RequestEncoder.register_encoder(*args)
667
+ def register_encoder(*args, **options)
668
+ RequestEncoder.register_encoder(*args, **options)
638
669
  end
639
670
  end
640
671
 
@@ -38,8 +38,8 @@ module ActionDispatch
38
38
  end
39
39
 
40
40
  def self.parser(content_type)
41
- mime = Mime::Type.lookup(content_type)
42
- encoder(mime ? mime.ref : nil).response_parser
41
+ type = Mime::Type.lookup(content_type).ref if content_type
42
+ encoder(type).response_parser
43
43
  end
44
44
 
45
45
  def self.encoder(name)
@@ -6,19 +6,21 @@ require "action_dispatch/middleware/flash"
6
6
  module ActionDispatch
7
7
  module TestProcess
8
8
  module FixtureFile
9
- # Shortcut for <tt>Rack::Test::UploadedFile.new(File.join(ActionDispatch::IntegrationTest.fixture_path, path), type)</tt>:
9
+ # Shortcut for <tt>Rack::Test::UploadedFile.new(File.join(ActionDispatch::IntegrationTest.file_fixture_path, path), type)</tt>:
10
10
  #
11
- # post :change_avatar, avatar: fixture_file_upload('files/spongebob.png', 'image/png')
11
+ # post :change_avatar, params: { avatar: fixture_file_upload('david.png', 'image/png') }
12
+ #
13
+ # Default fixture files location is <tt>test/fixtures/files</tt>.
12
14
  #
13
15
  # To upload binary files on Windows, pass <tt>:binary</tt> as the last parameter.
14
16
  # This will not affect other platforms:
15
17
  #
16
- # post :change_avatar, avatar: fixture_file_upload('files/spongebob.png', 'image/png', :binary)
18
+ # post :change_avatar, params: { avatar: fixture_file_upload('david.png', 'image/png', :binary) }
17
19
  def fixture_file_upload(path, mime_type = nil, binary = false)
18
- if self.class.respond_to?(:fixture_path) && self.class.fixture_path &&
19
- !File.exist?(path)
20
- path = File.join(self.class.fixture_path, path)
20
+ if self.class.file_fixture_path && !File.exist?(path)
21
+ path = file_fixture(path)
21
22
  end
23
+
22
24
  Rack::Test::UploadedFile.new(path, mime_type, binary)
23
25
  end
24
26
  end
@@ -6,9 +6,9 @@ require "rack/utils"
6
6
  module ActionDispatch
7
7
  class TestRequest < Request
8
8
  DEFAULT_ENV = Rack::MockRequest.env_for("/",
9
- "HTTP_HOST" => "test.host",
10
- "REMOTE_ADDR" => "0.0.0.0",
11
- "HTTP_USER_AGENT" => "Rails Testing",
9
+ "HTTP_HOST" => "test.host".b,
10
+ "REMOTE_ADDR" => "0.0.0.0".b,
11
+ "HTTP_USER_AGENT" => "Rails Testing".b,
12
12
  )
13
13
 
14
14
  # Create a new test request with default +env+ values.
@@ -14,40 +14,12 @@ module ActionDispatch
14
14
  new response.status, response.headers, response.body
15
15
  end
16
16
 
17
- def initialize(*) # :nodoc:
18
- super
19
- @response_parser = RequestEncoder.parser(content_type)
20
- end
21
-
22
- # Was the response successful?
23
- def success?
24
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
25
- The success? predicate is deprecated and will be removed in Rails 6.0.
26
- Please use successful? as provided by Rack::Response::Helpers.
27
- MSG
28
- successful?
29
- end
30
-
31
- # Was the URL not found?
32
- def missing?
33
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
34
- The missing? predicate is deprecated and will be removed in Rails 6.0.
35
- Please use not_found? as provided by Rack::Response::Helpers.
36
- MSG
37
- not_found?
38
- end
39
-
40
- # Was there a server-side error?
41
- def error?
42
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
43
- The error? predicate is deprecated and will be removed in Rails 6.0.
44
- Please use server_error? as provided by Rack::Response::Helpers.
45
- MSG
46
- server_error?
17
+ def parsed_body
18
+ @parsed_body ||= response_parser.call(body)
47
19
  end
48
20
 
49
- def parsed_body
50
- @parsed_body ||= @response_parser.call(body)
21
+ def response_parser
22
+ @response_parser ||= RequestEncoder.parser(media_type)
51
23
  end
52
24
  end
53
25
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #--
4
- # Copyright (c) 2004-2018 David Heinemeier Hansson
4
+ # Copyright (c) 2004-2022 David Heinemeier Hansson
5
5
  #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining
7
7
  # a copy of this software and associated documentation files (the
@@ -40,26 +40,34 @@ module ActionDispatch
40
40
  class IllegalStateError < StandardError
41
41
  end
42
42
 
43
+ class MissingController < NameError
44
+ end
45
+
43
46
  eager_autoload do
44
47
  autoload_under "http" do
45
48
  autoload :ContentSecurityPolicy
49
+ autoload :PermissionsPolicy
46
50
  autoload :Request
47
51
  autoload :Response
48
52
  end
49
53
  end
50
54
 
51
55
  autoload_under "middleware" do
56
+ autoload :HostAuthorization
52
57
  autoload :RequestId
53
58
  autoload :Callbacks
54
59
  autoload :Cookies
60
+ autoload :ActionableExceptions
55
61
  autoload :DebugExceptions
56
62
  autoload :DebugLocks
63
+ autoload :DebugView
57
64
  autoload :ExceptionWrapper
58
65
  autoload :Executor
59
66
  autoload :Flash
60
67
  autoload :PublicExceptions
61
68
  autoload :Reloader
62
69
  autoload :RemoteIp
70
+ autoload :ServerTiming
63
71
  autoload :ShowExceptions
64
72
  autoload :SSL
65
73
  autoload :Static
@@ -76,17 +84,16 @@ module ActionDispatch
76
84
  autoload :Headers
77
85
  autoload :MimeNegotiation
78
86
  autoload :Parameters
79
- autoload :ParameterFilter
80
- autoload :Upload
81
87
  autoload :UploadedFile, "action_dispatch/http/upload"
82
88
  autoload :URL
83
89
  end
84
90
 
85
91
  module Session
86
- autoload :AbstractStore, "action_dispatch/middleware/session/abstract_store"
87
- autoload :CookieStore, "action_dispatch/middleware/session/cookie_store"
88
- autoload :MemCacheStore, "action_dispatch/middleware/session/mem_cache_store"
89
- autoload :CacheStore, "action_dispatch/middleware/session/cache_store"
92
+ autoload :AbstractStore, "action_dispatch/middleware/session/abstract_store"
93
+ autoload :AbstractSecureStore, "action_dispatch/middleware/session/abstract_store"
94
+ autoload :CookieStore, "action_dispatch/middleware/session/cookie_store"
95
+ autoload :MemCacheStore, "action_dispatch/middleware/session/mem_cache_store"
96
+ autoload :CacheStore, "action_dispatch/middleware/session/cache_store"
90
97
  end
91
98
 
92
99
  mattr_accessor :test_app
@@ -109,4 +116,5 @@ autoload :Mime, "action_dispatch/http/mime_type"
109
116
  ActiveSupport.on_load(:action_view) do
110
117
  ActionView::Base.default_formats ||= Mime::SET.symbols
111
118
  ActionView::Template::Types.delegate_to Mime
119
+ ActionView::LookupContext::DetailsKey.clear
112
120
  end
@@ -7,10 +7,10 @@ module ActionPack
7
7
  end
8
8
 
9
9
  module VERSION
10
- MAJOR = 5
11
- MINOR = 2
12
- TINY = 1
13
- PRE = nil
10
+ MAJOR = 7
11
+ MINOR = 0
12
+ TINY = 2
13
+ PRE = "4"
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
16
16
  end
data/lib/action_pack.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #--
4
- # Copyright (c) 2004-2018 David Heinemeier Hansson
4
+ # Copyright (c) 2004-2022 David Heinemeier Hansson
5
5
  #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining
7
7
  # a copy of this software and associated documentation files (the