From bb8b5b7cc003400263ea1006725eed441db50bc5 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Tue, 8 Jun 2010 18:00:43 +0100 Subject: [PATCH] Fix resources ignoring scope options --- actionpack/lib/action_dispatch/routing/mapper.rb | 2 + actionpack/test/dispatch/routing_test.rb | 34 +++++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index e441b85..e91a72c 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -581,6 +581,7 @@ module ActionDispatch 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 @@ module ActionDispatch def resources(*resources, &block) options = resources.extract_options! + options = (@scope[:options] || {}).merge(options) if apply_common_behavior_for(:resources, resources, options, &block) return self diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index ecc73f1..a294535 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -229,10 +229,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest 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 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest 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 -- 1.7.1