Permalink
Browse files

Actually make the name_prefix work like the previous checkin said it …

…would

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6590 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 63aea3f commit 0adf4a97c1f29a7230e00d39c04c8b4a6053fa65 @dhh dhh committed Apr 27, 2007
Showing with 25 additions and 17 deletions.
  1. +9 −4 actionpack/lib/action_controller/resources.rb
  2. +16 −13 actionpack/test/controller/resources_test.rb
@@ -44,6 +44,11 @@ def nesting_path_prefix
@nesting_path_prefix ||= "#{path}/:#{singular}_id"
end
+ def nesting_name_prefix
+ "#{singular}_"
+ end
+
+
protected
def arrange_actions
@collection_methods = arrange_actions_by_methods(options.delete(:collection))
@@ -309,7 +314,7 @@ def map_resource(entities, options = {}, &block)
map_associations(resource, options)
if block_given?
- with_options(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.name_prefix, &block)
+ with_options(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix, &block)
end
end
end
@@ -326,18 +331,18 @@ def map_singleton_resource(entities, options = {}, &block)
map_associations(resource, options)
if block_given?
- with_options(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.name_prefix, &block)
+ with_options(:path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix, &block)
end
end
end
def map_associations(resource, options)
Array(options[:has_many]).each do |association|
- resources(association, :path_prefix => resource.nesting_path_prefix, :name_prefix => resource.name_prefix)
+ resources(association, :path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix)
end
Array(options[:has_one]).each do |association|
- resource(association, :path_prefix => resource.nesting_path_prefix, :name_prefix => resource.name_prefix)
+ resource(association, :path_prefix => resource.nesting_path_prefix, :name_prefix => resource.nesting_name_prefix)
end
end
@@ -204,9 +204,11 @@ def test_nested_restful_routes
assert_simply_restful_for :threads
assert_simply_restful_for :messages,
+ :name_prefix => 'thread_',
:path_prefix => 'threads/1/',
:options => { :thread_id => '1' }
assert_simply_restful_for :comments,
+ :name_prefix => 'message_',
:path_prefix => 'threads/1/messages/2/',
:options => { :thread_id => '1', :message_id => '2' }
end
@@ -246,7 +248,7 @@ def test_should_create_nested_singleton_resource_routes
end
assert_singleton_restful_for :admin
- assert_singleton_restful_for :account, :path_prefix => 'admin/'
+ assert_singleton_restful_for :account, :name_prefix => "admin_", :path_prefix => 'admin/'
end
end
@@ -257,8 +259,8 @@ def test_resource_has_many_should_become_nested_resources
end
assert_simply_restful_for :messages
- assert_simply_restful_for :comments, :path_prefix => 'messages/1/', :options => { :message_id => '1' }
- assert_simply_restful_for :authors, :path_prefix => 'messages/1/', :options => { :message_id => '1' }
+ assert_simply_restful_for :comments, :name_prefix => "message_", :path_prefix => 'messages/1/', :options => { :message_id => '1' }
+ assert_simply_restful_for :authors, :name_prefix => "message_", :path_prefix => 'messages/1/', :options => { :message_id => '1' }
end
end
@@ -269,7 +271,7 @@ def test_resource_has_one_should_become_nested_resources
end
assert_simply_restful_for :messages
- assert_singleton_restful_for :logo, :path_prefix => 'messages/1/', :options => { :message_id => '1' }
+ assert_singleton_restful_for :logo, :name_prefix => 'message_', :path_prefix => 'messages/1/', :options => { :message_id => '1' }
end
end
@@ -316,7 +318,7 @@ def test_should_nest_resources_in_singleton_resource
end
assert_singleton_restful_for :account
- assert_simply_restful_for :messages, :path_prefix => 'account/'
+ assert_simply_restful_for :messages, :name_prefix => "account_", :path_prefix => 'account/'
end
end
@@ -329,7 +331,7 @@ def test_should_nest_resources_in_singleton_resource_with_path_prefix
end
assert_singleton_restful_for :account, :path_prefix => '7/', :options => { :site_id => '7' }
- assert_simply_restful_for :messages, :path_prefix => '7/account/', :options => { :site_id => '7' }
+ assert_simply_restful_for :messages, :name_prefix => "account_", :path_prefix => '7/account/', :options => { :site_id => '7' }
end
end
@@ -342,7 +344,7 @@ def test_should_nest_singleton_resource_in_resources
end
assert_simply_restful_for :threads
- assert_singleton_restful_for :admin, :path_prefix => 'threads/5/', :options => { :thread_id => '5' }
+ assert_singleton_restful_for :admin, :name_prefix => 'thread_', :path_prefix => 'threads/5/', :options => { :thread_id => '5' }
end
end
@@ -498,13 +500,14 @@ def assert_singleton_named_routes_for(singleton_name, options = {})
options[:options].delete :action
full_path = "/#{options[:path_prefix]}#{singleton_name}"
+ name_prefix = options[:name_prefix]
- assert_named_route "#{full_path}", "#{singleton_name}_path", options[:options]
- assert_named_route "#{full_path}/new", "new_#{singleton_name}_path", options[:options]
- assert_named_route "#{full_path}/edit", "edit_#{singleton_name}_path", options[:options]
- assert_named_route "#{full_path}.xml", "formatted_#{singleton_name}_path", options[:options].merge(:format => 'xml')
- assert_named_route "#{full_path}/new.xml", "formatted_new_#{singleton_name}_path", options[:options].merge(:format => 'xml')
- assert_named_route "#{full_path}/edit.xml", "formatted_edit_#{singleton_name}_path", options[:options].merge(:format => 'xml')
+ assert_named_route "#{full_path}", "#{name_prefix}#{singleton_name}_path", options[:options]
+ assert_named_route "#{full_path}/new", "#{name_prefix}new_#{singleton_name}_path", options[:options]
+ assert_named_route "#{full_path}/edit", "#{name_prefix}edit_#{singleton_name}_path", options[:options]
+ assert_named_route "#{full_path}.xml", "formatted_#{name_prefix}#{singleton_name}_path", options[:options].merge(:format => 'xml')
+ assert_named_route "#{full_path}/new.xml", "formatted_#{name_prefix}new_#{singleton_name}_path", options[:options].merge(:format => 'xml')
+ assert_named_route "#{full_path}/edit.xml", "formatted_#{name_prefix}edit_#{singleton_name}_path", options[:options].merge(:format => 'xml')
end
def assert_named_route(expected, route, options)

0 comments on commit 0adf4a9

Please sign in to comment.