From db4f421b0bfae226005591b1da90e4b42edf178d Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Mon, 18 Feb 2008 00:42:06 +0000 Subject: Add :trailing_slash option to UrlWriter. Closes #9117 [juanjo.bazan] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8892 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/test/controller/url_rewriter_test.rb | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb index 41ea9ed98b..a9974db5d5 100644 --- a/actionpack/test/controller/url_rewriter_test.rb +++ b/actionpack/test/controller/url_rewriter_test.rb @@ -149,6 +149,40 @@ class UrlWriterTests < Test::Unit::TestCase ) end + def test_trailing_slash + add_host! + options = {:controller => 'foo', :trailing_slash => true, :action => 'bar', :id => '33'} + assert_equal('http://www.basecamphq.com/foo/bar/33/', W.new.url_for(options) ) + end + + def test_trailing_slash_with_protocol + add_host! + options = { :trailing_slash => true,:protocol => 'https', :controller => 'foo', :action => 'bar', :id => '33'} + assert_equal('https://www.basecamphq.com/foo/bar/33/', W.new.url_for(options) ) + assert_equal 'https://www.basecamphq.com/foo/bar/33/?query=string', W.new.url_for(options.merge({:query => 'string'})) + end + + def test_trailing_slash_with_only_path + options = {:controller => 'foo', :trailing_slash => true} + assert_equal '/foo/', W.new.url_for(options.merge({:only_path => true})) + options.update({:action => 'bar', :id => '33'}) + assert_equal '/foo/bar/33/', W.new.url_for(options.merge({:only_path => true})) + assert_equal '/foo/bar/33/?query=string', W.new.url_for(options.merge({:query => 'string',:only_path => true})) + end + + def test_trailing_slash_with_anchor + options = {:trailing_slash => true, :controller => 'foo', :action => 'bar', :id => '33', :only_path => true, :anchor=> 'chapter7'} + assert_equal '/foo/bar/33/#chapter7', W.new.url_for(options) + assert_equal '/foo/bar/33/?query=string#chapter7', W.new.url_for(options.merge({:query => 'string'})) + end + + def test_trailing_slash_with_params + url = W.new.url_for(:trailing_slash => true, :only_path => true, :controller => 'cont', :action => 'act', :p1 => 'cafe', :p2 => 'link') + params = extract_params(url) + assert_equal params[0], { :p1 => 'cafe' }.to_query + assert_equal params[1], { :p2 => 'link' }.to_query + end + def test_relative_url_root_is_respected orig_relative_url_root = ActionController::AbstractRequest.relative_url_root ActionController::AbstractRequest.relative_url_root = '/subdir' -- cgit v1.2.3