From cad394769413303e1da242f8ffe03069d5a59ac3 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Fri, 18 Jun 2010 16:19:09 +0100 Subject: [PATCH] Fix missing url helpers when only :create, :update and destroy actions are specified --- actionpack/lib/action_dispatch/routing/mapper.rb | 7 +++---- actionpack/test/dispatch/routing_test.rb | 12 +++++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 46304b0..95e5656 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -536,6 +536,7 @@ module ActionDispatch def member_name name end + alias_method :collection_name, :member_name def nested_path path @@ -874,9 +875,9 @@ module ActionDispatch shallow_prefix = @scope[:module].blank? ? "" : "#{@scope[:module].tr('/', '_')}_" case action - when :index + when :index, :create "#{name_prefix}#{parent_resource.collection_name}" - when :show + when :show, :update, :destroy if parent_resource.shallow? "#{shallow_prefix}#{parent_resource.member_name}" else @@ -890,8 +891,6 @@ module ActionDispatch end when :new "new_#{name_prefix}#{parent_resource.member_name}" - when :update, :create, :destroy - nil else case @scope[:scope_level] when :collection diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index e294703..b0275b4 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -261,6 +261,9 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest post :preview end end + + resource :history, :only => [:create] + resources :customers, :only => [:create] end end @@ -843,7 +846,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_equal '/account/admin/subscription', account_admin_subscription_path end end - + def test_namespace_nested_in_resources with_test_routes do get '/clients/1/google/account' @@ -1257,6 +1260,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_helper_generated_when_only_create + with_test_routes do + assert_equal '/history', history_path + assert_equal '/customers', customers_path + end + end + private def with_test_routes yield -- 1.7.1