From a61360688cd0e1f43f523866384d0d0796a4ea73 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 20 Mar 2005 22:02:22 +0000 Subject: Changed .htaccess to allow dispatch.* to be called from a sub-directory as part of the push with Action Pack to make Rails work on non-vhost setups #826 [Nicholas Seckar/Tobias Luetke] Fixed routing and helpers to make Rails work on non-vhost setups #826 [Nicholas Seckar/Tobias Luetke] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@945 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/test/controller/request_test.rb | 34 +++++++++ actionpack/test/template/asset_tag_helper_test.rb | 87 ++++++++++++++++++++++- actionpack/test/template/url_helper_test.rb | 22 ------ 3 files changed, 118 insertions(+), 25 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb index 54ff84151a..09c1dd7ce3 100644 --- a/actionpack/test/controller/request_test.rb +++ b/actionpack/test/controller/request_test.rb @@ -32,6 +32,23 @@ class RequestTest < Test::Unit::TestCase assert_equal ":8080", @request.port_string end + def test_relative_url_root + @request.env['SCRIPT_NAME'] = nil + assert_equal "", @request.relative_url_root + + @request.env['SCRIPT_NAME'] = "/dispatch.cgi" + assert_equal "", @request.relative_url_root + + @request.env['SCRIPT_NAME'] = "/myapp.rb" + assert_equal "", @request.relative_url_root + + @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi" + assert_equal "/hieraki", @request.relative_url_root + + @request.env['SCRIPT_NAME'] = "/collaboration/hieraki/dispatch.cgi" + assert_equal "/collaboration/hieraki", @request.relative_url_root + end + def test_request_uri @request.set_REQUEST_URI "http://www.rubyonrails.org/path/of/some/uri?mapped=1" assert_equal "/path/of/some/uri?mapped=1", @request.request_uri @@ -52,7 +69,24 @@ class RequestTest < Test::Unit::TestCase @request.set_REQUEST_URI "/?m=b" assert_equal "/?m=b", @request.request_uri assert_equal "/", @request.path + + @request.set_REQUEST_URI "/" + @request.env['SCRIPT_NAME'] = "/dispatch.cgi" + assert_equal "/", @request.request_uri + assert_equal "/", @request.path + + @request.set_REQUEST_URI "/hieraki/" + @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi" + assert_equal "/hieraki/", @request.request_uri + assert_equal "/", @request.path + + @request.set_REQUEST_URI "/collaboration/hieraki/books/edit/2" + @request.env['SCRIPT_NAME'] = "/collaboration/hieraki/dispatch.cgi" + assert_equal "/collaboration/hieraki/books/edit/2", @request.request_uri + assert_equal "/books/edit/2", @request.path + end + def test_host_with_port @request.env['HTTP_HOST'] = "rubyonrails.org:8080" diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 896d843165..d51d0075b0 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -8,11 +8,19 @@ class AssetTagHelperTest < Test::Unit::TestCase def setup @controller = Class.new do + def url_for(options, *parameters_for_method_reference) "http://www.example.com" end - end - @controller = @controller.new + + end.new + + @request = Class.new do + def relative_url_root + "" + end + end.new + end AutoDiscoveryToTag = { @@ -31,6 +39,74 @@ class AssetTagHelperTest < Test::Unit::TestCase %(stylesheet_link_tag("random.styles", "/css/stylish")) => %(\n) } + ImageLinkToTag = { + %(image_tag("xml")) => %(Xml), + %(image_tag("rss", :alt => "rss syndication")) => %(rss syndication), + %(image_tag("gold", :size => "45x70")) => %(Gold), + } + + def test_auto_discovery + AutoDiscoveryToTag.each { |method, tag| assert_equal(tag, eval(method)) } + end + + def test_javascript_include + JavascriptIncludeToTag.each { |method, tag| assert_equal(tag, eval(method)) } + end + + def test_style_link + StyleLinkToTag.each { |method, tag| assert_equal(tag, eval(method)) } + end + + def test_image_tag + ImageLinkToTag.each { |method, tag| assert_equal(tag, eval(method)) } + end + +end + +class AssetTagHelperNonVhostTest < Test::Unit::TestCase + include ActionView::Helpers::TagHelper + include ActionView::Helpers::UrlHelper + include ActionView::Helpers::AssetTagHelper + + def setup + @controller = Class.new do + + def url_for(options, *parameters_for_method_reference) + "http://www.example.com/calloboration/hieraki" + end + + end.new + + @request = Class.new do + def relative_url_root + "/calloboration/hieraki" + end + end.new + + end + + AutoDiscoveryToTag = { + %(auto_discovery_link_tag(:rss, :action => "feed")) => %(), + %(auto_discovery_link_tag(:atom)) => %(), + %(auto_discovery_link_tag) => %(), + } + + JavascriptIncludeToTag = { + %(javascript_include_tag("xmlhr")) => %(), + %(javascript_include_tag("common.javascript", "/elsewhere/cools")) => %(\n), + } + + StyleLinkToTag = { + %(stylesheet_link_tag("style")) => %(), + %(stylesheet_link_tag("random.styles", "/css/stylish")) => %(\n) + } + + ImageLinkToTag = { + %(image_tag("xml")) => %(Xml), + %(image_tag("rss", :alt => "rss syndication")) => %(rss syndication), + %(image_tag("gold", :size => "45x70")) => %(Gold), + } + def test_auto_discovery AutoDiscoveryToTag.each { |method, tag| assert_equal(tag, eval(method)) } end @@ -44,6 +120,11 @@ class AssetTagHelperTest < Test::Unit::TestCase end def test_image_tag - assert_equal %(Gold), image_tag("gold", :size => "45x70") + assert_equal %(Gold), image_tag("gold", :size => "45x70") + end + + def test_image_tag + ImageLinkToTag.each { |method, tag| assert_equal(tag, eval(method)) } end + end \ No newline at end of file diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 8e0016f0fd..32b98eb5dc 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -36,28 +36,6 @@ class UrlHelperTest < Test::Unit::TestCase ) end - def test_link_image_to - assert_equal( - "\"Rss\"", - link_image_to("rss", "http://www.example.com", "size" => "30x45", "border" => "0") - ) - - assert_equal( - "\"Rss\"", - link_to(image_tag("rss", :size => "30x45", :border => 0), "http://www.example.com") - ) - - assert_equal( - "\"Feed\"", - link_image_to("rss.gif", "http://www.example.com", "size" => "30x45", "alt" => "Feed", "class" => "admin") - ) - - assert_equal link_image_to("rss", "http://www.example.com", "size" => "30x45"), - link_image_to("rss", "http://www.example.com", :size => "30x45") - assert_equal link_image_to("rss.gif", "http://www.example.com", "size" => "30x45", "alt" => "Feed", "class" => "admin"), - link_image_to("rss.gif", "http://www.example.com", :size => "30x45", :alt => "Feed", :class => "admin") - end - def test_link_to_unless assert_equal "Showing", link_to_unless(true, "Showing", :action => "show", :controller => "weblog") assert "Listing", link_to_unless(false, "Listing", :action => "list", :controller => "weblog") -- cgit v1.2.3