From 17509b9d40fc92872cf1879fb94a352a0d08019a Mon Sep 17 00:00:00 2001 From: Daniel Libanori Date: Mon, 26 Apr 2010 04:29:38 -0300 Subject: [PATCH] Fixing options to resources blocks --- actionpack/lib/action_dispatch/routing/mapper.rb | 30 +++++++++------------ actionpack/test/dispatch/routing_test.rb | 25 ++++++++++++++++++ 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 4b02c2d..cd67bd7 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -585,23 +585,17 @@ module ActionDispatch with_scope_level(:resources, resource) do yield if block_given? - with_scope_level(:collection) do - scope(resource.collection_options) do - get :index if resource.actions.include?(:index) - post :create if resource.actions.include?(:create) - get :new, :as => resource.singular if resource.actions.include?(:new) - end + collection do + get :index if resource.actions.include?(:index) + post :create if resource.actions.include?(:create) + get :new, :as => resource.singular if resource.actions.include?(:new) end - with_scope_level(:member) do - scope(':id') do - scope(resource.options) do - get :show if resource.actions.include?(:show) - put :update if resource.actions.include?(:update) - delete :destroy if resource.actions.include?(:destroy) - get :edit, :as => resource.singular if resource.actions.include?(:edit) - end - end + member do + get :show if resource.actions.include?(:show) + put :update if resource.actions.include?(:update) + delete :destroy if resource.actions.include?(:destroy) + get :edit if resource.actions.include?(:edit) end end end @@ -615,7 +609,8 @@ module ActionDispatch end with_scope_level(:collection) do - scope(:name_prefix => parent_resource.collection_name, :as => "") do + options = parent_resource.collection_options + scope(options.merge(:as => parent_resource.collection_name)) do yield end end @@ -627,7 +622,8 @@ module ActionDispatch end with_scope_level(:member) do - scope(':id', :name_prefix => parent_resource.member_name, :as => "") do + options = parent_resource.options + scope(':id', options.merge(:as => parent_resource.singular)) do yield end end diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 5bca476..71e91c8 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -201,6 +201,18 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end match "whatever/:controller(/:action(/:id))" + + resources :jokes, :name_prefix => 'fail' do + get :lastest, :on => :collection + collection do + get :search + end + + post :report, :on => :member + member do + post :rate + end + end end end @@ -990,6 +1002,19 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_resource_block_with_options + with_test_routes do + assert_equal '/jokes', fail_jokes_path + assert_equal '/jokes/new', new_fail_joke_path + assert_equal '/jokes/1', fail_joke_path(1) + assert_equal '/jokes/1/edit', edit_fail_joke_path(1) + assert_equal '/jokes/lastest', lastest_fail_jokes_path + assert_equal '/jokes/search', search_fail_jokes_path + assert_equal '/jokes/1/report', report_fail_joke_path(1) + assert_equal '/jokes/1/rate', rate_fail_joke_path(1) + end + end + def test_url_generator_for_generic_route with_test_routes do get 'whatever/foo/bar' -- 1.6.3.3