diff options
author | Nicholas Seckar <nseckar@gmail.com> | 2005-07-13 23:13:15 +0000 |
---|---|---|
committer | Nicholas Seckar <nseckar@gmail.com> | 2005-07-13 23:13:15 +0000 |
commit | 9314793239e3728a457d8048a02b334b8955dd23 (patch) | |
tree | e68f99c5e3c6217d20e44989450454fcd944916d /actionpack/test/controller | |
parent | f92f6a1301aea5a920ec212ec3274551f2767e15 (diff) | |
download | rails-9314793239e3728a457d8048a02b334b8955dd23.tar.gz rails-9314793239e3728a457d8048a02b334b8955dd23.tar.bz2 rails-9314793239e3728a457d8048a02b334b8955dd23.zip |
Named routes should not provide nil values to url_for. Includes factoring and extra testcases.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1825 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r-- | actionpack/test/controller/routing_test.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 3bc240b44d..946dba6c06 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -689,6 +689,23 @@ class RouteSetTests < Test::Unit::TestCase end end + def test_named_route_with_regexps + rs.draw do |map| + rs.article 'page/:year/:month/:day/:title', :controller => 'page', :action => 'show', + :year => /^\d+$/, :month => /^\d+$/, :day => /^\d+$/ + rs.connect ':controller/:action/:id' + end + x = setup_for_named_route + assert_equal( + {:controller => '/page', :action => 'show', :title => 'hi'}, + x.new.send(:article_url, :title => 'hi') + ) + assert_equal( + {:controller => '/page', :action => 'show', :title => 'hi', :day => 10, :year => 2005, :month => 6}, + x.new.send(:article_url, :title => 'hi', :day => 10, :year => 2005, :month => 6) + ) + end + def test_changing_controller assert_equal ['/admin/stuff/show/10', {}], rs.generate( {:controller => 'stuff', :action => 'show', :id => 10}, @@ -766,6 +783,25 @@ class RouteSetTests < Test::Unit::TestCase assert_equal({'controller' => ::Controllers::Admin::NewsFeedController, 'action' => 'index'}, rs.recognize_path(%w(Admin NewsFeed))) assert_equal({'controller' => ::Controllers::Admin::NewsFeedController, 'action' => 'index'}, rs.recognize_path(%w(Admin News_Feed))) end + + def test_both_requirement_and_optional + rs.draw do + rs.blog('test/:year', :controller => 'post', :action => 'show', + :defaults => { :year => nil }, + :requirements => { :year => /\d{4}/ } + ) + rs.connect ':controller/:action/:id' + end + + assert_equal ['/test', {}], rs.generate(:controller => 'post', :action => 'show') + assert_equal ['/test', {}], rs.generate(:controller => 'post', :action => 'show', :year => nil) + + x = setup_for_named_route + assert_equal({:controller => '/post', :action => 'show'}, + x.new.send(:blog_url)) + end + + end end |