From b87decc8fcff252aa78e1914452a0dc94bf06d2c Mon Sep 17 00:00:00 2001 From: Paul Barry Date: Fri, 11 Jun 2010 15:54:52 -0400 Subject: [PATCH] [#4832] Added failing test for optional static and dynamic prefix route --- actionpack/test/dispatch/routing_test.rb | 48 +++++++++++++++++++++++++++++- 1 files changed, 47 insertions(+), 1 deletions(-) diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index e13960e..52f71e8 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -232,6 +232,10 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest match '/' => 'mes#index' end + get "(/:username)/followers" => "followers#index" + get "/groups(/user/:username)" => "groups#index" + get "(/user/:username)/posts" => "posts#index" + match "whatever/:controller(/:action(/:id))" resource :profile do @@ -823,7 +827,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_equal '/account/admin/subscription', account_admin_subscription_path end end - + def test_namespace_nested_in_resources with_test_routes do get '/clients/1/google/account' @@ -1078,6 +1082,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/posts' + assert_equal 'posts#index', @response.body + assert_equal 'http://www.example.com/user/bob/posts', + url_for(:controller => "posts", :action => "index", :username => "bob") + + get 'posts' + assert_equal 'posts#index', @response.body + assert_equal 'http://www.example.com/posts', + url_for(:controller => "posts", :action => "index", :username => nil) + end + end + def test_assert_recognizes_account_overview with_test_routes do assert_recognizes({:controller => "account", :action => "overview"}, "/account/overview") -- 1.6.6.1