Skip to content
Browse files

Resource namespaces are inherited by their has_many subresources. Clo…

…ses #8280.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6806 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 4afd6c9 commit 5a3b4cf0bca5453547e89dc82966909b6bde3564 @jeremy jeremy committed
View
2 actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Resource namespaces are inherited by their has_many subresources. #8280 [marclove, ggarside]
+
* Fix filtered parameter logging with nil parameter values. #8422 [choonkeat]
* Integration tests: alias xhr to xml_http_request and add a request_method argument instead of always using POST. #7124 [Nik Wakelin, Francois Beausoleil, Wizard]
View
8 actionpack/lib/action_controller/resources.rb
@@ -375,12 +375,16 @@ def map_singleton_resource(entities, options = {}, &block)
end
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 => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix)
+ resources(association, :path_prefix => path_prefix, :name_prefix => name_prefix, :namespace => namespace)
end
Array(options[:has_one]).each do |association|
- resource(association, :path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix)
+ resource(association, :path_prefix => path_prefix, :name_prefix => name_prefix, :namespace => namespace)
end
end
View
35 actionpack/test/controller/resources_test.rb
@@ -17,9 +17,11 @@ class AdminController < ResourcesController; end
module Backoffice
class ProductsController < ResourcesController; end
-
+ class TagsController < ResourcesController; end
+ class ManufacturerController < ResourcesController; end
+
module Admin
- class ProductsController < ResourcesController; end
+ class ProductsController < ResourcesController; end
end
end
@@ -403,6 +405,32 @@ def test_resources_in_namespace
assert_simply_restful_for :products, :controller => "backoffice/products", :name_prefix => 'backoffice_', :path_prefix => 'backoffice/'
end
end
+
+ def test_resource_has_many_in_namespace
+ with_routing do |set|
+ set.draw do |map|
+ map.namespace :backoffice do |backoffice|
+ backoffice.resources :products, :has_many => :tags
+ end
+ end
+
+ assert_simply_restful_for :products, :controller => "backoffice/products", :name_prefix => 'backoffice_', :path_prefix => 'backoffice/'
+ assert_simply_restful_for :tags, :controller => "backoffice/tags", :name_prefix => "backoffice_product_", :path_prefix => 'backoffice/products/1/', :options => { :product_id => '1' }
+ end
+ end
+
+ def test_resource_has_one_in_namespace
+ with_routing do |set|
+ set.draw do |map|
+ map.namespace :backoffice do |backoffice|
+ backoffice.resources :products, :has_one => :manufacturer
+ end
+ end
+
+ assert_simply_restful_for :products, :controller => "backoffice/products", :name_prefix => 'backoffice_', :path_prefix => 'backoffice/'
+ assert_singleton_restful_for :manufacturer, :controller => "backoffice/manufacturer", :name_prefix => 'backoffice_product_', :path_prefix => 'backoffice/products/1/', :options => { :product_id => '1' }
+ end
+ end
def test_resources_in_nested_namespace
with_routing do |set|
@@ -526,7 +554,8 @@ def assert_restful_named_routes_for(controller_name, singular_name = nil, option
end
def assert_singleton_routes_for(singleton_name, options = {})
- (options[:options] ||= {})[:controller] ||= singleton_name.to_s
+ options[:options] ||= {}
+ options[:options][:controller] = options[:controller] || singleton_name.to_s
full_path = "/#{options[:path_prefix]}#{singleton_name}"
new_path = "#{full_path}/new"

0 comments on commit 5a3b4cf

Please sign in to comment.
Something went wrong with that request. Please try again.