actionpack 5.0.7.2 → 5.1.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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +189 -1002
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/lib/abstract_controller.rb +3 -3
- data/lib/abstract_controller/base.rb +10 -12
- data/lib/abstract_controller/caching.rb +6 -3
- data/lib/abstract_controller/caching/fragments.rb +1 -1
- data/lib/abstract_controller/callbacks.rb +2 -43
- data/lib/abstract_controller/collector.rb +2 -2
- data/lib/abstract_controller/helpers.rb +19 -19
- data/lib/abstract_controller/rendering.rb +9 -11
- data/lib/abstract_controller/translation.rb +3 -3
- data/lib/action_controller.rb +15 -13
- data/lib/action_controller/api.rb +3 -3
- data/lib/action_controller/base.rb +7 -12
- data/lib/action_controller/caching.rb +1 -1
- data/lib/action_controller/log_subscriber.rb +2 -2
- data/lib/action_controller/metal.rb +34 -43
- data/lib/action_controller/metal/conditional_get.rb +10 -9
- data/lib/action_controller/metal/data_streaming.rb +8 -9
- data/lib/action_controller/metal/etag_with_flash.rb +16 -0
- data/lib/action_controller/metal/etag_with_template_digest.rb +15 -15
- data/lib/action_controller/metal/exceptions.rb +4 -14
- data/lib/action_controller/metal/flash.rb +1 -1
- data/lib/action_controller/metal/force_ssl.rb +6 -6
- data/lib/action_controller/metal/head.rb +13 -19
- data/lib/action_controller/metal/helpers.rb +6 -6
- data/lib/action_controller/metal/http_authentication.rb +22 -23
- data/lib/action_controller/metal/implicit_render.rb +2 -5
- data/lib/action_controller/metal/instrumentation.rb +14 -14
- data/lib/action_controller/metal/live.rb +15 -16
- data/lib/action_controller/metal/mime_responds.rb +3 -3
- data/lib/action_controller/metal/parameter_encoding.rb +49 -0
- data/lib/action_controller/metal/params_wrapper.rb +32 -32
- data/lib/action_controller/metal/redirecting.rb +8 -24
- data/lib/action_controller/metal/renderers.rb +2 -3
- data/lib/action_controller/metal/rendering.rb +50 -60
- data/lib/action_controller/metal/request_forgery_protection.rb +51 -49
- data/lib/action_controller/metal/rescue.rb +1 -1
- data/lib/action_controller/metal/streaming.rb +4 -4
- data/lib/action_controller/metal/strong_parameters.rb +117 -250
- data/lib/action_controller/metal/testing.rb +1 -1
- data/lib/action_controller/metal/url_for.rb +4 -4
- data/lib/action_controller/railtie.rb +9 -13
- data/lib/action_controller/renderer.rb +17 -16
- data/lib/action_controller/test_case.rb +75 -148
- data/lib/action_dispatch.rb +20 -19
- data/lib/action_dispatch/http/cache.rb +9 -10
- data/lib/action_dispatch/http/filter_parameters.rb +8 -8
- data/lib/action_dispatch/http/filter_redirect.rb +2 -4
- data/lib/action_dispatch/http/headers.rb +10 -10
- data/lib/action_dispatch/http/mime_negotiation.rb +17 -22
- data/lib/action_dispatch/http/mime_type.rb +27 -52
- data/lib/action_dispatch/http/parameter_filter.rb +8 -6
- data/lib/action_dispatch/http/parameters.rb +40 -17
- data/lib/action_dispatch/http/request.rb +38 -34
- data/lib/action_dispatch/http/response.rb +16 -16
- data/lib/action_dispatch/http/upload.rb +6 -10
- data/lib/action_dispatch/http/url.rb +48 -74
- data/lib/action_dispatch/journey.rb +5 -5
- data/lib/action_dispatch/journey/formatter.rb +8 -4
- data/lib/action_dispatch/journey/gtg/builder.rb +5 -5
- data/lib/action_dispatch/journey/gtg/simulator.rb +1 -1
- data/lib/action_dispatch/journey/gtg/transition_table.rb +15 -15
- data/lib/action_dispatch/journey/nfa/builder.rb +3 -3
- data/lib/action_dispatch/journey/nfa/dot.rb +2 -2
- data/lib/action_dispatch/journey/nfa/simulator.rb +1 -1
- data/lib/action_dispatch/journey/nfa/transition_table.rb +2 -2
- data/lib/action_dispatch/journey/nodes/node.rb +5 -5
- data/lib/action_dispatch/journey/parser.rb +23 -24
- data/lib/action_dispatch/journey/parser.y +3 -2
- data/lib/action_dispatch/journey/parser_extras.rb +2 -2
- data/lib/action_dispatch/journey/path/pattern.rb +10 -3
- data/lib/action_dispatch/journey/route.rb +19 -12
- data/lib/action_dispatch/journey/router.rb +19 -12
- data/lib/action_dispatch/journey/router/utils.rb +9 -9
- data/lib/action_dispatch/journey/scanner.rb +17 -15
- data/lib/action_dispatch/journey/visitors.rb +23 -23
- data/lib/action_dispatch/middleware/callbacks.rb +0 -12
- data/lib/action_dispatch/middleware/cookies.rb +39 -39
- data/lib/action_dispatch/middleware/debug_exceptions.rb +126 -112
- data/lib/action_dispatch/middleware/debug_locks.rb +8 -8
- data/lib/action_dispatch/middleware/exception_wrapper.rb +55 -55
- data/lib/action_dispatch/middleware/executor.rb +1 -1
- data/lib/action_dispatch/middleware/flash.rb +17 -16
- data/lib/action_dispatch/middleware/public_exceptions.rb +20 -20
- data/lib/action_dispatch/middleware/reloader.rb +3 -47
- data/lib/action_dispatch/middleware/remote_ip.rb +6 -8
- data/lib/action_dispatch/middleware/request_id.rb +6 -5
- data/lib/action_dispatch/middleware/session/abstract_store.rb +14 -26
- data/lib/action_dispatch/middleware/session/cache_store.rb +3 -3
- data/lib/action_dispatch/middleware/session/cookie_store.rb +35 -35
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +2 -2
- data/lib/action_dispatch/middleware/show_exceptions.rb +19 -19
- data/lib/action_dispatch/middleware/ssl.rb +9 -27
- data/lib/action_dispatch/middleware/stack.rb +7 -26
- data/lib/action_dispatch/middleware/static.rb +13 -24
- data/lib/action_dispatch/railtie.rb +9 -11
- data/lib/action_dispatch/request/session.rb +22 -22
- data/lib/action_dispatch/request/utils.rb +11 -2
- data/lib/action_dispatch/routing.rb +8 -6
- data/lib/action_dispatch/routing/inspector.rb +37 -37
- data/lib/action_dispatch/routing/mapper.rb +296 -203
- data/lib/action_dispatch/routing/polymorphic_routes.rb +160 -134
- data/lib/action_dispatch/routing/redirection.rb +27 -22
- data/lib/action_dispatch/routing/route_set.rb +206 -92
- data/lib/action_dispatch/routing/routes_proxy.rb +2 -2
- data/lib/action_dispatch/routing/url_for.rb +14 -12
- data/lib/action_dispatch/system_test_case.rb +119 -0
- data/lib/action_dispatch/system_testing/browser.rb +28 -0
- data/lib/action_dispatch/system_testing/driver.rb +18 -0
- data/lib/action_dispatch/system_testing/server.rb +32 -0
- data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +61 -0
- data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +20 -0
- data/lib/action_dispatch/testing/assertion_response.rb +6 -6
- data/lib/action_dispatch/testing/assertions.rb +4 -4
- data/lib/action_dispatch/testing/assertions/response.rb +8 -3
- data/lib/action_dispatch/testing/assertions/routing.rb +11 -11
- data/lib/action_dispatch/testing/integration.rb +47 -138
- data/lib/action_dispatch/testing/test_process.rb +2 -2
- data/lib/action_dispatch/testing/test_request.rb +16 -16
- data/lib/action_dispatch/testing/test_response.rb +1 -1
- data/lib/action_pack.rb +2 -2
- data/lib/action_pack/gem_version.rb +3 -3
- data/lib/action_pack/version.rb +1 -1
- metadata +20 -12
- data/lib/action_dispatch/middleware/params_parser.rb +0 -46
@@ -27,10 +27,10 @@ module ActionController
|
|
27
27
|
|
28
28
|
def url_options
|
29
29
|
@_url_options ||= {
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
30
|
+
host: request.host,
|
31
|
+
port: request.optional_port,
|
32
|
+
protocol: request.protocol,
|
33
|
+
_recall: request.path_parameters
|
34
34
|
}.merge!(super).freeze
|
35
35
|
|
36
36
|
if (same_origin = _routes.equal?(request.routes)) ||
|
@@ -11,7 +11,7 @@ module ActionController
|
|
11
11
|
|
12
12
|
config.eager_load_namespaces << ActionController
|
13
13
|
|
14
|
-
initializer "action_controller.assets_config", :
|
14
|
+
initializer "action_controller.assets_config", group: :all do |app|
|
15
15
|
app.config.action_controller.assets_dir ||= app.config.paths["public"].first
|
16
16
|
end
|
17
17
|
|
@@ -22,17 +22,13 @@ module ActionController
|
|
22
22
|
initializer "action_controller.parameters_config" do |app|
|
23
23
|
options = app.config.action_controller
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
options.delete(:raise_on_unfiltered_parameters) { false }
|
33
|
-
ActionController::Parameters.action_on_unpermitted_parameters = options.delete(:action_on_unpermitted_parameters) do
|
34
|
-
(Rails.env.test? || Rails.env.development?) ? :log : false
|
35
|
-
end
|
25
|
+
ActionController::Parameters.permit_all_parameters = options.delete(:permit_all_parameters) { false }
|
26
|
+
if app.config.action_controller[:always_permitted_parameters]
|
27
|
+
ActionController::Parameters.always_permitted_parameters =
|
28
|
+
app.config.action_controller.delete(:always_permitted_parameters)
|
29
|
+
end
|
30
|
+
ActionController::Parameters.action_on_unpermitted_parameters = options.delete(:action_on_unpermitted_parameters) do
|
31
|
+
(Rails.env.test? || Rails.env.development?) ? :log : false
|
36
32
|
end
|
37
33
|
end
|
38
34
|
|
@@ -55,7 +51,7 @@ module ActionController
|
|
55
51
|
extend ::AbstractController::Railties::RoutesHelpers.with(app.routes)
|
56
52
|
extend ::ActionController::Railties::Helpers
|
57
53
|
|
58
|
-
options.each do |k,v|
|
54
|
+
options.each do |k, v|
|
59
55
|
k = "#{k}="
|
60
56
|
if respond_to?(k)
|
61
57
|
send(k, v)
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "active_support/core_ext/hash/keys"
|
2
2
|
|
3
3
|
module ActionController
|
4
|
-
# ActionController::Renderer allows to render arbitrary templates
|
4
|
+
# ActionController::Renderer allows you to render arbitrary templates
|
5
5
|
# without requirement of being in controller actions.
|
6
6
|
#
|
7
7
|
# You get a concrete renderer class by invoking ActionController::Base#renderer.
|
@@ -37,11 +37,11 @@ module ActionController
|
|
37
37
|
attr_reader :defaults, :controller
|
38
38
|
|
39
39
|
DEFAULTS = {
|
40
|
-
http_host:
|
40
|
+
http_host: "example.org",
|
41
41
|
https: false,
|
42
|
-
method:
|
43
|
-
script_name:
|
44
|
-
input:
|
42
|
+
method: "get",
|
43
|
+
script_name: "",
|
44
|
+
input: ""
|
45
45
|
}.freeze
|
46
46
|
|
47
47
|
# Create a new renderer instance for a specific controller class.
|
@@ -70,7 +70,7 @@ module ActionController
|
|
70
70
|
|
71
71
|
# Render templates with any options from ActionController::Base#render_to_string.
|
72
72
|
def render(*args)
|
73
|
-
raise
|
73
|
+
raise "missing controller" unless controller
|
74
74
|
|
75
75
|
request = ActionDispatch::Request.new @env
|
76
76
|
request.routes = controller._routes
|
@@ -84,27 +84,28 @@ module ActionController
|
|
84
84
|
private
|
85
85
|
def normalize_keys(env)
|
86
86
|
new_env = {}
|
87
|
-
env.each_pair { |k,v| new_env[rack_key_for(k)] = rack_value_for(k, v) }
|
88
|
-
new_env["rack.url_scheme"] = new_env["HTTPS"] == "on" ? "https" : "http"
|
87
|
+
env.each_pair { |k, v| new_env[rack_key_for(k)] = rack_value_for(k, v) }
|
89
88
|
new_env
|
90
89
|
end
|
91
90
|
|
92
91
|
RACK_KEY_TRANSLATION = {
|
93
|
-
http_host:
|
94
|
-
https:
|
95
|
-
method:
|
96
|
-
script_name:
|
97
|
-
input:
|
92
|
+
http_host: "HTTP_HOST",
|
93
|
+
https: "HTTPS",
|
94
|
+
method: "REQUEST_METHOD",
|
95
|
+
script_name: "SCRIPT_NAME",
|
96
|
+
input: "rack.input"
|
98
97
|
}
|
99
98
|
|
100
99
|
IDENTITY = ->(_) { _ }
|
101
100
|
|
102
101
|
RACK_VALUE_TRANSLATION = {
|
103
|
-
https: ->(v) { v ?
|
102
|
+
https: ->(v) { v ? "on" : "off" },
|
104
103
|
method: ->(v) { v.upcase },
|
105
104
|
}
|
106
105
|
|
107
|
-
def rack_key_for(key)
|
106
|
+
def rack_key_for(key)
|
107
|
+
RACK_KEY_TRANSLATION.fetch(key, key.to_s)
|
108
|
+
end
|
108
109
|
|
109
110
|
def rack_value_for(key, value)
|
110
111
|
RACK_VALUE_TRANSLATION.fetch(key, IDENTITY).call value
|
@@ -1,10 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
1
|
+
require "rack/session/abstract/id"
|
2
|
+
require "active_support/core_ext/hash/conversions"
|
3
|
+
require "active_support/core_ext/object/to_query"
|
4
|
+
require "active_support/core_ext/module/anonymous"
|
5
|
+
require "active_support/core_ext/hash/keys"
|
6
|
+
require "active_support/testing/constant_lookup"
|
7
|
+
require "action_controller/template_assertions"
|
8
|
+
require "rails-dom-testing"
|
8
9
|
|
9
10
|
module ActionController
|
10
11
|
class Metal
|
@@ -26,18 +27,20 @@ module ActionController
|
|
26
27
|
# Please use ActionDispatch::IntegrationTest going forward.
|
27
28
|
class TestRequest < ActionDispatch::TestRequest #:nodoc:
|
28
29
|
DEFAULT_ENV = ActionDispatch::TestRequest::DEFAULT_ENV.dup
|
29
|
-
DEFAULT_ENV.delete
|
30
|
+
DEFAULT_ENV.delete "PATH_INFO"
|
30
31
|
|
31
32
|
def self.new_session
|
32
33
|
TestSession.new
|
33
34
|
end
|
34
35
|
|
36
|
+
attr_reader :controller_class
|
37
|
+
|
35
38
|
# Create a new test request with default `env` values
|
36
|
-
def self.create
|
39
|
+
def self.create(controller_class)
|
37
40
|
env = {}
|
38
41
|
env = Rails.application.env_config.merge(env) if defined?(Rails.application) && Rails.application
|
39
42
|
env["rack.request.cookie_hash"] = {}.with_indifferent_access
|
40
|
-
new(default_env.merge(env), new_session)
|
43
|
+
new(default_env.merge(env), new_session, controller_class)
|
41
44
|
end
|
42
45
|
|
43
46
|
def self.default_env
|
@@ -45,13 +48,14 @@ module ActionController
|
|
45
48
|
end
|
46
49
|
private_class_method :default_env
|
47
50
|
|
48
|
-
def initialize(env, session)
|
51
|
+
def initialize(env, session, controller_class)
|
49
52
|
super(env)
|
50
53
|
|
51
54
|
self.session = session
|
52
55
|
self.session_options = TestSession::DEFAULT_OPTIONS.dup
|
56
|
+
@controller_class = controller_class
|
53
57
|
@custom_param_parsers = {
|
54
|
-
xml: lambda { |raw_post| Hash.from_xml(raw_post)[
|
58
|
+
xml: lambda { |raw_post| Hash.from_xml(raw_post)["hash"] }
|
55
59
|
}
|
56
60
|
end
|
57
61
|
|
@@ -60,7 +64,7 @@ module ActionController
|
|
60
64
|
end
|
61
65
|
|
62
66
|
def content_type=(type)
|
63
|
-
set_header
|
67
|
+
set_header "CONTENT_TYPE", type
|
64
68
|
end
|
65
69
|
|
66
70
|
def assign_parameters(routes, controller_path, action, parameters, generated_path, query_string_keys)
|
@@ -82,7 +86,7 @@ module ActionController
|
|
82
86
|
end
|
83
87
|
|
84
88
|
if get?
|
85
|
-
if
|
89
|
+
if query_string.blank?
|
86
90
|
self.query_string = non_path_parameters.to_query
|
87
91
|
end
|
88
92
|
else
|
@@ -90,8 +94,8 @@ module ActionController
|
|
90
94
|
self.content_type = ENCODER.content_type
|
91
95
|
data = ENCODER.build_multipart non_path_parameters
|
92
96
|
else
|
93
|
-
fetch_header(
|
94
|
-
set_header k,
|
97
|
+
fetch_header("CONTENT_TYPE") do |k|
|
98
|
+
set_header k, "application/x-www-form-urlencoded"
|
95
99
|
end
|
96
100
|
|
97
101
|
case content_mime_type.to_sym
|
@@ -152,9 +156,9 @@ module ActionController
|
|
152
156
|
|
153
157
|
private
|
154
158
|
|
155
|
-
|
156
|
-
|
157
|
-
|
159
|
+
def params_parsers
|
160
|
+
super.merge @custom_param_parsers
|
161
|
+
end
|
158
162
|
end
|
159
163
|
|
160
164
|
class LiveTestResponse < Live::Response
|
@@ -328,7 +332,6 @@ module ActionController
|
|
328
332
|
attr_reader :response, :request
|
329
333
|
|
330
334
|
module ClassMethods
|
331
|
-
|
332
335
|
# Sets the controller class name. Useful if the name can't be inferred from test class.
|
333
336
|
# Normalizes +controller_class+ before using.
|
334
337
|
#
|
@@ -351,7 +354,7 @@ module ActionController
|
|
351
354
|
end
|
352
355
|
|
353
356
|
def controller_class
|
354
|
-
if current_controller_class =
|
357
|
+
if current_controller_class = _controller_class
|
355
358
|
current_controller_class
|
356
359
|
else
|
357
360
|
self.controller_class = determine_default_controller_class(name)
|
@@ -385,57 +388,42 @@ module ActionController
|
|
385
388
|
#
|
386
389
|
# Note that the request method is not verified. The different methods are
|
387
390
|
# available to make the tests more expressive.
|
388
|
-
def get(action,
|
389
|
-
res =
|
391
|
+
def get(action, **args)
|
392
|
+
res = process(action, method: "GET", **args)
|
390
393
|
cookies.update res.cookies
|
391
394
|
res
|
392
395
|
end
|
393
396
|
|
394
397
|
# Simulate a POST request with the given parameters and set/volley the response.
|
395
398
|
# See +get+ for more details.
|
396
|
-
def post(action,
|
397
|
-
|
399
|
+
def post(action, **args)
|
400
|
+
process(action, method: "POST", **args)
|
398
401
|
end
|
399
402
|
|
400
403
|
# Simulate a PATCH request with the given parameters and set/volley the response.
|
401
404
|
# See +get+ for more details.
|
402
|
-
def patch(action,
|
403
|
-
|
405
|
+
def patch(action, **args)
|
406
|
+
process(action, method: "PATCH", **args)
|
404
407
|
end
|
405
408
|
|
406
409
|
# Simulate a PUT request with the given parameters and set/volley the response.
|
407
410
|
# See +get+ for more details.
|
408
|
-
def put(action,
|
409
|
-
|
411
|
+
def put(action, **args)
|
412
|
+
process(action, method: "PUT", **args)
|
410
413
|
end
|
411
414
|
|
412
415
|
# Simulate a DELETE request with the given parameters and set/volley the response.
|
413
416
|
# See +get+ for more details.
|
414
|
-
def delete(action,
|
415
|
-
|
417
|
+
def delete(action, **args)
|
418
|
+
process(action, method: "DELETE", **args)
|
416
419
|
end
|
417
420
|
|
418
421
|
# Simulate a HEAD request with the given parameters and set/volley the response.
|
419
422
|
# See +get+ for more details.
|
420
|
-
def head(action,
|
421
|
-
|
423
|
+
def head(action, **args)
|
424
|
+
process(action, method: "HEAD", **args)
|
422
425
|
end
|
423
426
|
|
424
|
-
def xml_http_request(*args)
|
425
|
-
ActiveSupport::Deprecation.warn(<<-MSG.strip_heredoc)
|
426
|
-
`xhr` and `xml_http_request` are deprecated and will be removed in Rails 5.1.
|
427
|
-
Switch to e.g. `post :create, params: { comment: { body: 'Honey bunny' } }, xhr: true`.
|
428
|
-
MSG
|
429
|
-
|
430
|
-
@request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
|
431
|
-
@request.env['HTTP_ACCEPT'] ||= [Mime[:js], Mime[:html], Mime[:xml], 'text/xml', '*/*'].join(', ')
|
432
|
-
__send__(*args).tap do
|
433
|
-
@request.env.delete 'HTTP_X_REQUESTED_WITH'
|
434
|
-
@request.env.delete 'HTTP_ACCEPT'
|
435
|
-
end
|
436
|
-
end
|
437
|
-
alias xhr :xml_http_request
|
438
|
-
|
439
427
|
# Simulate an HTTP request to +action+ by specifying request method,
|
440
428
|
# parameters and set/volley the response.
|
441
429
|
#
|
@@ -466,62 +454,40 @@ module ActionController
|
|
466
454
|
# respectively which will make tests more expressive.
|
467
455
|
#
|
468
456
|
# Note that the request method is not verified.
|
469
|
-
def process(action,
|
457
|
+
def process(action, method: "GET", params: {}, session: nil, body: nil, flash: {}, format: nil, xhr: false, as: nil)
|
470
458
|
check_required_ivars
|
471
459
|
|
472
|
-
if kwarg_request?(args)
|
473
|
-
parameters, session, body, flash, http_method, format, xhr, as = args[0].values_at(:params, :session, :body, :flash, :method, :format, :xhr, :as)
|
474
|
-
else
|
475
|
-
http_method, parameters, session, flash = args
|
476
|
-
format = nil
|
477
|
-
|
478
|
-
if parameters.is_a?(String) && http_method != 'HEAD'
|
479
|
-
body = parameters
|
480
|
-
parameters = nil
|
481
|
-
end
|
482
|
-
|
483
|
-
if parameters || session || flash
|
484
|
-
non_kwarg_request_warning
|
485
|
-
end
|
486
|
-
end
|
487
|
-
|
488
460
|
if body
|
489
|
-
@request.set_header
|
461
|
+
@request.set_header "RAW_POST_DATA", body
|
490
462
|
end
|
491
463
|
|
492
|
-
|
493
|
-
http_method = http_method.to_s.upcase
|
494
|
-
else
|
495
|
-
http_method = "GET"
|
496
|
-
end
|
497
|
-
|
498
|
-
parameters ||= {}
|
464
|
+
http_method = method.to_s.upcase
|
499
465
|
|
500
466
|
@html_document = nil
|
501
467
|
|
502
|
-
|
503
|
-
|
504
|
-
@request.set_header
|
505
|
-
@request.delete_header
|
468
|
+
cookies.update(@request.cookies)
|
469
|
+
cookies.update_cookies_from_jar
|
470
|
+
@request.set_header "HTTP_COOKIE", cookies.to_header
|
471
|
+
@request.delete_header "action_dispatch.cookies"
|
506
472
|
|
507
|
-
@request = TestRequest.new scrub_env!(@request.env), @request.session
|
473
|
+
@request = TestRequest.new scrub_env!(@request.env), @request.session, @controller.class
|
508
474
|
@response = build_response @response_klass
|
509
475
|
@response.request = @request
|
510
476
|
@controller.recycle!
|
511
477
|
|
512
|
-
@request.set_header
|
478
|
+
@request.set_header "REQUEST_METHOD", http_method
|
513
479
|
|
514
480
|
if as
|
515
481
|
@request.content_type = Mime[as].to_s
|
516
482
|
format ||= as
|
517
483
|
end
|
518
484
|
|
485
|
+
parameters = params.symbolize_keys
|
486
|
+
|
519
487
|
if format
|
520
488
|
parameters[:format] = format
|
521
489
|
end
|
522
490
|
|
523
|
-
parameters = parameters.symbolize_keys
|
524
|
-
|
525
491
|
generated_extras = @routes.generate_extras(parameters.merge(controller: controller_class_name, action: action.to_s))
|
526
492
|
generated_path = generated_path(generated_extras)
|
527
493
|
query_string_keys = query_parameter_names(generated_extras)
|
@@ -532,9 +498,9 @@ module ActionController
|
|
532
498
|
@request.flash.update(flash || {})
|
533
499
|
|
534
500
|
if xhr
|
535
|
-
@request.set_header
|
536
|
-
@request.fetch_header(
|
537
|
-
@request.set_header k, [Mime[:js], Mime[:html], Mime[:xml],
|
501
|
+
@request.set_header "HTTP_X_REQUESTED_WITH", "XMLHttpRequest"
|
502
|
+
@request.fetch_header("HTTP_ACCEPT") do |k|
|
503
|
+
@request.set_header k, [Mime[:js], Mime[:html], Mime[:xml], "text/xml", "*/*"].join(", ")
|
538
504
|
end
|
539
505
|
end
|
540
506
|
|
@@ -552,22 +518,23 @@ module ActionController
|
|
552
518
|
if @request.have_cookie_jar?
|
553
519
|
unless @request.cookie_jar.committed?
|
554
520
|
@request.cookie_jar.write(@response)
|
555
|
-
|
521
|
+
cookies.update(@request.cookie_jar.instance_variable_get(:@cookies))
|
556
522
|
end
|
557
523
|
end
|
558
524
|
@response.prepare!
|
559
525
|
|
560
526
|
if flash_value = @request.flash.to_session_value
|
561
|
-
@request.session[
|
527
|
+
@request.session["flash"] = flash_value
|
562
528
|
else
|
563
|
-
@request.session.delete(
|
529
|
+
@request.session.delete("flash")
|
564
530
|
end
|
565
531
|
|
566
532
|
if xhr
|
567
|
-
@request.delete_header
|
568
|
-
@request.delete_header
|
533
|
+
@request.delete_header "HTTP_X_REQUESTED_WITH"
|
534
|
+
@request.delete_header "HTTP_ACCEPT"
|
569
535
|
end
|
570
|
-
@request.query_string =
|
536
|
+
@request.query_string = ""
|
537
|
+
@request.env.delete "PATH_INFO"
|
571
538
|
|
572
539
|
@response.sent!
|
573
540
|
end
|
@@ -605,7 +572,7 @@ module ActionController
|
|
605
572
|
end
|
606
573
|
end
|
607
574
|
|
608
|
-
@request = TestRequest.create
|
575
|
+
@request = TestRequest.create(@controller.class)
|
609
576
|
@response = build_response @response_klass
|
610
577
|
@response.request = @request
|
611
578
|
|
@@ -629,68 +596,28 @@ module ActionController
|
|
629
596
|
|
630
597
|
private
|
631
598
|
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
end
|
640
|
-
|
641
|
-
def process_with_kwargs(http_method, action, *args)
|
642
|
-
if kwarg_request?(args)
|
643
|
-
args.first.merge!(method: http_method)
|
644
|
-
process(action, *args)
|
645
|
-
else
|
646
|
-
non_kwarg_request_warning if args.any?
|
647
|
-
|
648
|
-
args = args.unshift(http_method)
|
649
|
-
process(action, *args)
|
599
|
+
def scrub_env!(env)
|
600
|
+
env.delete_if { |k, v| k =~ /^(action_dispatch|rack)\.request/ }
|
601
|
+
env.delete_if { |k, v| k =~ /^action_dispatch\.rescue/ }
|
602
|
+
env.delete "action_dispatch.request.query_parameters"
|
603
|
+
env.delete "action_dispatch.request.request_parameters"
|
604
|
+
env["rack.input"] = StringIO.new
|
605
|
+
env
|
650
606
|
end
|
651
|
-
end
|
652
|
-
|
653
|
-
REQUEST_KWARGS = %i(params session flash method body xhr)
|
654
|
-
FORMAT_KWARGS = %i(format as)
|
655
|
-
def kwarg_request?(args)
|
656
|
-
args.size == 1 && args[0].respond_to?(:keys) && (
|
657
|
-
args[0].keys.all? { |k| FORMAT_KWARGS.include?(k) } ||
|
658
|
-
args[0].keys.any? { |k| REQUEST_KWARGS.include?(k) }
|
659
|
-
)
|
660
|
-
end
|
661
|
-
|
662
|
-
def non_kwarg_request_warning
|
663
|
-
ActiveSupport::Deprecation.warn(<<-MSG.strip_heredoc)
|
664
|
-
Using positional arguments in functional tests has been deprecated,
|
665
|
-
in favor of keyword arguments, and will be removed in Rails 5.1.
|
666
607
|
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
New keyword style:
|
671
|
-
get :show, params: { id: 1 }, flash: { notice: "This is a flash message" },
|
672
|
-
session: nil # Can safely be omitted.
|
673
|
-
MSG
|
674
|
-
end
|
675
|
-
|
676
|
-
def document_root_element
|
677
|
-
html_document.root
|
678
|
-
end
|
608
|
+
def document_root_element
|
609
|
+
html_document.root
|
610
|
+
end
|
679
611
|
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
612
|
+
def check_required_ivars
|
613
|
+
# Sanity check for required instance variables so we can give an
|
614
|
+
# understandable error message.
|
615
|
+
[:@routes, :@controller, :@request, :@response].each do |iv_name|
|
616
|
+
if !instance_variable_defined?(iv_name) || instance_variable_get(iv_name).nil?
|
617
|
+
raise "#{iv_name} is nil: make sure you set it in your test's setup method."
|
618
|
+
end
|
686
619
|
end
|
687
620
|
end
|
688
|
-
end
|
689
|
-
|
690
|
-
def html_format?(parameters)
|
691
|
-
return true unless parameters.key?(:format)
|
692
|
-
Mime.fetch(parameters[:format]) { Mime['html'] }.html?
|
693
|
-
end
|
694
621
|
end
|
695
622
|
|
696
623
|
include Behavior
|