diff options
author | Paul Barry <mail@paulbarry.com> | 2010-06-25 22:01:56 -0400 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-06-26 12:02:24 +0200 |
commit | 59b24ceb0c558715714e272737ca0ca06f6043d5 (patch) | |
tree | c92d8a099d328d1af1afbdaa388b4740ce270c68 /actionpack/test/dispatch | |
parent | 7bd85a8fc2d216a5e2b1d0380df572f782a54d1c (diff) | |
download | rails-59b24ceb0c558715714e272737ca0ca06f6043d5.tar.gz rails-59b24ceb0c558715714e272737ca0ca06f6043d5.tar.bz2 rails-59b24ceb0c558715714e272737ca0ca06f6043d5.zip |
Fixed normalize_path in Routing::Mapper to handle optional prefix segments with static and dynamic parts
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionpack/test/dispatch')
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 8881838aef..719323a85c 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -308,6 +308,10 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest match "index", :to => 'private#index' end + get "(/:username)/followers" => "followers#index" + get "/groups(/user/:username)" => "groups#index" + get "(/user/:username)/photos" => "photos#index" + match "whatever/:controller(/:action(/:id))" resource :profile do @@ -1466,6 +1470,48 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_url_generator_for_optional_prefix_dynamic_segment + with_test_routes do + get '/bob/followers' + assert_equal 'followers#index', @response.body + assert_equal 'http://www.example.com/bob/followers', + url_for(:controller => "followers", :action => "index", :username => "bob") + + get '/followers' + assert_equal 'followers#index', @response.body + assert_equal 'http://www.example.com/followers', + url_for(:controller => "followers", :action => "index", :username => nil) + end + end + + def test_url_generator_for_optional_suffix_static_and_dynamic_segment + with_test_routes do + get '/groups/user/bob' + assert_equal 'groups#index', @response.body + assert_equal 'http://www.example.com/groups/user/bob', + url_for(:controller => "groups", :action => "index", :username => "bob") + + get '/groups' + assert_equal 'groups#index', @response.body + assert_equal 'http://www.example.com/groups', + url_for(:controller => "groups", :action => "index", :username => nil) + end + end + + def test_url_generator_for_optional_prefix_static_and_dynamic_segment + with_test_routes do + get 'user/bob/photos' + assert_equal 'photos#index', @response.body + assert_equal 'http://www.example.com/user/bob/photos', + url_for(:controller => "photos", :action => "index", :username => "bob") + + get 'photos' + assert_equal 'photos#index', @response.body + assert_equal 'http://www.example.com/photos', + url_for(:controller => "photos", :action => "index", :username => nil) + end + end + private def with_test_routes yield |