File tree 4 files changed +33
-2
lines changed
4 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -172,6 +172,7 @@ def to_code
172
172
env['router.request'] = request
173
173
env['router.params'] ||= {}
174
174
#{ "env['router.params'].merge!(Hash[#{ param_names . inspect } .zip(request.params)])" if dynamic? }
175
+ env['router.params'] = env['router.params'].with_indifferent_access
175
176
@router.rewrite#{ "_partial" if route . match_partially } _path_info(env, request)
176
177
response = @router.process_destination_path(#{ path_ivar } , env)
177
178
return response unless router.pass_on_response(response)
@@ -959,10 +960,12 @@ def recognize_path(path)
959
960
#
960
961
def current_path ( *path_params )
961
962
if path_params . last . is_a? ( Hash )
962
- path_params [ -1 ] = params . merge ( path_params [ -1 ] )
963
+ path_params [ -1 ] = params . merge ( path_params [ -1 ] . with_indifferent_access )
963
964
else
964
965
path_params << params
965
966
end
967
+
968
+ path_params [ -1 ] = path_params [ -1 ] . symbolize_keys
966
969
@route . path ( *path_params )
967
970
end
968
971
Original file line number Diff line number Diff line change 4
4
require 'active_support/core_ext/module/aliasing' # alias_method_chain
5
5
require 'active_support/core_ext/hash/keys' # symbolize_keys
6
6
require 'active_support/core_ext/hash/reverse_merge' # reverse_merge
7
+ require 'active_support/core_ext/hash/indifferent_access'
7
8
require 'active_support/core_ext/hash/slice' # slice
8
9
require 'active_support/core_ext/object/blank' # present?
9
10
require 'active_support/core_ext/array/extract_options' # extract_options
Original file line number Diff line number Diff line change 65
65
assert_equal 200 , status
66
66
67
67
get "/complex_2_demo/var/destroy/variable"
68
- assert_equal '{:id =>"variable"}' , body
68
+ assert_equal '{"id" =>"variable"}' , body
69
69
ensure
70
70
# Now we need to prevent to commit a new changed file so we revert it
71
71
File . open ( Complex1Demo . app_file , "w" ) { |f | f . write ( buffer ) }
Original file line number Diff line number Diff line change @@ -1790,6 +1790,33 @@ def authorize(username, password)
1790
1790
assert ok?
1791
1791
end
1792
1792
1793
+ should 'return params as a HashWithIndifferentAccess object via GET' do
1794
+ mock_app do
1795
+ get ( '/foo/:bar' ) { "#{ params [ "bar" ] } #{ params [ :bar ] } " }
1796
+ get ( :foo , :map => '/prefix/:var' ) { "#{ params [ "var" ] } #{ params [ :var ] } " }
1797
+ end
1798
+
1799
+ get ( '/foo/some_text' )
1800
+ assert_equal "some_text some_text" , body
1801
+
1802
+ get ( '/prefix/var' )
1803
+ assert_equal "var var" , body
1804
+ end
1805
+
1806
+ should 'return params as a HashWithIndifferentAccess object via POST' do
1807
+ mock_app do
1808
+ post ( '/user' ) do
1809
+ "#{ params [ "user" ] [ "full_name" ] } #{ params [ :user ] [ :full_name ] } "
1810
+ end
1811
+ end
1812
+
1813
+ post '/user' , { :user => { :full_name => 'example user' } }
1814
+ assert_equal "example user example user" , body
1815
+
1816
+ post '/user' , { "user" => { "full_name" => 'example user' } }
1817
+ assert_equal "example user example user" , body
1818
+ end
1819
+
1793
1820
should 'have MethodOverride middleware with more options' do
1794
1821
mock_app do
1795
1822
put ( '/hi' , :provides => [ :json ] ) { 'hi' }
You can’t perform that action at this time.
0 commit comments