Skip to content

Commit 98b8309

Browse files
committed
Remove deprecated support to non-keyword arguments #process
1 parent 31639ea commit 98b8309

File tree

3 files changed

+21
-181
lines changed

3 files changed

+21
-181
lines changed

Diff for: actionpack/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
* Remove deprecated support to non-keyword arguments in `ActionController::TestCase#process`,
2+
`#get`, `#post`, `#patch`, `#put`, `#delete`, and `#head`.
3+
4+
*Rafael Mendonça França*
5+
16
* Remove deprecated `xml_http_request` and `xhr` methods in `ActionController::TestCase`.
27

38
*Rafael Mendonça França*

Diff for: actionpack/lib/action_controller/test_case.rb

+16-70
Original file line numberDiff line numberDiff line change
@@ -386,40 +386,40 @@ def determine_default_controller_class(name)
386386
#
387387
# Note that the request method is not verified. The different methods are
388388
# available to make the tests more expressive.
389-
def get(action, *args)
390-
res = process_with_kwargs("GET", action, *args)
389+
def get(action, **args)
390+
res = process(action, method: "GET", **args)
391391
cookies.update res.cookies
392392
res
393393
end
394394

395395
# Simulate a POST request with the given parameters and set/volley the response.
396396
# See +get+ for more details.
397-
def post(action, *args)
398-
process_with_kwargs("POST", action, *args)
397+
def post(action, **args)
398+
process(action, method: "POST", **args)
399399
end
400400

401401
# Simulate a PATCH request with the given parameters and set/volley the response.
402402
# See +get+ for more details.
403-
def patch(action, *args)
404-
process_with_kwargs("PATCH", action, *args)
403+
def patch(action, **args)
404+
process(action, method: "PATCH", **args)
405405
end
406406

407407
# Simulate a PUT request with the given parameters and set/volley the response.
408408
# See +get+ for more details.
409-
def put(action, *args)
410-
process_with_kwargs("PUT", action, *args)
409+
def put(action, **args)
410+
process(action, method: "PUT", **args)
411411
end
412412

413413
# Simulate a DELETE request with the given parameters and set/volley the response.
414414
# See +get+ for more details.
415-
def delete(action, *args)
416-
process_with_kwargs("DELETE", action, *args)
415+
def delete(action, **args)
416+
process(action, method: "DELETE", **args)
417417
end
418418

419419
# Simulate a HEAD request with the given parameters and set/volley the response.
420420
# See +get+ for more details.
421-
def head(action, *args)
422-
process_with_kwargs("HEAD", action, *args)
421+
def head(action, **args)
422+
process(action, method: "HEAD", **args)
423423
end
424424

425425
# Simulate an HTTP request to +action+ by specifying request method,
@@ -452,36 +452,14 @@ def head(action, *args)
452452
# respectively which will make tests more expressive.
453453
#
454454
# Note that the request method is not verified.
455-
def process(action, *args)
455+
def process(action, method: "GET", params: {}, session: nil, body: nil, flash: {}, format: nil, xhr: false, as: nil)
456456
check_required_ivars
457457

458-
if kwarg_request?(args)
459-
parameters, session, body, flash, http_method, format, xhr, as = args[0].values_at(:params, :session, :body, :flash, :method, :format, :xhr, :as)
460-
else
461-
http_method, parameters, session, flash = args
462-
format = nil
463-
464-
if parameters.is_a?(String) && http_method != "HEAD"
465-
body = parameters
466-
parameters = nil
467-
end
468-
469-
if parameters || session || flash
470-
non_kwarg_request_warning
471-
end
472-
end
473-
474458
if body
475459
@request.set_header "RAW_POST_DATA", body
476460
end
477461

478-
if http_method
479-
http_method = http_method.to_s.upcase
480-
else
481-
http_method = "GET"
482-
end
483-
484-
parameters ||= {}
462+
http_method = method.to_s.upcase
485463

486464
@html_document = nil
487465

@@ -502,12 +480,12 @@ def process(action, *args)
502480
format ||= as
503481
end
504482

483+
parameters = params.symbolize_keys
484+
505485
if format
506486
parameters[:format] = format
507487
end
508488

509-
parameters = parameters.symbolize_keys
510-
511489
generated_extras = @routes.generate_extras(parameters.merge(controller: controller_class_name, action: action.to_s))
512490
generated_path = generated_path(generated_extras)
513491
query_string_keys = query_parameter_names(generated_extras)
@@ -626,38 +604,6 @@ def scrub_env!(env)
626604
env
627605
end
628606

