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

This commit is contained in:
Ryan Bigg 2011-04-08 08:32:04 +10:00
commit c1fdcfc44f
2 changed files with 25 additions and 2 deletions

View File

@ -252,6 +252,10 @@ module Rails
@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)

View File

@ -145,6 +145,7 @@ end
assert_equal new_routes_code, result assert_equal new_routes_code, result
end end
def test_preserves_resources_except_option def test_preserves_resources_except_option
route = Rails::Upgrading::FakeResourceRoute.new("hats", :except => [:index]) route = Rails::Upgrading::FakeResourceRoute.new("hats", :except => [:index])
assert_equal "resources :hats, :except => [:index]", route.to_route_code assert_equal "resources :hats, :except => [:index]", route.to_route_code
@ -154,4 +155,22 @@ end
route = Rails::Upgrading::FakeResourceRoute.new("hats", :only => :show) route = Rails::Upgrading::FakeResourceRoute.new("hats", :only => :show)
assert_equal "resources :hats, :only => :show", route.to_route_code assert_equal "resources :hats, :only => :show", route.to_route_code
end end
def test_generates_code_for_delete_route
routes_code = %Q{
ActionController::Routing::Routes.draw do |map|
map.sign_out '/sign_out', :controller => 'sessions', :action => 'destroy', :method => :delete
end
}
new_routes_code = %Q{
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
assert_equal new_routes_code, upgrader.generate_new_routes
end
end end