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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +264 -220
- data/MIT-LICENSE +1 -1
- data/README.rdoc +6 -6
- data/lib/abstract_controller/asset_paths.rb +1 -1
- data/lib/abstract_controller/base.rb +24 -4
- data/lib/abstract_controller/caching/fragments.rb +8 -24
- data/lib/abstract_controller/caching.rb +2 -2
- data/lib/abstract_controller/callbacks.rb +34 -8
- data/lib/abstract_controller/collector.rb +5 -4
- data/lib/abstract_controller/error.rb +1 -1
- data/lib/abstract_controller/helpers.rb +107 -90
- data/lib/abstract_controller/logger.rb +1 -1
- data/lib/abstract_controller/railties/routes_helpers.rb +19 -1
- data/lib/abstract_controller/rendering.rb +9 -9
- data/lib/abstract_controller/translation.rb +12 -5
- data/lib/abstract_controller/url_for.rb +4 -6
- data/lib/abstract_controller.rb +2 -0
- data/lib/action_controller/api.rb +5 -4
- data/lib/action_controller/base.rb +6 -9
- data/lib/action_controller/caching.rb +1 -3
- data/lib/action_controller/log_subscriber.rb +13 -9
- data/lib/action_controller/metal/basic_implicit_render.rb +1 -1
- data/lib/action_controller/metal/conditional_get.rb +57 -6
- data/lib/action_controller/metal/content_security_policy.rb +2 -3
- data/lib/action_controller/metal/cookies.rb +4 -2
- data/lib/action_controller/metal/data_streaming.rb +9 -18
- data/lib/action_controller/metal/default_headers.rb +17 -0
- data/lib/action_controller/metal/etag_with_template_digest.rb +4 -6
- data/lib/action_controller/metal/exceptions.rb +55 -12
- data/lib/action_controller/metal/flash.rb +10 -6
- data/lib/action_controller/metal/head.rb +7 -4
- data/lib/action_controller/metal/helpers.rb +15 -6
- data/lib/action_controller/metal/http_authentication.rb +41 -39
- data/lib/action_controller/metal/implicit_render.rb +5 -15
- data/lib/action_controller/metal/instrumentation.rb +59 -55
- data/lib/action_controller/metal/live.rb +80 -33
- data/lib/action_controller/metal/logging.rb +20 -0
- data/lib/action_controller/metal/mime_responds.rb +22 -7
- data/lib/action_controller/metal/parameter_encoding.rb +35 -4
- data/lib/action_controller/metal/params_wrapper.rb +50 -31
- data/lib/action_controller/metal/permissions_policy.rb +46 -0
- data/lib/action_controller/metal/redirecting.rb +93 -23
- data/lib/action_controller/metal/renderers.rb +4 -4
- data/lib/action_controller/metal/rendering.rb +14 -9
- data/lib/action_controller/metal/request_forgery_protection.rb +160 -58
- data/lib/action_controller/metal/rescue.rb +2 -2
- data/lib/action_controller/metal/streaming.rb +1 -4
- data/lib/action_controller/metal/strong_parameters.rb +236 -88
- data/lib/action_controller/metal/testing.rb +9 -2
- data/lib/action_controller/metal/url_for.rb +1 -1
- data/lib/action_controller/metal.rb +16 -17
- data/lib/action_controller/railtie.rb +49 -6
- data/lib/action_controller/railties/helpers.rb +1 -1
- data/lib/action_controller/renderer.rb +37 -13
- data/lib/action_controller/template_assertions.rb +1 -1
- data/lib/action_controller/test_case.rb +98 -68
- data/lib/action_controller.rb +4 -5
- data/lib/action_dispatch/http/cache.rb +45 -32
- data/lib/action_dispatch/http/content_disposition.rb +45 -0
- data/lib/action_dispatch/http/content_security_policy.rb +69 -56
- data/lib/action_dispatch/http/filter_parameters.rb +14 -8
- data/lib/action_dispatch/http/filter_redirect.rb +2 -3
- data/lib/action_dispatch/http/headers.rb +4 -4
- data/lib/action_dispatch/http/mime_negotiation.rb +44 -16
- data/lib/action_dispatch/http/mime_type.rb +47 -30
- data/lib/action_dispatch/http/parameters.rb +18 -27
- data/lib/action_dispatch/http/permissions_policy.rb +173 -0
- data/lib/action_dispatch/http/request.rb +49 -35
- data/lib/action_dispatch/http/response.rb +34 -26
- data/lib/action_dispatch/http/upload.rb +9 -1
- data/lib/action_dispatch/http/url.rb +86 -94
- data/lib/action_dispatch/journey/formatter.rb +55 -31
- data/lib/action_dispatch/journey/gtg/builder.rb +30 -46
- data/lib/action_dispatch/journey/gtg/simulator.rb +15 -8
- data/lib/action_dispatch/journey/gtg/transition_table.rb +78 -21
- data/lib/action_dispatch/journey/nfa/dot.rb +0 -11
- data/lib/action_dispatch/journey/nodes/node.rb +83 -16
- data/lib/action_dispatch/journey/parser.rb +13 -13
- data/lib/action_dispatch/journey/parser.y +1 -1
- data/lib/action_dispatch/journey/path/pattern.rb +42 -34
- data/lib/action_dispatch/journey/route.rb +14 -31
- data/lib/action_dispatch/journey/router/utils.rb +16 -14
- data/lib/action_dispatch/journey/router.rb +27 -35
- data/lib/action_dispatch/journey/routes.rb +3 -5
- data/lib/action_dispatch/journey/scanner.rb +10 -4
- data/lib/action_dispatch/journey/visitors.rb +1 -4
- data/lib/action_dispatch/journey/visualizer/fsm.js +49 -24
- data/lib/action_dispatch/journey/visualizer/index.html.erb +1 -1
- data/lib/action_dispatch/journey.rb +0 -2
- data/lib/action_dispatch/middleware/actionable_exceptions.rb +45 -0
- data/lib/action_dispatch/middleware/callbacks.rb +2 -4
- data/lib/action_dispatch/middleware/cookies.rb +136 -113
- data/lib/action_dispatch/middleware/debug_exceptions.rb +47 -68
- data/lib/action_dispatch/middleware/debug_locks.rb +8 -8
- data/lib/action_dispatch/middleware/debug_view.rb +66 -0
- data/lib/action_dispatch/middleware/exception_wrapper.rb +79 -30
- data/lib/action_dispatch/middleware/executor.rb +4 -1
- data/lib/action_dispatch/middleware/flash.rb +10 -12
- data/lib/action_dispatch/middleware/host_authorization.rb +159 -0
- data/lib/action_dispatch/middleware/public_exceptions.rb +6 -3
- data/lib/action_dispatch/middleware/remote_ip.rb +30 -20
- data/lib/action_dispatch/middleware/request_id.rb +5 -6
- data/lib/action_dispatch/middleware/server_timing.rb +33 -0
- data/lib/action_dispatch/middleware/session/abstract_store.rb +16 -3
- data/lib/action_dispatch/middleware/session/cache_store.rb +11 -6
- data/lib/action_dispatch/middleware/session/cookie_store.rb +24 -19
- data/lib/action_dispatch/middleware/show_exceptions.rb +20 -11
- data/lib/action_dispatch/middleware/ssl.rb +20 -15
- data/lib/action_dispatch/middleware/stack.rb +79 -7
- data/lib/action_dispatch/middleware/static.rb +150 -94
- data/lib/action_dispatch/middleware/templates/rescues/_actions.html.erb +13 -0
- data/lib/action_dispatch/middleware/templates/rescues/_actions.text.erb +0 -0
- data/lib/action_dispatch/middleware/templates/rescues/_message_and_suggestions.html.erb +22 -0
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +6 -11
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +4 -2
- data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +46 -36
- data/lib/action_dispatch/middleware/templates/rescues/blocked_host.html.erb +8 -0
- data/lib/action_dispatch/middleware/templates/rescues/blocked_host.text.erb +7 -0
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +25 -6
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +9 -6
- data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +4 -1
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +121 -15
- data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +19 -0
- data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.text.erb +3 -0
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +5 -5
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +4 -4
- data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +5 -5
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +4 -4
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +16 -2
- data/lib/action_dispatch/railtie.rb +16 -4
- data/lib/action_dispatch/request/session.rb +59 -22
- data/lib/action_dispatch/request/utils.rb +28 -2
- data/lib/action_dispatch/routing/inspector.rb +102 -54
- data/lib/action_dispatch/routing/mapper.rb +184 -156
- data/lib/action_dispatch/routing/polymorphic_routes.rb +21 -19
- data/lib/action_dispatch/routing/redirection.rb +4 -6
- data/lib/action_dispatch/routing/route_set.rb +83 -73
- data/lib/action_dispatch/routing/routes_proxy.rb +1 -1
- data/lib/action_dispatch/routing/url_for.rb +2 -3
- data/lib/action_dispatch/routing.rb +23 -22
- data/lib/action_dispatch/system_test_case.rb +65 -16
- data/lib/action_dispatch/system_testing/browser.rb +43 -16
- data/lib/action_dispatch/system_testing/driver.rb +42 -10
- data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +58 -12
- data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +3 -10
- data/lib/action_dispatch/testing/assertion_response.rb +0 -1
- data/lib/action_dispatch/testing/assertions/response.rb +4 -7
- data/lib/action_dispatch/testing/assertions/routing.rb +20 -8
- data/lib/action_dispatch/testing/assertions.rb +3 -6
- data/lib/action_dispatch/testing/integration.rb +61 -30
- data/lib/action_dispatch/testing/request_encoder.rb +2 -2
- data/lib/action_dispatch/testing/test_process.rb +8 -6
- data/lib/action_dispatch/testing/test_request.rb +3 -3
- data/lib/action_dispatch/testing/test_response.rb +4 -32
- data/lib/action_dispatch.rb +15 -7
- data/lib/action_pack/gem_version.rb +4 -4
- data/lib/action_pack.rb +1 -1
- metadata +44 -25
- data/lib/action_controller/metal/force_ssl.rb +0 -99
- data/lib/action_dispatch/http/parameter_filter.rb +0 -86
- data/lib/action_dispatch/journey/nfa/builder.rb +0 -78
- data/lib/action_dispatch/journey/nfa/simulator.rb +0 -49
- data/lib/action_dispatch/journey/nfa/transition_table.rb +0 -120
- 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
|
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.
|
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
|
-
|
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.
|
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
|
-
|
201
|
+
controller = @controller if defined?(@controller)
|
202
|
+
request = ActionController::TestRequest.create controller&.class
|
191
203
|
|
192
|
-
if
|
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.
|
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.
|
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
|
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,
|
48
|
-
process(:head, path,
|
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
|
-
|
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
|
-
|
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
|
-
|
76
|
-
|
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
|
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
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
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
|
-
|
370
|
+
result = integration_session.#{method}(...)
|
351
371
|
copy_session_variables!
|
372
|
+
result
|
352
373
|
end
|
353
|
-
|
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!
|
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
|
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
|
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
|
-
|
42
|
-
encoder(
|
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.
|
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('
|
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('
|
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.
|
19
|
-
|
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
|
18
|
-
|
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
|
50
|
-
@
|
21
|
+
def response_parser
|
22
|
+
@response_parser ||= RequestEncoder.parser(media_type)
|
51
23
|
end
|
52
24
|
end
|
53
25
|
end
|
data/lib/action_dispatch.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright (c) 2004-
|
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,
|
87
|
-
autoload :
|
88
|
-
autoload :
|
89
|
-
autoload :
|
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
|
data/lib/action_pack.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright (c) 2004-
|
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
|