From 6a6b4392c16c665eb713705f2b38e959a658eeef Mon Sep 17 00:00:00 2001 From: Cheah Chu Yeow Date: Sun, 20 Apr 2008 12:57:36 +0800 Subject: Ensure that default_url_options, if defined, are used in named routes. Signed-off-by: Michael Koziarski [#22 state:resolved] --- actionpack/test/controller/base_test.rb | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb index 1a8bd6dfe9..8416754c1e 100644 --- a/actionpack/test/controller/base_test.rb +++ b/actionpack/test/controller/base_test.rb @@ -48,6 +48,15 @@ protected end +class DefaultUrlOptionsController < ActionController::Base + def default_url_options_action + end + + def default_url_options(options) + { :host => 'www.override.com', :action => 'new', :bacon => 'chunky' } + end +end + class ControllerClassTests < Test::Unit::TestCase def test_controller_path assert_equal 'empty', EmptyController.controller_path @@ -134,3 +143,28 @@ class PerformActionTest < Test::Unit::TestCase assert_response 404 end end + +class DefaultUrlOptionsTest < Test::Unit::TestCase + def setup + @controller = DefaultUrlOptionsController.new + + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + + @request.host = 'www.example.com' + end + + def test_default_url_options_are_used_if_set + ActionController::Routing::Routes.draw do |map| + map.default_url_options 'default_url_options', :controller => 'default_url_options' + map.connect ':controller/:action/:id' + end + + get :default_url_options_action # Make a dummy request so that the controller is initialized properly. + + assert_equal 'http://www.override.com/default_url_options/new?bacon=chunky', @controller.url_for(:controller => 'default_url_options') + assert_equal 'http://www.override.com/default_url_options?bacon=chunky', @controller.send(:default_url_options_url) + ensure + ActionController::Routing::Routes.load! + end +end \ No newline at end of file -- cgit v1.2.3