Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix resources ignoring scope options

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit a7edddf605d2ffbb6669365dcd23d6e4c6c2cf84 1 parent 47bf19c
@pixeltrix pixeltrix authored josevalim committed
View
2  actionpack/lib/action_dispatch/routing/mapper.rb
@@ -581,6 +581,7 @@ def initialize(*args) #:nodoc:
def resource(*resources, &block)
options = resources.extract_options!
+ options = (@scope[:options] || {}).merge(options)
if apply_common_behavior_for(:resource, resources, options, &block)
return self
@@ -611,6 +612,7 @@ def resource(*resources, &block)
def resources(*resources, &block)
options = resources.extract_options!
+ options = (@scope[:options] || {}).merge(options)
if apply_common_behavior_for(:resources, resources, options, &block)
return self
View
34 actionpack/test/dispatch/routing_test.rb
@@ -229,10 +229,13 @@ def self.matches?(request)
root :to => 'projects#index'
end
- resources :products, :constraints => { :id => /\d{4}/ } do
- root :to => "products#root"
- get :favorite, :on => :collection
- resources :images
+ scope :only => [:index, :show] do
+ resources :products, :constraints => { :id => /\d{4}/ } do
+ root :to => "products#root"
+ get :favorite, :on => :collection
+ resources :images
+ end
+ resource :account
end
resource :dashboard, :constraints => { :ip => /192\.168\.1\.\d{1,3}/ }
@@ -1123,6 +1126,29 @@ def test_resource_new_actions
end
end
+ def test_resource_merges_options_from_scope
+ with_test_routes do
+ assert_raise(NameError) { new_account_path }
+
+ get '/account/new'
+ assert_equal 404, status
+ end
+ end
+
+ def test_resources_merges_options_from_scope
+ with_test_routes do
+ assert_raise(NoMethodError) { edit_product_path('1') }
+
+ get '/products/1/edit'
+ assert_equal 404, status
+
+ assert_raise(NoMethodError) { edit_product_image_path('1', '2') }
+
+ post '/products/1/images/2/edit'
+ assert_equal 404, status
+ end
+ end
+
private
def with_test_routes
yield
Please sign in to comment.
Something went wrong with that request. Please try again.