From 1d7196b55272d5f900a3080387319686e395b981 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Fri, 20 Oct 2006 18:00:20 +0000 Subject: Force *_url named routes to show the host in ActionView [Rick] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5325 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/test/template/url_helper_test.rb | 57 ++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) (limited to 'actionpack/test') diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index ba813f72ce..a3fd8c0d1b 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -28,7 +28,7 @@ class UrlHelperTest < Test::Unit::TestCase assert_equal "http://www.example.com?a=b&c=d", url_for(:a => 'b', :c => 'd', :escape => true) assert_equal "http://www.example.com?a=b&c=d", url_for(:a => 'b', :c => 'd', :escape => false) end - + # todo: missing test cases def test_button_to_with_straight_url assert_dom_equal "
", button_to("Hello", "http://www.example.com") @@ -237,3 +237,58 @@ class UrlHelperTest < Test::Unit::TestCase assert_dom_equal "", mail_to("me@domain.com", "My email", :encode => "javascript", :replace_at => "(at)", :replace_dot => "(dot)") end end + +class UrlHelperWithControllerTest < Test::Unit::TestCase + class UrlHelperController < ActionController::Base + self.template_root = "#{File.dirname(__FILE__)}/../fixtures/" + + def self.controller_path; 'url_helper_with_controller' end + + def show_url_for + render :inline => "<%= url_for :controller => 'url_helper_with_controller', :action => 'show_url_for' %>" + end + + def show_named_route + render :inline => "<%= show_named_route_#{params[:kind]} %>" + end + + def rescue_action(e) raise e end + end + + include ActionView::Helpers::UrlHelper + + def setup + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @controller = UrlHelperController.new + end + + def test_url_for_shows_only_path + get :show_url_for + assert_equal '/url_helper_with_controller/show_url_for', @response.body + end + + def test_named_route_shows_host_and_path + with_url_helper_routing do + get :show_named_route, :kind => 'url' + assert_equal 'http://test.host/url_helper_with_controller/show_named_route', @response.body + end + end + + def test_named_route_path_shows_only_path + with_url_helper_routing do + get :show_named_route, :kind => 'path' + assert_equal '/url_helper_with_controller/show_named_route', @response.body + end + end + + protected + def with_url_helper_routing + with_routing do |set| + set.draw do |map| + map.show_named_route 'url_helper_with_controller/show_named_route', :controller => 'url_helper_with_controller', :action => 'show_named_route' + end + yield + end + end +end -- cgit v1.2.3