Skip to content

Commit

Permalink
Added both the documentation and a test case for the collection path …
Browse files Browse the repository at this point in the history
…name customization feature.

[#1218 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information
Hugo Peixoto authored and jeremy committed Aug 9, 2009
1 parent e1b73b9 commit 202b091
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
5 changes: 3 additions & 2 deletions actionpack/lib/action_controller/routing/resources.rb
Expand Up @@ -320,9 +320,10 @@ def initialize(entity, options)
# notes.resources :attachments # notes.resources :attachments
# end # end
# #
# * <tt>:path_names</tt> - Specify different names for the 'new' and 'edit' actions. For example: # * <tt>:path_names</tt> - Specify different path names for the actions. For example:
# # new_products_path == '/productos/nuevo' # # new_products_path == '/productos/nuevo'
# map.resources :products, :as => 'productos', :path_names => { :new => 'nuevo', :edit => 'editar' } # # bids_product_path(1) == '/productos/1/licitacoes'
# map.resources :products, :as => 'productos', :member => { :bids => :get }, :path_names => { :new => 'nuevo', :bids => 'licitacoes' }
# #
# You can also set default action names from an environment, like this: # You can also set default action names from an environment, like this:
# config.action_controller.resources_path_names = { :new => 'nuevo', :edit => 'editar' } # config.action_controller.resources_path_names = { :new => 'nuevo', :edit => 'editar' }
Expand Down
44 changes: 44 additions & 0 deletions actionpack/test/controller/resources_test.rb
Expand Up @@ -76,6 +76,50 @@ def test_default_restful_routes
end end
end end


def test_override_paths_for_member_and_collection_methods
collection_methods = { 'rss' => :get, 'reorder' => :post, 'csv' => :post }
member_methods = { 'rss' => :get, :atom => :get, :upload => :post, :fix => :post }
path_names = {:new => 'nuevo', 'rss' => 'canal', :fix => 'corrigir' }

with_restful_routing :messages,
:collection => collection_methods,
:member => member_methods,
:path_names => path_names do

assert_restful_routes_for :messages,
:collection => collection_methods,
:member => member_methods,
:path_names => path_names do |options|
member_methods.each do |action, method|
assert_recognizes(options.merge(:action => action.to_s, :id => '1'),
:path => "/messages/1/#{path_names[action] || action}",
:method => method)
end

collection_methods.each do |action, method|
assert_recognizes(options.merge(:action => action),
:path => "/messages/#{path_names[action] || action}",
:method => method)
end
end

assert_restful_named_routes_for :messages,
:collection => collection_methods,
:member => member_methods,
:path_names => path_names do |options|

collection_methods.keys.each do |action|
assert_named_route "/messages/#{path_names[action] || action}", "#{action}_messages_path", :action => action
end

member_methods.keys.each do |action|
assert_named_route "/messages/1/#{path_names[action] || action}", "#{action}_message_path", :action => action, :id => "1"
end

end
end
end

def test_override_paths_for_default_restful_actions def test_override_paths_for_default_restful_actions
resource = ActionController::Resources::Resource.new(:messages, resource = ActionController::Resources::Resource.new(:messages,
:path_names => {:new => 'nuevo', :edit => 'editar'}) :path_names => {:new => 'nuevo', :edit => 'editar'})
Expand Down

0 comments on commit 202b091

Please sign in to comment.