629-
def process_with_kwargs(http_method, action, *args)
630-
if kwarg_request?(args)
631-
args.first.merge!(method: http_method)
632-
process(action, *args)
633-
else
634-
non_kwarg_request_warning if args.any?
635-
636-
args = args.unshift(http_method)
637-
process(action, *args)
638-
end
639-
end
640-
641-
REQUEST_KWARGS = %i(params session flash method body xhr)
642-
def kwarg_request?(args)
643-
args[0].respond_to?(:keys) && (
644-
(args[0].key?(:format) && args[0].keys.size == 1) ||
645-
args[0].keys.any? { |k| REQUEST_KWARGS.include?(k) }
646-
)
647-
end
648-
649-
def non_kwarg_request_warning
650-
ActiveSupport::Deprecation.warn(<<-MSG.strip_heredoc)
651-
ActionController::TestCase HTTP request methods will accept only
652-
keyword arguments in future Rails versions.
653-
654-
Examples:
655-
656-
get :show, params: { id: 1 }, session: { user_id: 1 }
657-
process :update, method: :post, params: { id: 1 }
658-
MSG
659-
end
660-
661607
def document_root_element
662608
html_document.root
663609
end

Diff for: actionpack/test/controller/test_case_test.rb

-111
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,6 @@ def test_body_stream
229229
assert_equal params.to_query, @response.body
230230
end
231231

232-
def test_deprecated_body_stream
233-
params = Hash[:page, { name: "page name" }, "some key", 123]
234-
235-
assert_deprecated { post :render_body, params.dup }
236-
237-
assert_equal params.to_query, @response.body
238-
end
239-
240232
def test_document_body_and_params_with_post
241233
post :test_params, params: { id: 1 }
242234
assert_equal({ "id"=>"1", "controller"=>"test_case_test/test", "action"=>"test_params" }, ::JSON.parse(@response.body))
@@ -247,21 +239,11 @@ def test_document_body_with_post
247239
assert_equal "document body", @response.body
248240
end
249241

250-
def test_deprecated_document_body_with_post
251-
assert_deprecated { post :render_body, "document body" }
252-
assert_equal "document body", @response.body
253-
end
254-
255242
def test_document_body_with_put
256243
put :render_body, body: "document body"
257244
assert_equal "document body", @response.body
258245
end
259246

260-
def test_deprecated_document_body_with_put
261-
assert_deprecated { put :render_body, "document body" }
262-
assert_equal "document body", @response.body
263-
end
264-
265247
def test_head
266248
head :test_params
267249
assert_equal 200, @response.status
@@ -272,23 +254,13 @@ def test_process_without_flash
272254
assert_equal "><", flash["test"]
273255
end
274256

275-
def test_deprecated_process_with_flash
276-
assert_deprecated { process :set_flash, "GET", nil, nil, "test" => "value" }
277-
assert_equal ">value<", flash["test"]
278-
end
279-
280257
def test_process_with_flash
281258
process :set_flash,
282259
method: "GET",
283260
flash: { "test" => "value" }
284261
assert_equal ">value<", flash["test"]
285262
end
286263

287-
def test_deprecated_process_with_flash_now
288-
assert_deprecated { process :set_flash_now, "GET", nil, nil, "test_now" => "value_now" }
289-
assert_equal ">value_now<", flash["test_now"]
290-
end
291-
292264
def test_process_with_flash_now
293265
process :set_flash_now,
294266
method: "GET",
@@ -311,14 +283,6 @@ def test_process_with_session
311283
assert_equal "it works", session[:symbol], "Test session hash should allow indifferent access"
312284
end
313285

314-
def test_process_with_session_arg
315-
assert_deprecated { process :no_op, "GET", nil, "string" => "value1", symbol: "value2" }
316-
assert_equal "value1", session["string"]
317-
assert_equal "value1", session[:string]
318-
assert_equal "value2", session["symbol"]
319-
assert_equal "value2", session[:symbol]
320-
end
321-
322286
def test_process_with_session_kwarg
323287
process :no_op, method: "GET", session: { "string" => "value1", symbol: "value2" }
324288
assert_equal "value1", session["string"]
@@ -327,31 +291,13 @@ def test_process_with_session_kwarg
327291
assert_equal "value2", session[:symbol]
328292
end
329293

330-
def test_deprecated_process_merges_session_arg
331-
session[:foo] = "bar"
332-
assert_deprecated {
333-
get :no_op, nil, bar: "baz"
334-
}
335-
assert_equal "bar", session[:foo]
336-
assert_equal "baz", session[:bar]
337-
end
338-
339294
def test_process_merges_session_arg
340295
session[:foo] = "bar"
341296
get :no_op, session: { bar: "baz" }
342297
assert_equal "bar", session[:foo]
343298
assert_equal "baz", session[:bar]
344299
end
345300

