Skip to content
This repository
Browse code

fix for :shallow in router not generating helpers for create, update,…

… and destroy actions when :only or :except are used

[#4900 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
commit 9d3eeb905341aaad942ceb0e47bd04cced34d031 1 parent a55d832
Josh Kalderimis authored June 18, 2010 jeremy committed June 18, 2010
7  actionpack/lib/action_dispatch/routing/mapper.rb
@@ -536,6 +536,7 @@ def initialize(entity, options = {})
536 536
           def member_name
537 537
             name
538 538
           end
  539
+          alias_method :collection_name, :member_name
539 540
 
540 541
           def nested_path
541 542
             path
@@ -874,9 +875,9 @@ def name_for_action(action)
874 875
             shallow_prefix = @scope[:module].blank? ? "" : "#{@scope[:module].tr('/', '_')}_"
875 876
 
876 877
             case action
877  
-            when :index
  878
+            when :index, :create
878 879
               "#{name_prefix}#{parent_resource.collection_name}"
879  
-            when :show
  880
+            when :show, :update, :destroy
880 881
               if parent_resource.shallow?
881 882
                 "#{shallow_prefix}#{parent_resource.member_name}"
882 883
               else
@@ -890,8 +891,6 @@ def name_for_action(action)
890 891
               end
891 892
             when :new
892 893
               "new_#{name_prefix}#{parent_resource.member_name}"
893  
-            when :update, :create, :destroy
894  
-              nil
895 894
             else
896 895
               case @scope[:scope_level]
897 896
               when :collection
40  actionpack/test/dispatch/routing_test.rb
@@ -142,6 +142,12 @@ def self.matches?(request)
142 142
         resources :comments, :except => :destroy
143 143
       end
144 144
 
  145
+      resource  :past, :only => :destroy
  146
+      resource  :present, :only => :update
  147
+      resource  :future, :only => :create
  148
+      resources :relationships, :only => [:create, :destroy]
  149
+      resources :friendships,   :only => [:update]
  150
+
145 151
       shallow do
146 152
         namespace :api do
147 153
           resources :teams do
@@ -729,6 +735,38 @@ def test_resource_routes_with_only_and_except
729 735
     end
730 736
   end
731 737
 
  738
+  def test_resource_routes_only_create_update_destroy
  739
+    with_test_routes do
  740
+      delete '/past'
  741
+      assert_equal 'pasts#destroy', @response.body
  742
+      assert_equal '/past', past_path
  743
+
  744
+      put '/present'
  745
+      assert_equal 'presents#update', @response.body
  746
+      assert_equal '/present', present_path
  747
+
  748
+      post '/future'
  749
+      assert_equal 'futures#create', @response.body
  750
+      assert_equal '/future', future_path
  751
+    end
  752
+  end
  753
+
  754
+  def test_resources_routes_only_create_update_destroy
  755
+    with_test_routes do
  756
+      post '/relationships'
  757
+      assert_equal 'relationships#create', @response.body
  758
+      assert_equal '/relationships', relationships_path
  759
+
  760
+      delete '/relationships/1'
  761
+      assert_equal 'relationships#destroy', @response.body
  762
+      assert_equal '/relationships/1', relationship_path(1)
  763
+
  764
+      put '/friendships/1'
  765
+      assert_equal 'friendships#update', @response.body
  766
+      assert_equal '/friendships/1', friendship_path(1)
  767
+    end
  768
+  end
  769
+
732 770
   def test_resource_with_slugs_in_ids
733 771
     with_test_routes do
734 772
       get '/posts/rails-rocks'
@@ -843,7 +881,7 @@ def test_nested_namespace
843 881
       assert_equal '/account/admin/subscription', account_admin_subscription_path
844 882
     end
845 883
   end
846  
-  
  884
+
847 885
   def test_namespace_nested_in_resources
848 886
     with_test_routes do
849 887
       get '/clients/1/google/account'

1 note on commit 9d3eeb9

Diego Plentz
plentz commented on 9d3eeb9 May 20, 2011

related to issue #1167

Please sign in to comment.
Something went wrong with that request. Please try again.