diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-09-13 04:04:19 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-09-13 04:04:19 +0000 |
commit | 73a8d7393f842d4030561cef20fcf0ec9d52e1b9 (patch) | |
tree | a29412a6155f5d4e0be7f855a4061a096a1272ca /actionpack | |
parent | 89840c40ceb54855fa81e641586abba04c3e35cb (diff) | |
download | rails-73a8d7393f842d4030561cef20fcf0ec9d52e1b9.tar.gz rails-73a8d7393f842d4030561cef20fcf0ec9d52e1b9.tar.bz2 rails-73a8d7393f842d4030561cef20fcf0ec9d52e1b9.zip |
Make sure that formatted routes for all verbs are created. Still needs 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
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_controller/resources.rb | 34 | ||||
-rw-r--r-- | actionpack/test/controller/resources_test.rb | 11 |
2 files changed, 24 insertions, 21 deletions
diff --git a/actionpack/lib/action_controller/resources.rb b/actionpack/lib/action_controller/resources.rb index 1c59a23c96..dcc4c19c90 100644 --- a/actionpack/lib/action_controller/resources.rb +++ b/actionpack/lib/action_controller/resources.rb @@ -45,11 +45,7 @@ module ActionController 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 @@ module ActionController 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 @@ module ActionController 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) diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index 7e0299e834..e6ce8f21a2 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -17,12 +17,11 @@ class ResourcesTest < Test::Unit::TestCase :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 |