From 7349b9deee129554f86fc8b4a3ef06b389f83d00 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Thu, 24 Jun 2010 10:51:04 +0100 Subject: [PATCH] Fix namespaced redirects --- actionpack/lib/action_dispatch/routing/mapper.rb | 3 ++- actionpack/test/dispatch/routing_test.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index e001d10..6a7ff23 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -55,7 +55,7 @@ module ActionDispatch path = args.first end - if @scope[:module] && options[:to] + if @scope[:module] && options[:to] && !options[:to].is_a?(Proc) if options[:to].to_s.include?("#") options[:to] = "#{@scope[:module]}/#{options[:to]}" elsif @scope[:controller].nil? @@ -255,6 +255,7 @@ module ActionDispatch options = args.last.is_a?(Hash) ? args.pop : {} path = args.shift || block + path = Mapper.normalize_path("#{@scope[:path]}/#{path}") if @scope[:path] path_proc = path.is_a?(Proc) ? path : proc { |params| path % params } status = options[:status] || 301 body = 'Moved Permanently' diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 58a1fa0..7501266 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -300,6 +300,11 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest match '/' => 'mes#index' end + namespace :private do + root :to => redirect('/index') + match "index", :to => 'private#index' + end + match "whatever/:controller(/:action(/:id))" resource :profile do @@ -421,6 +426,15 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_namespace_redirect + with_test_routes do + get '/private' + assert_equal 301, @response.status + assert_equal 'http://www.example.com/private/index', @response.headers['Location'] + assert_equal 'Moved Permanently', @response.body + end + end + def test_session_singleton_resource with_test_routes do get '/session' -- 1.7.1