fixed up rails-3 verb routing. convert 'method' into 'via'

This commit is contained in:
Marc Chung 2011-02-26 11:04:21 -07:00
parent 56b03373a8
commit 075c128f31
2 changed files with 26 additions and 2 deletions

View File

@ -251,11 +251,15 @@ module Rails
if @options[:conditions] if @options[:conditions]
@options[:via] = @options.delete(:conditions).delete(:method) @options[:via] = @options.delete(:conditions).delete(:method)
end end
if @options[:method]
@options[:via] = @options.delete(:method).to_s
end
@options ||= {} @options ||= {}
base = (base % [@path, @options.delete(:controller), (@options.delete(:action) || "index")]) base = (base % [@path, @options.delete(:controller), (@options.delete(:action) || "index")])
opts = opts_to_string(@options) opts = opts_to_string(@options)
route_pieces = ([base] + extra_options + [opts]) route_pieces = ([base] + extra_options + [opts])
route_pieces.delete("") route_pieces.delete("")

View File

@ -139,4 +139,24 @@ end
assert_equal new_routes_code, result assert_equal new_routes_code, result
end end
def test_generates_code_for_delete_route
routes_code = "
ActionController::Routing::Routes.draw do |map|
map.sign_out '/sign_out', :controller => 'sessions', :action => 'destroy', :method => :delete
end
"
new_routes_code = "MyApplication::Application.routes.draw do
match '/sign_out' => 'sessions#destroy', :as => :sign_out, :via => 'delete'
end
"
upgrader = Rails::Upgrading::RoutesUpgrader.new
upgrader.routes_code = routes_code
result = upgrader.generate_new_routes
assert_equal new_routes_code, result
end
end end