Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use symbol keys for path_parameters

  • Loading branch information...
commit 925bd975663df2e0e8613507a7c95a6945a277ac 1 parent 0e7e4f7
@tenderlove tenderlove authored
View
2  actionpack/lib/action_controller/metal/url_for.rb
@@ -27,7 +27,7 @@ def url_options
:host => request.host,
:port => request.optional_port,
:protocol => request.protocol,
- :_recall => request.symbolized_path_parameters
+ :_recall => request.path_parameters
}.merge(super).freeze
if (same_origin = _routes.equal?(env["action_dispatch.routes".freeze])) ||
View
10 actionpack/lib/action_controller/test_case.rb
@@ -199,7 +199,7 @@ def assign_parameters(routes, controller_path, action, parameters = {})
value = value.dup
end
- if extra_keys.include?(key.to_sym)
+ if extra_keys.include?(key)
non_path_parameters[key] = value
else
if value.is_a?(Array)
@@ -208,7 +208,7 @@ def assign_parameters(routes, controller_path, action, parameters = {})
value = value.to_param
end
- path_parameters[key.to_s] = value
+ path_parameters[key] = value
end
end
@@ -583,6 +583,7 @@ def process(action, http_method = 'GET', *args)
end
parameters, session, flash = args
+ parameters ||= {}
# Ensure that numbers and symbols passed as params are converted to
# proper params, as is the case when engaging rack.
@@ -601,7 +602,6 @@ def process(action, http_method = 'GET', *args)
@request.env['REQUEST_METHOD'] = http_method
- parameters ||= {}
controller_class_name = @controller.class.anonymous? ?
"anonymous" :
@controller.class.controller_path
@@ -695,7 +695,7 @@ def build_request_uri(action, parameters)
:only_path => true,
:action => action,
:relative_url_root => nil,
- :_recall => @request.symbolized_path_parameters)
+ :_recall => @request.path_parameters)
url, query_string = @routes.url_for(options).split("?", 2)
@@ -706,7 +706,7 @@ def build_request_uri(action, parameters)
end
def html_format?(parameters)
- return true unless parameters.is_a?(Hash)
+ return true unless parameters.key?(:format)
Mime.fetch(parameters[:format]) { Mime['html'] }.html?
end
end
View
2  actionpack/lib/action_dispatch/routing/mapper.rb
@@ -47,7 +47,7 @@ def call(env)
private
def constraint_args(constraint, request)
- constraint.arity == 1 ? [request] : [request.symbolized_path_parameters, request]
+ constraint.arity == 1 ? [request] : [request.path_parameters, request]
end
end
View
4 actionpack/lib/action_dispatch/routing/redirection.rb
@@ -19,13 +19,13 @@ def call(env)
# If any of the path parameters has an invalid encoding then
# raise since it's likely to trigger errors further on.
- req.symbolized_path_parameters.each do |key, value|
+ req.path_parameters.each do |key, value|
unless value.valid_encoding?
raise ActionController::BadRequest, "Invalid parameter: #{key} => #{value}"
end
end
- uri = URI.parse(path(req.symbolized_path_parameters, req))
+ uri = URI.parse(path(req.path_parameters, req))
unless uri.host
if relative_path?(uri.path)
View
4 actionpack/lib/action_dispatch/routing/route_set.rb
@@ -707,8 +707,8 @@ def recognize_path(path, environment = {})
params[key] = URI.parser.unescape(value)
end
end
- old_params = env[::ActionDispatch::Routing::RouteSet::PARAMETERS_KEY]
- env[::ActionDispatch::Routing::RouteSet::PARAMETERS_KEY] = (old_params || {}).merge(params)
+ old_params = req.path_parameters
+ req.path_parameters = old_params.merge params
dispatcher = route.app
while dispatcher.is_a?(Mapper::Constraints) && dispatcher.matches?(env) do
dispatcher = dispatcher.app
View
10 actionpack/test/controller/test_case_test.rb
@@ -662,7 +662,7 @@ def test_params_passing_doesnt_modify_in_place
def test_id_converted_to_string
get :test_params, :id => 20, :foo => Object.new
- assert_kind_of String, @request.path_parameters['id']
+ assert_kind_of String, @request.path_parameters[:id]
end
def test_array_path_parameter_handled_properly
@@ -673,17 +673,17 @@ def test_array_path_parameter_handled_properly
end
get :test_params, :path => ['hello', 'world']
- assert_equal ['hello', 'world'], @request.path_parameters['path']
- assert_equal 'hello/world', @request.path_parameters['path'].to_param
+ assert_equal ['hello', 'world'], @request.path_parameters[:path]
+ assert_equal 'hello/world', @request.path_parameters[:path].to_param
end
end
def test_assert_realistic_path_parameters
get :test_params, :id => 20, :foo => Object.new
- # All elements of path_parameters should use string keys
+ # All elements of path_parameters should use Symbol keys
@request.path_parameters.keys.each do |key|
- assert_kind_of String, key
+ assert_kind_of Symbol, key
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.