Permalink
Browse files

Make sure that formatted routes for all verbs are created. Still need…

…s to resolve two failing tests after this refactoring [DHH]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5096 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 89840c4 commit 73a8d7393f842d4030561cef20fcf0ec9d52e1b9 @dhh dhh committed Sep 13, 2006
Showing with 24 additions and 21 deletions.
  1. +19 −15 actionpack/lib/action_controller/resources.rb
  2. +5 −6 actionpack/test/controller/resources_test.rb
@@ -45,11 +45,7 @@ def arrange_actions
end
def add_default_actions
- add_default_action(collection_methods, :post, :create)
- add_default_action(member_methods, :get, :edit)
- add_default_action(member_methods, :put, :update)
- add_default_action(member_methods, :delete, :destroy)
- add_default_action(new_methods, :get, :new)
+ add_default_action(member_methods, :get, :edit)
end
def set_prefixes
@@ -250,24 +246,26 @@ def map_collection_actions(map, resource)
map.connect(resource.path, route_options.merge(:action => primary))
map.connect("#{resource.path}.:format", route_options.merge(:action => primary))
end
-
- map.named_route("#{resource.name_prefix}#{resource.plural}", resource.path, :action => "index", :conditions => { :method => :get })
- map.named_route("formatted_#{resource.name_prefix}#{resource.plural}", "#{resource.path}.:format", :action => "index", :conditions => { :method => :get })
end
+
+ map.named_route("#{resource.name_prefix}#{resource.plural}", resource.path, :action => "index", :conditions => { :method => :get })
+ map.named_route("formatted_#{resource.name_prefix}#{resource.plural}", "#{resource.path}.:format", :action => "index", :conditions => { :method => :get })
+
+ map.connect(resource.path, :action => "create", :conditions => { :method => :post })
+ map.connect("#{resource.path}.:format", :action => "create", :conditions => { :method => :post })
end
-
+
def map_new_actions(map, resource)
resource.new_methods.each do |method, actions|
route_options = requirements_for(method)
actions.each do |action|
- path = action == :new ? resource.new_path : "#{resource.new_path};#{action}"
- name = "new_#{resource.singular}"
- name = "#{action}_#{name}" unless action == :new
-
- map.named_route("#{resource.name_prefix}#{name}", path, route_options.merge(:action => action.to_s))
- map.named_route("formatted_#{resource.name_prefix}#{name}", action == :new ? "#{resource.new_path}.:format" : "#{resource.new_path}.:format;#{action}", route_options.merge(:action => action.to_s))
+ map.named_route("#{resource.name_prefix}#{action}_new_#{resource.singular}", "#{resource.new_path};#{action}", route_options.merge(:action => action.to_s))
+ map.named_route("formatted_#{resource.name_prefix}#{action}_new_#{resource.singular}", "#{resource.new_path}.:format;#{action}", route_options.merge(:action => action.to_s))
end
end
+
+ map.named_route("#{resource.name_prefix}new_#{resource.singular}", resource.new_path, :action => "new", :conditions => { :method => :get })
+ map.named_route("formatted_#{resource.name_prefix}new_#{resource.singular}", "#{resource.new_path}.:format", :action => "new", :conditions => { :method => :get })
end
def map_member_actions(map, resource)
@@ -285,6 +283,12 @@ def map_member_actions(map, resource)
map.named_route("#{resource.name_prefix}#{resource.singular}", resource.member_path, :action => "show", :conditions => { :method => :get })
map.named_route("formatted_#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}.:format", :action => "show", :conditions => { :method => :get })
+
+ map.connect(resource.member_path, :action => "update", :conditions => { :method => :put })
+ map.connect("#{resource.member_path}.:format", :action => "update", :conditions => { :method => :put })
+
+ map.connect(resource.member_path, :action => "destroy", :conditions => { :method => :delete })
+ map.connect("#{resource.member_path}.:format", :action => "destroy", :conditions => { :method => :delete })
end
def requirements_for(method)
@@ -17,12 +17,11 @@ def test_should_arrange_actions
:member => { :rss => :get, :atom => :get, :upload => :post, :fix => :post },
:new => { :preview => :get, :draft => :get })
- assert_resource_methods [:rss], resource, :collection, :get
- assert_resource_methods [:create, :csv, :reorder], resource, :collection, :post
- assert_resource_methods [:edit, :rss, :atom], resource, :member, :get
- assert_resource_methods [:upload, :fix], resource, :member, :post
- assert_resource_methods [:update], resource, :member, :put
- assert_resource_methods [:new, :preview, :draft], resource, :new, :get
+ assert_resource_methods [:rss], resource, :collection, :get
+ assert_resource_methods [:csv, :reorder], resource, :collection, :post
+ assert_resource_methods [:edit, :rss, :atom], resource, :member, :get
+ assert_resource_methods [:upload, :fix], resource, :member, :post
+ assert_resource_methods [:preview, :draft], resource, :new, :get
end
def test_default_restful_routes

0 comments on commit 73a8d73

Please sign in to comment.