From b611c685d92038b199149e8eec900c3058523ab7 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 10 Sep 2007 14:31:44 +0000 Subject: Fixed that resource namespaces wouldnt stick to all nested resources (closes #9399) [pixeltrix] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7447 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 ++ actionpack/lib/action_controller/resources.rb | 9 ++++---- actionpack/test/controller/resources_test.rb | 32 +++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 5 deletions(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 99482b8090..551cc753d9 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixed that resource namespaces wouldn't stick to all nested resources #9399 [pixeltrix] + * Moved ActionController::Macros::InPlaceEditing into the in_place_editor plugin on the official Rails svn #9513 [lifofifo] * Removed deprecated form of calling xml_http_request/xhr without the first argument being the http verb [DHH] diff --git a/actionpack/lib/action_controller/resources.rb b/actionpack/lib/action_controller/resources.rb index e909a65eab..7b311e5eb7 100644 --- a/actionpack/lib/action_controller/resources.rb +++ b/actionpack/lib/action_controller/resources.rb @@ -394,7 +394,7 @@ module ActionController map_associations(resource, options) if block_given? - with_options(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix, &block) + with_options(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix, :namespace => options[:namespace], &block) end end end @@ -411,7 +411,7 @@ module ActionController map_associations(resource, options) if block_given? - with_options(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix, &block) + with_options(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix, :namespace => options[:namespace], &block) end end end @@ -419,14 +419,13 @@ module ActionController def map_associations(resource, options) path_prefix = "#{options.delete(:path_prefix)}#{resource.nesting_path_prefix}" name_prefix = "#{options.delete(:name_prefix)}#{resource.nesting_name_prefix}" - namespace = options.delete(:namespace) Array(options[:has_many]).each do |association| - resources(association, :path_prefix => path_prefix, :name_prefix => name_prefix, :namespace => namespace) + resources(association, :path_prefix => path_prefix, :name_prefix => name_prefix, :namespace => options[:namespace]) end Array(options[:has_one]).each do |association| - resource(association, :path_prefix => path_prefix, :name_prefix => name_prefix, :namespace => namespace) + resource(association, :path_prefix => path_prefix, :name_prefix => name_prefix, :namespace => options[:namespace]) end end diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index 29c25e6cfc..d28089da0c 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -19,9 +19,11 @@ module Backoffice class ProductsController < ResourcesController; end class TagsController < ResourcesController; end class ManufacturersController < ResourcesController; end + class ImagesController < ResourcesController; end module Admin class ProductsController < ResourcesController; end + class ImagesController < ResourcesController; end end end @@ -576,6 +578,36 @@ class ResourcesTest < Test::Unit::TestCase assert_simply_restful_for :products, :controller => "backoffice/products" end end + + def test_nested_resources_using_namespace + with_routing do |set| + set.draw do |map| + map.namespace :backoffice do |backoffice| + backoffice.resources :products do |products| + products.resources :images + end + end + end + + assert_simply_restful_for :images, :controller => "backoffice/images", :name_prefix => 'backoffice_product_', :path_prefix => 'backoffice/products/1/', :options => {:product_id => '1'} + end + end + + def test_nested_resources_in_nested_namespace + with_routing do |set| + set.draw do |map| + map.namespace :backoffice do |backoffice| + backoffice.namespace :admin do |admin| + admin.resources :products do |products| + products.resources :images + end + end + end + end + + assert_simply_restful_for :images, :controller => "backoffice/admin/images", :name_prefix => 'backoffice_admin_product_', :path_prefix => 'backoffice/admin/products/1/', :options => {:product_id => '1'} + end + end protected def with_restful_routing(*args) -- cgit v1.2.3