Permalink
Browse files

Ensure shallow routes respects namespace [#1356 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
tomstuart authored and lifo committed Mar 7, 2009
1 parent 7438788 commit 5c87e9adddc22703a3dbbb785e32fafe0e91ce78
Showing with 33 additions and 5 deletions.
  1. +2 −2 actionpack/lib/action_controller/resources.rb
  2. +31 −3 actionpack/test/controller/resources_test.rb
@@ -91,7 +91,7 @@ def new_path
end
def shallow_path_prefix
@shallow_path_prefix ||= "#{path_prefix unless @options[:shallow]}"
@shallow_path_prefix ||= @options[:shallow] ? @options[:namespace].try(:sub, /\/$/, '') : path_prefix
end
def member_path
@@ -103,7 +103,7 @@ def nesting_path_prefix
end
def shallow_name_prefix
@shallow_name_prefix ||= "#{name_prefix unless @options[:shallow]}"
@shallow_name_prefix ||= @options[:shallow] ? @options[:namespace].try(:gsub, /\//, '_') : name_prefix
end
def nesting_name_prefix
@@ -414,6 +414,34 @@ def test_shallow_nested_restful_routes
end
end
def test_shallow_nested_restful_routes_with_namespaces
with_routing do |set|
set.draw do |map|
map.namespace :backoffice do |map|
map.namespace :admin do |map|
map.resources :products, :shallow => true do |map|
map.resources :images
end
end
end
end
assert_simply_restful_for :products,
:controller => 'backoffice/admin/products',
:namespace => 'backoffice/admin/',
:name_prefix => 'backoffice_admin_',
:path_prefix => 'backoffice/admin/',
:shallow => true
assert_simply_restful_for :images,
:controller => 'backoffice/admin/images',
:namespace => 'backoffice/admin/',
:name_prefix => 'backoffice_admin_product_',
:path_prefix => 'backoffice/admin/products/1/',
:shallow => true,
:options => { :product_id => '1' }
end
end
def test_restful_routes_dont_generate_duplicates
with_restful_routing :messages do
routes = ActionController::Routing::Routes.routes
@@ -1082,7 +1110,7 @@ def assert_restful_routes_for(controller_name, options = {})
path = "#{options[:as] || controller_name}"
collection_path = "/#{options[:path_prefix]}#{path}"
shallow_path = "/#{options[:path_prefix] unless options[:shallow]}#{path}"
shallow_path = "/#{options[:shallow] ? options[:namespace] : options[:path_prefix]}#{path}"
member_path = "#{shallow_path}/1"
new_path = "#{collection_path}/#{new_action}"
edit_member_path = "#{member_path}/#{edit_action}"
@@ -1146,10 +1174,10 @@ def assert_restful_named_routes_for(controller_name, singular_name = nil, option
options[:options].delete :action
path = "#{options[:as] || controller_name}"
shallow_path = "/#{options[:path_prefix] unless options[:shallow]}#{path}"
shallow_path = "/#{options[:shallow] ? options[:namespace] : options[:path_prefix]}#{path}"
full_path = "/#{options[:path_prefix]}#{path}"
name_prefix = options[:name_prefix]
shallow_prefix = "#{options[:name_prefix] unless options[:shallow]}"
shallow_prefix = options[:shallow] ? options[:namespace].try(:gsub, /\//, '_') : options[:name_prefix]
new_action = "new"
edit_action = "edit"

1 comment on commit 5c87e9a

@tejo

This comment has been minimized.

Show comment
Hide comment
@tejo

tejo Oct 21, 2009

Actually in 2.3.4 this does not work

tejo commented on 5c87e9a Oct 21, 2009

Actually in 2.3.4 this does not work

Please sign in to comment.