Permalink
Browse files

Remove deprecated support to non-keyword arguments #process

  • Loading branch information...
rafaelfranca committed May 23, 2016
1 parent 31639ea commit 98b8309569a326910a723f521911e54994b112fb
Showing with 21 additions and 181 deletions.
  1. +5 −0 actionpack/CHANGELOG.md
  2. +16 −70 actionpack/lib/action_controller/test_case.rb
  3. +0 −111 actionpack/test/controller/test_case_test.rb
View
@@ -1,3 +1,8 @@
* Remove deprecated support to non-keyword arguments in `ActionController::TestCase#process`,
`#get`, `#post`, `#patch`, `#put`, `#delete`, and `#head`.
*Rafael Mendonça França*
* Remove deprecated `xml_http_request` and `xhr` methods in `ActionController::TestCase`.
*Rafael Mendonça França*
@@ -386,40 +386,40 @@ def determine_default_controller_class(name)
#
# Note that the request method is not verified. The different methods are
# available to make the tests more expressive.
def get(action, *args)
res = process_with_kwargs("GET", action, *args)
def get(action, **args)
res = process(action, method: "GET", **args)
cookies.update res.cookies
res
end
# Simulate a POST request with the given parameters and set/volley the response.
# See +get+ for more details.
def post(action, *args)
process_with_kwargs("POST", action, *args)
def post(action, **args)
process(action, method: "POST", **args)
end
# Simulate a PATCH request with the given parameters and set/volley the response.
# See +get+ for more details.
def patch(action, *args)
process_with_kwargs("PATCH", action, *args)
def patch(action, **args)
process(action, method: "PATCH", **args)
end
# Simulate a PUT request with the given parameters and set/volley the response.
# See +get+ for more details.
def put(action, *args)
process_with_kwargs("PUT", action, *args)
def put(action, **args)
process(action, method: "PUT", **args)
end
# Simulate a DELETE request with the given parameters and set/volley the response.
# See +get+ for more details.
def delete(action, *args)
process_with_kwargs("DELETE", action, *args)
def delete(action, **args)
process(action, method: "DELETE", **args)
end
# Simulate a HEAD request with the given parameters and set/volley the response.
# See +get+ for more details.
def head(action, *args)
process_with_kwargs("HEAD", action, *args)
def head(action, **args)
process(action, method: "HEAD", **args)
end
# Simulate an HTTP request to +action+ by specifying request method,
@@ -452,36 +452,14 @@ def head(action, *args)
# respectively which will make tests more expressive.
#
# Note that the request method is not verified.
def process(action, *args)
def process(action, method: "GET", params: {}, session: nil, body: nil, flash: {}, format: nil, xhr: false, as: nil)
check_required_ivars
if kwarg_request?(args)
parameters, session, body, flash, http_method, format, xhr, as = args[0].values_at(:params, :session, :body, :flash, :method, :format, :xhr, :as)
else
http_method, parameters, session, flash = args
format = nil
if parameters.is_a?(String) && http_method != "HEAD"
body = parameters
parameters = nil
end
if parameters || session || flash
non_kwarg_request_warning
end
end
if body
@request.set_header "RAW_POST_DATA", body
end
if http_method
http_method = http_method.to_s.upcase
else
http_method = "GET"
end
parameters ||= {}
http_method = method.to_s.upcase
@html_document = nil
@@ -502,12 +480,12 @@ def process(action, *args)
format ||= as
end
parameters = params.symbolize_keys
if format
parameters[:format] = format
end
parameters = parameters.symbolize_keys
generated_extras = @routes.generate_extras(parameters.merge(controller: controller_class_name, action: action.to_s))
generated_path = generated_path(generated_extras)
query_string_keys = query_parameter_names(generated_extras)
@@ -626,38 +604,6 @@ def scrub_env!(env)
env
end
def process_with_kwargs(http_method, action, *args)
if kwarg_request?(args)
args.first.merge!(method: http_method)
process(action, *args)
else
non_kwarg_request_warning if args.any?
args = args.unshift(http_method)
process(action, *args)
end
end
REQUEST_KWARGS = %i(params session flash method body xhr)
def kwarg_request?(args)
args[0].respond_to?(:keys) && (
(args[0].key?(:format) && args[0].keys.size == 1) ||
args[0].keys.any? { |k| REQUEST_KWARGS.include?(k) }
)
end
def non_kwarg_request_warning
ActiveSupport::Deprecation.warn(<<-MSG.strip_heredoc)
ActionController::TestCase HTTP request methods will accept only
keyword arguments in future Rails versions.
Examples:
get :show, params: { id: 1 }, session: { user_id: 1 }
process :update, method: :post, params: { id: 1 }
MSG
end
def document_root_element
html_document.root
end
@@ -229,14 +229,6 @@ def test_body_stream
assert_equal params.to_query, @response.body
end
def test_deprecated_body_stream
params = Hash[:page, { name: "page name" }, "some key", 123]
assert_deprecated { post :render_body, params.dup }
assert_equal params.to_query, @response.body
end
def test_document_body_and_params_with_post
post :test_params, params: { id: 1 }
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
assert_equal "document body", @response.body
end
def test_deprecated_document_body_with_post
assert_deprecated { post :render_body, "document body" }
assert_equal "document body", @response.body
end
def test_document_body_with_put
put :render_body, body: "document body"
assert_equal "document body", @response.body
end
def test_deprecated_document_body_with_put
assert_deprecated { put :render_body, "document body" }
assert_equal "document body", @response.body
end
def test_head
head :test_params
assert_equal 200, @response.status
@@ -272,23 +254,13 @@ def test_process_without_flash
assert_equal "><", flash["test"]
end
def test_deprecated_process_with_flash
assert_deprecated { process :set_flash, "GET", nil, nil, "test" => "value" }
assert_equal ">value<", flash["test"]
end
def test_process_with_flash
process :set_flash,
method: "GET",
flash: { "test" => "value" }
assert_equal ">value<", flash["test"]
end
def test_deprecated_process_with_flash_now
assert_deprecated { process :set_flash_now, "GET", nil, nil, "test_now" => "value_now" }
assert_equal ">value_now<", flash["test_now"]
end
def test_process_with_flash_now
process :set_flash_now,
method: "GET",
@@ -311,14 +283,6 @@ def test_process_with_session
assert_equal "it works", session[:symbol], "Test session hash should allow indifferent access"
end
def test_process_with_session_arg
assert_deprecated { process :no_op, "GET", nil, "string" => "value1", symbol: "value2" }
assert_equal "value1", session["string"]
assert_equal "value1", session[:string]
assert_equal "value2", session["symbol"]
assert_equal "value2", session[:symbol]
end
def test_process_with_session_kwarg
process :no_op, method: "GET", session: { "string" => "value1", symbol: "value2" }
assert_equal "value1", session["string"]
@@ -327,31 +291,13 @@ def test_process_with_session_kwarg
assert_equal "value2", session[:symbol]
end
def test_deprecated_process_merges_session_arg
session[:foo] = "bar"
assert_deprecated {
get :no_op, nil, bar: "baz"
}
assert_equal "bar", session[:foo]
assert_equal "baz", session[:bar]
end
def test_process_merges_session_arg
session[:foo] = "bar"
get :no_op, session: { bar: "baz" }
assert_equal "bar", session[:foo]
assert_equal "baz", session[:bar]
end
def test_deprecated_merged_session_arg_is_retained_across_requests
assert_deprecated {
get :no_op, nil, foo: "bar"
}
assert_equal "bar", session[:foo]
get :no_op
assert_equal "bar", session[:foo]
end
def test_merged_session_arg_is_retained_across_requests
get :no_op, session: { foo: "bar" }
assert_equal "bar", session[:foo]
@@ -393,11 +339,6 @@ def test_process_with_symbol_method
assert_equal "/test_case_test/test/test_uri", @response.body
end
def test_deprecated_process_with_request_uri_with_params
assert_deprecated { process :test_uri, "GET", id: 7 }
assert_equal "/test_case_test/test/test_uri/7", @response.body
end
def test_process_with_request_uri_with_params
process :test_uri,
method: "GET",
@@ -406,12 +347,6 @@ def test_process_with_request_uri_with_params
assert_equal "/test_case_test/test/test_uri/7", @response.body
end
def test_deprecated_process_with_request_uri_with_params_with_explicit_uri
@request.env["PATH_INFO"] = "/explicit/uri"
assert_deprecated { process :test_uri, "GET", id: 7 }
assert_equal "/explicit/uri", @response.body
end
def test_process_with_request_uri_with_params_with_explicit_uri
@request.env["PATH_INFO"] = "/explicit/uri"
process :test_uri, method: "GET", params: { id: 7 }
@@ -491,20 +426,6 @@ def test_assert_routing_with_glob
end
end
def test_deprecated_params_passing
assert_deprecated {
get :test_params, page: { name: "Page name", month: "4", year: "2004", day: "6" }
}
parsed_params = ::JSON.parse(@response.body)
assert_equal(
{
"controller" => "test_case_test/test", "action" => "test_params",
"page" => { "name" => "Page name", "month" => "4", "year" => "2004", "day" => "6" }
},
parsed_params
)
end
def test_params_passing
get :test_params, params: {
page: {
@@ -589,16 +510,6 @@ def test_params_passing_path_parameter_is_string_when_not_html_request
)
end
def test_deprecated_params_passing_path_parameter_is_string_when_not_html_request
assert_deprecated { get :test_params, format: "json", id: 1 }
parsed_params = ::JSON.parse(@response.body)
assert_equal(
{ "controller" => "test_case_test/test", "action" => "test_params",
"format" => "json", "id" => "1" },
parsed_params
)
end
def test_params_passing_with_frozen_values
assert_nothing_raised do
get :test_params, params: {
@@ -683,11 +594,6 @@ def test_id_converted_to_string
assert_kind_of String, @request.path_parameters[:id]
end
def test_deprecared_id_converted_to_string
assert_deprecated { get :test_params, id: 20, foo: Object.new }
assert_kind_of String, @request.path_parameters[:id]
end
def test_array_path_parameter_handled_properly
with_routing do |set|
set.draw do
@@ -757,14 +663,6 @@ def test_xhr_with_session
assert_equal "it works", session[:symbol], "Test session hash should allow indifferent access"
end
def test_deprecated_params_reset_between_post_requests
assert_deprecated { post :no_op, foo: "bar" }
assert_equal "bar", @request.params[:foo]
post :no_op
assert @request.params[:foo].blank?
end
def test_params_reset_between_post_requests
post :no_op, params: { foo: "bar" }
assert_equal "bar", @request.params[:foo]
@@ -964,15 +862,6 @@ def test_fixture_file_upload_ignores_nil_fixture_path
assert_equal File.open("#{FILES_DIR}/mona_lisa.jpg", READ_PLAIN).read, uploaded_file.read
end
def test_deprecated_action_dispatch_uploaded_file_upload
filename = "mona_lisa.jpg"
path = "#{FILES_DIR}/#{filename}"
assert_deprecated {
post :test_file_upload, file: Rack::Test::UploadedFile.new(path, "image/jpg", true)
}
assert_equal "159528", @response.body
end
def test_action_dispatch_uploaded_file_upload
filename = "mona_lisa.jpg"
path = "#{FILES_DIR}/#{filename}"

0 comments on commit 98b8309

Please sign in to comment.