From 8a189f895fa47e25c935f4e349e4526917f87c8e Mon Sep 17 00:00:00 2001 From: Eugene Pimenov Date: Fri, 18 Apr 2008 15:45:33 +0400 Subject: [PATCH] :member in routes rewrites show action when :path_names specified. Commit 063c393bf0a2eb762770c97f925b7c2867361ad4 broke :member in routes. For example: map.routes :messages, :path_names => {:new => 'nuevo'}, :member => {:mark => :put} in map_member_actions action_path is "", so it rewrites show action. --- actionpack/lib/action_controller/resources.rb | 2 +- actionpack/test/controller/resources_test.rb | 45 +++++++++++++++++++++---- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/actionpack/lib/action_controller/resources.rb b/actionpack/lib/action_controller/resources.rb index df7d6ea..d3cedfd 100644 --- a/actionpack/lib/action_controller/resources.rb +++ b/actionpack/lib/action_controller/resources.rb @@ -527,7 +527,7 @@ module ActionController action_path = action if resource.options[:path_names] action_path = resource.options[:path_names][action] - action_path ||= Base.resources_path_names[action] + action_path ||= Base.resources_path_names[action] || action end map.named_route("#{action}_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}#{resource.action_separator}#{action_path}", action_options) diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index 0f1ac30..b138cee 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -209,6 +209,23 @@ class ResourcesTest < Test::Unit::TestCase end end + def test_member_when_override_paths_for_default_restful_actions_with + [:put, :post].each do |method| + with_restful_routing :messages, :member => { :mark => method }, :path_names => {:new => 'nuevo'} do + mark_options = {:action => 'mark', :id => '1', :controller => "messages"} + mark_path = "/messages/1/mark" + + assert_restful_routes_for :messages, :path_names => {:new => 'nuevo'} do |options| + assert_recognizes(options.merge(mark_options), :path => mark_path, :method => method) + end + + assert_restful_named_routes_for :messages, :path_names => {:new => 'nuevo'} do |options| + assert_named_route mark_path, :mark_message_path, mark_options + end + end + end + end + def test_with_two_member_actions_with_same_method [:put, :post].each do |method| with_restful_routing :messages, :member => { :mark => method, :unmark => method } do @@ -674,11 +691,18 @@ class ResourcesTest < Test::Unit::TestCase options[:options] ||= {} options[:options][:controller] = options[:controller] || controller_name.to_s + new_action = "new" + edit_action = "edit" + if options[:path_names] + new_action = options[:path_names][:new] || "new" + edit_action = options[:path_names][:edit] || "edit" + end + collection_path = "/#{options[:path_prefix]}#{options[:as] || controller_name}" member_path = "#{collection_path}/1" - new_path = "#{collection_path}/new" - edit_member_path = "#{member_path}/edit" - formatted_edit_member_path = "#{member_path}/edit.xml" + new_path = "#{collection_path}/#{new_action}" + edit_member_path = "#{member_path}/#{edit_action}" + formatted_edit_member_path = "#{member_path}/#{edit_action}.xml" with_options(options[:options]) do |controller| controller.assert_routing collection_path, :action => 'index' @@ -730,15 +754,22 @@ class ResourcesTest < Test::Unit::TestCase full_prefix = "/#{options[:path_prefix]}#{options[:as] || controller_name}" name_prefix = options[:name_prefix] + new_action = "new" + edit_action = "edit" + if options[:path_names] + new_action = options[:path_names][:new] || "new" + edit_action = options[:path_names][:edit] || "edit" + end + assert_named_route "#{full_prefix}", "#{name_prefix}#{controller_name}_path", options[:options] assert_named_route "#{full_prefix}.xml", "formatted_#{name_prefix}#{controller_name}_path", options[:options].merge( :format => 'xml') assert_named_route "#{full_prefix}/1", "#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1') assert_named_route "#{full_prefix}/1.xml", "formatted_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1', :format => 'xml') - assert_named_route "#{full_prefix}/new", "new_#{name_prefix}#{singular_name}_path", options[:options] - assert_named_route "#{full_prefix}/new.xml", "formatted_new_#{name_prefix}#{singular_name}_path", options[:options].merge( :format => 'xml') - assert_named_route "#{full_prefix}/1/edit", "edit_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1') - assert_named_route "#{full_prefix}/1/edit.xml", "formatted_edit_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1', :format => 'xml') + assert_named_route "#{full_prefix}/#{new_action}", "new_#{name_prefix}#{singular_name}_path", options[:options] + assert_named_route "#{full_prefix}/#{new_action}.xml", "formatted_new_#{name_prefix}#{singular_name}_path", options[:options].merge( :format => 'xml') + assert_named_route "#{full_prefix}/1/#{edit_action}", "edit_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1') + assert_named_route "#{full_prefix}/1/#{edit_action}.xml", "formatted_edit_#{name_prefix}#{singular_name}_path", options[:options].merge(:id => '1', :format => 'xml') yield options[:options] if block_given? end -- 1.5.5.43.g74bd6