diff options
author | Prem Sichanugrist <s@sikachu.com> | 2011-03-29 02:59:24 +0700 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2011-03-29 10:12:17 +0100 |
commit | 51551a0a5bd6f7e4116bc3759a4d7c15634643dc (patch) | |
tree | c5502f9dc06798f1e1321b69119c2b24b69c1095 /actionpack/test | |
parent | 3d1e7c2645af6c187d5ab6d2a02bd1e7b9ad7af3 (diff) | |
download | rails-51551a0a5bd6f7e4116bc3759a4d7c15634643dc.tar.gz rails-51551a0a5bd6f7e4116bc3759a4d7c15634643dc.tar.bz2 rails-51551a0a5bd6f7e4116bc3759a4d7c15634643dc.zip |
Update the wildcard route to be non-greedy by default, therefore be able to match the (.:format) segment [#6605 state:resolved]
After some discussion with Andrew White, it seems like this is a better approach for handling a wildcard route. However, user can still bring back the old behavior by supplying `:format => false` to the route.
Signed-off-by: Andrew White <andyw@pixeltrix.co.uk>
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/action_dispatch/routing/mapper_test.rb | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/actionpack/test/action_dispatch/routing/mapper_test.rb b/actionpack/test/action_dispatch/routing/mapper_test.rb index e21b271907..f90de735b6 100644 --- a/actionpack/test/action_dispatch/routing/mapper_test.rb +++ b/actionpack/test/action_dispatch/routing/mapper_test.rb @@ -25,6 +25,10 @@ module ActionDispatch def conditions routes.map { |x| x[1] } end + + def requirements + routes.map { |x| x[2] } + end end def test_initialize @@ -50,8 +54,34 @@ module ActionDispatch def test_map_wildcard fakeset = FakeSet.new mapper = Mapper.new fakeset - mapper.match '/*path', :to => 'pages#show', :as => :page + mapper.match '/*path', :to => 'pages#show' + assert_equal '/*path(.:format)', fakeset.conditions.first[:path_info] + assert_equal /.+?/, fakeset.requirements.first[:path] + end + + def test_map_wildcard_with_other_element + fakeset = FakeSet.new + mapper = Mapper.new fakeset + mapper.match '/*path/foo/:bar', :to => 'pages#show' + assert_equal '/*path/foo/:bar(.:format)', fakeset.conditions.first[:path_info] + assert_nil fakeset.requirements.first[:path] + end + + def test_map_wildcard_with_multiple_wildcard + fakeset = FakeSet.new + mapper = Mapper.new fakeset + mapper.match '/*foo/*bar', :to => 'pages#show' + assert_equal '/*foo/*bar(.:format)', fakeset.conditions.first[:path_info] + assert_nil fakeset.requirements.first[:foo] + assert_equal /.+?/, fakeset.requirements.first[:bar] + end + + def test_map_wildcard_with_format_false + fakeset = FakeSet.new + mapper = Mapper.new fakeset + mapper.match '/*path', :to => 'pages#show', :format => false assert_equal '/*path', fakeset.conditions.first[:path_info] + assert_nil fakeset.requirements.first[:path] end end end |