diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2010-08-22 18:48:26 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-08-22 16:17:26 -0300 |
commit | ae2c60734a0f71593709608710a0c7507bb8699e (patch) | |
tree | 142ba7641daf70cd79d2f046c934f3320383bb8f /actionpack/test | |
parent | d79a010976785ec42ed2b567c0f8a2e0fa7d15bf (diff) | |
download | rails-ae2c60734a0f71593709608710a0c7507bb8699e.tar.gz rails-ae2c60734a0f71593709608710a0c7507bb8699e.tar.bz2 rails-ae2c60734a0f71593709608710a0c7507bb8699e.zip |
Cache the symbolized path parameters using a instance variable in the request object rather than the environment hash. This it to prevent stale parameters in later routing constraints/redirects as only the normal path parameters are set by Rack::Mount.
Also if a constraint proc arity is more than one, pass the symbolized path parameters
as the first argument to match redirect proc args and provide easier access.
[#5157 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 44b83f3afc..c529db4771 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -427,6 +427,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get :preview, :on => :member end + scope '/countries/:country', :constraints => lambda { |params, req| %[all France].include?(params[:country]) } do + match '/', :to => 'countries#index' + match '/cities', :to => 'countries#cities' + end + + match '/countries/:country/(*other)', :to => redirect{ |params, req| params[:other] ? "/countries/all/#{params[:other]}" : '/countries/all' } + match '/:locale/*file.:format', :to => 'files#show', :file => /path\/to\/existing\/file/ end end @@ -2013,6 +2020,20 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_symbolized_path_parameters_is_not_stale + get '/countries/France' + assert_equal 'countries#index', @response.body + + get '/countries/France/cities' + assert_equal 'countries#cities', @response.body + + get '/countries/UK' + verify_redirect 'http://www.example.com/countries/all' + + get '/countries/UK/cities' + verify_redirect 'http://www.example.com/countries/all/cities' + end + private def with_test_routes yield |