From 4560385fa4fa6925aa220bbaf6b2608c2bbd7039 Mon Sep 17 00:00:00 2001 From: Jan De Poorter Date: Wed, 14 Apr 2010 10:34:42 +0200 Subject: [PATCH] Make sure namespaces are nested within resources MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/lib/action_dispatch/routing/mapper.rb | 8 ++++++++ actionpack/test/dispatch/routing_test.rb | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 6db8d1aacc..0f267caefe 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -679,6 +679,14 @@ module ActionDispatch end end + def namespace(path) + if @scope[:scope_level] == :resources + nested { super } + else + super + end + end + def match(*args) options = args.extract_options! diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 5c46f9b971..c4e402afd3 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -144,6 +144,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest resources :sheep + resources :clients do + namespace :google do + resource :account + end + end + match 'sprockets.js' => ::TestRoutingMapper::SprocketsApp match 'people/:id/update', :to => 'people#update', :as => :update_person @@ -813,6 +819,15 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_equal '/account/admin/subscription', account_admin_subscription_path end end + + def test_namespace_nested_in_resources + with_test_routes do + get '/clients/1/google/account' + assert_equal '/clients/1/google/account', client_google_account_path(1) + + assert_equal 'google/accounts#show', @response.body + end + end def test_articles_with_id with_test_routes do