Skip to content

Commit

Permalink
Use draw/connect mapper api instead of directly using add_named_route
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Sep 7, 2009
1 parent 314e18a commit 1a0f822
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions actionpack/test/controller/routing_test.rb
Expand Up @@ -232,14 +232,18 @@ def test_route_with_regexp_and_dot
end

def test_basic_named_route
rs.add_named_route :home, '', :controller => 'content', :action => 'list'
rs.draw do |map|
map.home '', :controller => 'content', :action => 'list'
end
x = setup_for_named_route
assert_equal("http://test.host/",
x.send(:home_url))
end

def test_basic_named_route_with_relative_url_root
rs.add_named_route :home, '', :controller => 'content', :action => 'list'
rs.draw do |map|
map.home '', :controller => 'content', :action => 'list'
end
x = setup_for_named_route
ActionController::Base.relative_url_root = "/foo"
assert_equal("http://test.host/foo/",
Expand All @@ -249,51 +253,65 @@ def test_basic_named_route_with_relative_url_root
end

def test_named_route_with_option
rs.add_named_route :page, 'page/:title', :controller => 'content', :action => 'show_page'
rs.draw do |map|
map.page 'page/:title', :controller => 'content', :action => 'show_page'
end
x = setup_for_named_route
assert_equal("http://test.host/page/new%20stuff",
x.send(:page_url, :title => 'new stuff'))
end

def test_named_route_with_default
rs.add_named_route :page, 'page/:title', :controller => 'content', :action => 'show_page', :title => 'AboutPage'
rs.draw do |map|
map.page 'page/:title', :controller => 'content', :action => 'show_page', :title => 'AboutPage'
end
x = setup_for_named_route
assert_equal("http://test.host/page/AboutRails",
x.send(:page_url, :title => "AboutRails"))

end

def test_named_route_with_name_prefix
rs.add_named_route :page, 'page', :controller => 'content', :action => 'show_page', :name_prefix => 'my_'
rs.draw do |map|
map.page 'page', :controller => 'content', :action => 'show_page', :name_prefix => 'my_'
end
x = setup_for_named_route
assert_equal("http://test.host/page",
x.send(:my_page_url))
end

def test_named_route_with_path_prefix
rs.add_named_route :page, 'page', :controller => 'content', :action => 'show_page', :path_prefix => 'my'
rs.draw do |map|
map.page 'page', :controller => 'content', :action => 'show_page', :path_prefix => 'my'
end
x = setup_for_named_route
assert_equal("http://test.host/my/page",
x.send(:page_url))
end

def test_named_route_with_blank_path_prefix
rs.add_named_route :page, 'page', :controller => 'content', :action => 'show_page', :path_prefix => ''
rs.draw do |map|
map.page 'page', :controller => 'content', :action => 'show_page', :path_prefix => ''
end
x = setup_for_named_route
assert_equal("http://test.host/page",
x.send(:page_url))
end

def test_named_route_with_nested_controller
rs.add_named_route :users, 'admin/user', :controller => 'admin/user', :action => 'index'
rs.draw do |map|
map.users 'admin/user', :controller => 'admin/user', :action => 'index'
end
x = setup_for_named_route
assert_equal("http://test.host/admin/user",
x.send(:users_url))
end

def test_optimised_named_route_call_never_uses_url_for
rs.add_named_route :users, 'admin/user', :controller => '/admin/user', :action => 'index'
rs.add_named_route :user, 'admin/user/:id', :controller=>'/admin/user', :action=>'show'
rs.draw do |map|
map.users 'admin/user', :controller => '/admin/user', :action => 'index'
map.user 'admin/user/:id', :controller=>'/admin/user', :action=>'show'
end
x = setup_for_named_route
x.expects(:url_for).never
x.send(:users_url)
Expand All @@ -303,7 +321,9 @@ def test_optimised_named_route_call_never_uses_url_for
end

def test_optimised_named_route_with_host
rs.add_named_route :pages, 'pages', :controller => 'content', :action => 'show_page', :host => 'foo.com'
rs.draw do |map|
map.pages 'pages', :controller => 'content', :action => 'show_page', :host => 'foo.com'
end
x = setup_for_named_route
x.expects(:url_for).with(:host => 'foo.com', :only_path => false, :controller => 'content', :action => 'show_page', :use_route => :pages).once
x.send(:pages_url)
Expand Down Expand Up @@ -378,7 +398,9 @@ def test_paths_escaped
end

def test_paths_slashes_unescaped_with_ordered_parameters
rs.add_named_route :path, '/file/*path', :controller => 'content'
rs.draw do |map|
map.path '/file/*path', :controller => 'content'
end

# No / to %2F in URI, only for query params.
x = setup_for_named_route
Expand Down

0 comments on commit 1a0f822

Please sign in to comment.