Skip to content
Browse files

Cleanup internal resource macro to use method helper shorthand

  • Loading branch information...
1 parent 21ce8ea commit 576b8dda52b0d0d099f88241ef6f4ec1e1248c3b @josh josh committed Jan 15, 2010
Showing with 26 additions and 20 deletions.
  1. +14 −20 actionpack/lib/action_dispatch/routing/mapper.rb
  2. +12 −0 actionpack/test/dispatch/routing_test.rb
View
34 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -344,7 +344,7 @@ def merge_options_scope(parent, child)
end
module Resources
- CRUD_ACTIONS = [:index, :show, :new, :edit, :create, :update, :destroy]
+ CRUD_ACTIONS = [:index, :show, :create, :update, :destroy]
class Resource #:nodoc:
def self.default_actions
@@ -444,12 +444,12 @@ def resource(*resources, &block)
with_scope_level(:resource, resource) do
yield if block_given?
- get "(.:format)", :to => :show, :as => resource.member_name if resource.actions.include?(:show)
- post "(.:format)", :to => :create if resource.actions.include?(:create)
- put "(.:format)", :to => :update if resource.actions.include?(:update)
- delete "(.:format)", :to => :destroy if resource.actions.include?(:destroy)
- get "/#{action_path(:new)}(.:format)", :to => :new, :as => "new_#{resource.singular}" if resource.actions.include?(:new)
- get "/#{action_path(:edit)}(.:format)", :to => :edit, :as => "edit_#{resource.singular}" if resource.actions.include?(:edit)
+ get :show, :as => resource.member_name if resource.actions.include?(:show)
+ post :create if resource.actions.include?(:create)
+ put :update if resource.actions.include?(:update)
+ delete :destroy if resource.actions.include?(:destroy)
+ get :new, :as => "new_#{resource.singular}" if resource.actions.include?(:new)
+ get :edit, :as => "edit_#{resource.singular}" if resource.actions.include?(:edit)
end
end
@@ -486,23 +486,17 @@ def resources(*resources, &block)
yield if block_given?
with_scope_level(:collection) do
- get "(.:format)", :to => :index, :as => resource.collection_name if resource.actions.include?(:index)
- post "(.:format)", :to => :create if resource.actions.include?(:create)
-
- with_exclusive_name_prefix :new do
- get "/#{action_path(:new)}(.:format)", :to => :new, :as => resource.singular if resource.actions.include?(:new)
- end
+ get :index, :as => resource.collection_name 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
- get "(.:format)", :to => :show, :as => resource.member_name if resource.actions.include?(:show)
- put "(.:format)", :to => :update if resource.actions.include?(:update)
- delete "(.:format)", :to => :destroy if resource.actions.include?(:destroy)
-
- with_exclusive_name_prefix :edit do
- get "/#{action_path(:edit)}(.:format)", :to => :edit, :as => resource.singular if resource.actions.include?(:edit)
- end
+ get :show, :as => resource.member_name 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
end
View
12 actionpack/test/dispatch/routing_test.rb
@@ -211,8 +211,17 @@ def test_session_singleton_resource
post '/session'
assert_equal 'sessions#create', @response.body
+ put '/session'
+ assert_equal 'sessions#update', @response.body
+
+ delete '/session'
+ assert_equal 'sessions#destroy', @response.body
+
get '/session/new'
assert_equal 'sessions#new', @response.body
+
+ get '/session/edit'
+ assert_equal 'sessions#edit', @response.body
end
end
@@ -284,6 +293,9 @@ def test_projects
assert_equal 'projects#index', @response.body
assert_equal '/projects', projects_path
+ post '/projects'
+ assert_equal 'projects#create', @response.body
+
get '/projects.xml'
assert_equal 'projects#index', @response.body
assert_equal '/projects.xml', projects_path(:format => 'xml')

0 comments on commit 576b8dd

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