Permalink
Browse files

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

  • Loading branch information...
2 parents 11d0804 + 075c128 commit c1fdcfc44f856b1b92b3b753327b88c6562603ee @radar radar committed Apr 7, 2011
Showing with 25 additions and 2 deletions.
  1. +6 −2 lib/routes_upgrader.rb
  2. +19 −0 test/routes_upgrader_test.rb
View
@@ -251,11 +251,15 @@ def to_route_code
if @options[:conditions]
@options[:via] = @options.delete(:conditions).delete(:method)
end
-
+
+ if @options[:method]
+ @options[:via] = @options.delete(:method).to_s
+ end
+
@options ||= {}
base = (base % [@path, @options.delete(:controller), (@options.delete(:action) || "index")])
opts = opts_to_string(@options)
-
+
route_pieces = ([base] + extra_options + [opts])
route_pieces.delete("")
@@ -145,6 +145,7 @@ def test_generates_code_for_default_route
assert_equal new_routes_code, result
end
+
def test_preserves_resources_except_option
route = Rails::Upgrading::FakeResourceRoute.new("hats", :except => [:index])
assert_equal "resources :hats, :except => [:index]", route.to_route_code
@@ -154,4 +155,22 @@ def test_preserves_resources_only_option
route = Rails::Upgrading::FakeResourceRoute.new("hats", :only => :show)
assert_equal "resources :hats, :only => :show", route.to_route_code
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

0 comments on commit c1fdcfc

Please sign in to comment.