From 068fc6ce4962ef4c9432455f88a83400316cd321 Mon Sep 17 00:00:00 2001 From: Tom Lea Date: Tue, 28 Oct 2008 15:52:36 +0000 Subject: [PATCH] Added failing test case --- actionpack/test/template/url_helper_test.rb | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 797b74e..c3286ad 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -375,6 +375,19 @@ class UrlHelperWithControllerTest < ActionView::TestCase get :nil_url_for assert_equal '/url_helper_with_controller/nil_url_for', @response.body end + + def test_named_route_should_show_host_and_path_using_controller_default_url_options + class << @controller + def default_url_options(options = nil) + {:host => 'testtwo.host'} + end + end + + with_url_helper_routing do + get :show_named_route, :kind => 'url' + assert_equal 'http://testtwo.host/url_helper_with_controller/show_named_route', @response.body + end + end protected def with_url_helper_routing -- 1.6.0.1 From e6e1f76fb8028d1d431dca4648bad0de7a74f4e1 Mon Sep 17 00:00:00 2001 From: Tom Lea Date: Tue, 28 Oct 2008 16:02:46 +0000 Subject: [PATCH] Added a second test case that passes. This one uses the controller explicitly. --- actionpack/test/template/url_helper_test.rb | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-) diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index c3286ad..745ac38 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -340,6 +340,10 @@ class UrlHelperWithControllerTest < ActionView::TestCase def nil_url_for render :inline => '<%= url_for(nil) %>' end + + def show_named_route_from_controller + render :text => self.send("show_named_route_#{params[:kind]}") + end def rescue_action(e) raise e end end @@ -389,11 +393,26 @@ class UrlHelperWithControllerTest < ActionView::TestCase end end + def test_named_route_should_show_host_and_path_using_controller_default_url_options_from_controller + class << @controller + def default_url_options(options = nil) + {:host => 'testtwo.host'} + end + end + + with_url_helper_routing do + get :show_named_route_from_controller, :kind => 'url' + assert_equal 'http://testtwo.host/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' + map.show_named_route_from_controller 'url_helper_with_controller/show_named_route_from_controller', :controller => 'url_helper_with_controller', :action => 'show_named_route_from_controller' end yield end -- 1.6.0.1 From d84142375a788fbfe218d6774fc0e592942e4087 Mon Sep 17 00:00:00 2001 From: Tom Lea Date: Fri, 31 Oct 2008 10:20:51 +0000 Subject: [PATCH] ActionView needs to know about default_url_options. This is needed to allow the optomised named route methods to be evaluated directly in the scope of the action view. --- actionpack/lib/action_view/helpers/url_helper.rb | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 2e0eb87..ed23710 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -94,6 +94,8 @@ module ActionView escape ? escape_once(url) : url end + delegate :default_url_options, :to => :controller + # Creates a link tag of the given +name+ using a URL created by the set # of +options+. See the valid options in the documentation for # url_for. It's also possible to pass a string instead -- 1.6.0.1