From d2db4e5b7be0113082326444c72f34b163e75878 Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Fri, 18 Jun 2010 17:05:56 +0200 Subject: [PATCH] fix for :shallow in router not generating helpers for create, update, and destroy actions when :only or :except is used --- actionpack/lib/action_dispatch/routing/mapper.rb | 6 +--- actionpack/test/dispatch/routing_test.rb | 23 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 46304b0..8f2ae2e 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -874,9 +874,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 +890,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..d845fd3 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -142,6 +142,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest resources :comments, :except => :destroy end + resources :users, :only => [:create, :update, :destroy] + shallow do namespace :api do resources :teams do @@ -729,6 +731,27 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_resource_routes_only_create_update_destroy + with_test_routes do + post '/users' + assert_equal 'users#create', @response.body + assert_equal '/users', users_path + + put '/users/1' + assert_equal 'users#update', @response.body + assert_equal '/users/1', user_path(1) + + delete '/users/1' + assert_equal 'users#destroy', @response.body + assert_equal '/users/1', user_path(1) + + get '/users' + assert_equal 'pass', @response.headers['X-Cascade'] + get '/users/1' + assert_equal 'pass', @response.headers['X-Cascade'] + end + end + def test_resource_with_slugs_in_ids with_test_routes do get '/posts/rails-rocks' -- 1.6.6