346-
def test_deprecated_merged_session_arg_is_retained_across_requests
347-
assert_deprecated {
348-
get :no_op, nil, foo: "bar"
349-
}
350-
assert_equal "bar", session[:foo]
351-
get :no_op
352-
assert_equal "bar", session[:foo]
353-
end
354-
355301
def test_merged_session_arg_is_retained_across_requests
356302
get :no_op, session: { foo: "bar" }
357303
assert_equal "bar", session[:foo]
@@ -393,11 +339,6 @@ def test_process_with_symbol_method
393339
assert_equal "/test_case_test/test/test_uri", @response.body
394340
end
395341

396-
def test_deprecated_process_with_request_uri_with_params
397-
assert_deprecated { process :test_uri, "GET", id: 7 }
398-
assert_equal "/test_case_test/test/test_uri/7", @response.body
399-
end
400-
401342
def test_process_with_request_uri_with_params
402343
process :test_uri,
403344
method: "GET",
@@ -406,12 +347,6 @@ def test_process_with_request_uri_with_params
406347
assert_equal "/test_case_test/test/test_uri/7", @response.body
407348
end
408349

409-
def test_deprecated_process_with_request_uri_with_params_with_explicit_uri
410-
@request.env["PATH_INFO"] = "/explicit/uri"
411-
assert_deprecated { process :test_uri, "GET", id: 7 }
412-
assert_equal "/explicit/uri", @response.body
413-
end
414-
415350
def test_process_with_request_uri_with_params_with_explicit_uri
416351
@request.env["PATH_INFO"] = "/explicit/uri"
417352
process :test_uri, method: "GET", params: { id: 7 }
@@ -491,20 +426,6 @@ def test_assert_routing_with_glob
491426
end
492427
end
493428

494-
def test_deprecated_params_passing
495-
assert_deprecated {
496-
get :test_params, page: { name: "Page name", month: "4", year: "2004", day: "6" }
497-
}
498-
parsed_params = ::JSON.parse(@response.body)
499-
assert_equal(
500-
{
501-
"controller" => "test_case_test/test", "action" => "test_params",
502-
"page" => { "name" => "Page name", "month" => "4", "year" => "2004", "day" => "6" }
503-
},
504-
parsed_params
505-
)
506-
end
507-
508429
def test_params_passing
509430
get :test_params, params: {
510431
page: {
@@ -589,16 +510,6 @@ def test_params_passing_path_parameter_is_string_when_not_html_request
589510
)
590511
end
591512

592-
def test_deprecated_params_passing_path_parameter_is_string_when_not_html_request
593-
assert_deprecated { get :test_params, format: "json", id: 1 }
594-
parsed_params = ::JSON.parse(@response.body)
595-
assert_equal(
596-
{ "controller" => "test_case_test/test", "action" => "test_params",
597-
"format" => "json", "id" => "1" },
598-
parsed_params
599-
)
600-
end
601-
602513
def test_params_passing_with_frozen_values
603514
assert_nothing_raised do
604515
get :test_params, params: {
@@ -683,11 +594,6 @@ def test_id_converted_to_string
683594
assert_kind_of String, @request.path_parameters[:id]
684595
end
685596

686-
def test_deprecared_id_converted_to_string
687-
assert_deprecated { get :test_params, id: 20, foo: Object.new }
688-
assert_kind_of String, @request.path_parameters[:id]
689-
end
690-
691597
def test_array_path_parameter_handled_properly
692598
with_routing do |set|
693599
set.draw do
@@ -757,14 +663,6 @@ def test_xhr_with_session
757663
assert_equal "it works", session[:symbol], "Test session hash should allow indifferent access"
758664
end
759665

760-
def test_deprecated_params_reset_between_post_requests
761-
assert_deprecated { post :no_op, foo: "bar" }
762-
assert_equal "bar", @request.params[:foo]
763-
764-
post :no_op
765-
assert @request.params[:foo].blank?
766-
end
767-
768666
def test_params_reset_between_post_requests
769667
post :no_op, params: { foo: "bar" }
770668
assert_equal "bar", @request.params[:foo]
@@ -964,15 +862,6 @@ def test_fixture_file_upload_ignores_nil_fixture_path
964862
assert_equal File.open("#{FILES_DIR}/mona_lisa.jpg", READ_PLAIN).read, uploaded_file.read
965863
end
966864

967-
def test_deprecated_action_dispatch_uploaded_file_upload
968-
filename = "mona_lisa.jpg"
969-
path = "#{FILES_DIR}/#{filename}"
970-
assert_deprecated {
971-
post :test_file_upload, file: Rack::Test::UploadedFile.new(path, "image/jpg", true)
972-
}
973-
assert_equal "159528", @response.body
974-
end
975-
976865
def test_action_dispatch_uploaded_file_upload
977866
filename = "mona_lisa.jpg"
978867
path = "#{FILES_DIR}/#{filename}"

0 commit comments

Comments
 (0)