diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-01-10 02:51:09 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-01-10 02:51:09 +0000 |
commit | 59f222dbf7c05e3d1f9e71831bc79e2a5ed4a5b5 (patch) | |
tree | fa1b92ddfca5c0f5ab4a50fd42d2eb5eb3b00d71 /actionpack/test | |
parent | 3642a4d6f88d774b56cf82d111179c1743065015 (diff) | |
download | rails-59f222dbf7c05e3d1f9e71831bc79e2a5ed4a5b5.tar.gz rails-59f222dbf7c05e3d1f9e71831bc79e2a5ed4a5b5.tar.bz2 rails-59f222dbf7c05e3d1f9e71831bc79e2a5ed4a5b5.zip |
UrlWriter respects relative_url_root. Closes #10748.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8616 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/controller/url_rewriter_test.rb | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb index ffc45b513e..41ea9ed98b 100644 --- a/actionpack/test/controller/url_rewriter_test.rb +++ b/actionpack/test/controller/url_rewriter_test.rb @@ -149,27 +149,57 @@ class UrlWriterTests < Test::Unit::TestCase ) end - def test_named_route + def test_relative_url_root_is_respected + orig_relative_url_root = ActionController::AbstractRequest.relative_url_root + ActionController::AbstractRequest.relative_url_root = '/subdir' + + add_host! + assert_equal('https://www.basecamphq.com/subdir/c/a/i', + W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https') + ) + ensure + ActionController::AbstractRequest.relative_url_root = orig_relative_url_root + end + + def test_named_routes ActionController::Routing::Routes.draw do |map| map.no_args '/this/is/verbose', :controller => 'home', :action => 'index' map.home '/home/sweet/home/:user', :controller => 'home', :action => 'index' map.connect ':controller/:action/:id' end - + # We need to create a new class in order to install the new named route. kls = Class.new { include ActionController::UrlWriter } controller = kls.new assert controller.respond_to?(:home_url) assert_equal 'http://www.basecamphq.com/home/sweet/home/again', controller.send(:home_url, :host => 'www.basecamphq.com', :user => 'again') - + assert_equal("/home/sweet/home/alabama", controller.send(:home_path, :user => 'alabama', :host => 'unused')) assert_equal("http://www.basecamphq.com/home/sweet/home/alabama", controller.send(:home_url, :user => 'alabama', :host => 'www.basecamphq.com')) assert_equal("http://www.basecamphq.com/this/is/verbose", controller.send(:no_args_url, :host=>'www.basecamphq.com')) ensure ActionController::Routing::Routes.load! end - + + def test_relative_url_root_is_respected_for_named_routes + orig_relative_url_root = ActionController::AbstractRequest.relative_url_root + ActionController::AbstractRequest.relative_url_root = '/subdir' + + ActionController::Routing::Routes.draw do |map| + map.home '/home/sweet/home/:user', :controller => 'home', :action => 'index' + end + + kls = Class.new { include ActionController::UrlWriter } + controller = kls.new + + assert_equal 'http://www.basecamphq.com/subdir/home/sweet/home/again', + controller.send(:home_url, :host => 'www.basecamphq.com', :user => 'again') + ensure + ActionController::Routing::Routes.load! + ActionController::AbstractRequest.relative_url_root = orig_relative_url_root + end + def test_only_path ActionController::Routing::Routes.draw do |map| map.home '/home/sweet/home/:user', :controller => 'home', :action => 'index' |