Skip to content
This repository
Browse code

Fix resources ignoring scope options

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit a7edddf605d2ffbb6669365dcd23d6e4c6c2cf84 1 parent 47bf19c
Andrew White authored June 08, 2010 josevalim committed June 08, 2010
2  actionpack/lib/action_dispatch/routing/mapper.rb
@@ -581,6 +581,7 @@ def initialize(*args) #:nodoc:
581 581
 
582 582
         def resource(*resources, &block)
583 583
           options = resources.extract_options!
  584
+          options = (@scope[:options] || {}).merge(options)
584 585
 
585 586
           if apply_common_behavior_for(:resource, resources, options, &block)
586 587
             return self
@@ -611,6 +612,7 @@ def resource(*resources, &block)
611 612
 
612 613
         def resources(*resources, &block)
613 614
           options = resources.extract_options!
  615
+          options = (@scope[:options] || {}).merge(options)
614 616
 
615 617
           if apply_common_behavior_for(:resources, resources, options, &block)
616 618
             return self
34  actionpack/test/dispatch/routing_test.rb
@@ -229,10 +229,13 @@ def self.matches?(request)
229 229
         root :to => 'projects#index'
230 230
       end
231 231
 
232  
-      resources :products, :constraints => { :id => /\d{4}/ } do
233  
-        root :to => "products#root"
234  
-        get :favorite, :on => :collection
235  
-        resources :images
  232
+      scope :only => [:index, :show] do
  233
+        resources :products, :constraints => { :id => /\d{4}/ } do
  234
+          root :to => "products#root"
  235
+          get :favorite, :on => :collection
  236
+          resources :images
  237
+        end
  238
+        resource :account
236 239
       end
237 240
 
238 241
       resource :dashboard, :constraints => { :ip => /192\.168\.1\.\d{1,3}/ }
@@ -1123,6 +1126,29 @@ def test_resource_new_actions
1123 1126
     end
1124 1127
   end
1125 1128
 
  1129
+  def test_resource_merges_options_from_scope
  1130
+    with_test_routes do
  1131
+      assert_raise(NameError) { new_account_path }
  1132
+
  1133
+      get '/account/new'
  1134
+      assert_equal 404, status
  1135
+    end
  1136
+  end
  1137
+
  1138
+  def test_resources_merges_options_from_scope
  1139
+    with_test_routes do
  1140
+      assert_raise(NoMethodError) { edit_product_path('1') }
  1141
+
  1142
+      get '/products/1/edit'
  1143
+      assert_equal 404, status
  1144
+
  1145
+      assert_raise(NoMethodError) { edit_product_image_path('1', '2') }
  1146
+
  1147
+      post '/products/1/images/2/edit'
  1148
+      assert_equal 404, status
  1149
+    end
  1150
+  end
  1151
+
1126 1152
   private
1127 1153
     def with_test_routes
1128 1154
       yield

0 notes on commit a7edddf

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