From 075c128f31650e65dad931cc2c4d7e5f7596422d Mon Sep 17 00:00:00 2001 From: Marc Chung Date: Sat, 26 Feb 2011 11:04:21 -0700 Subject: [PATCH] fixed up rails-3 verb routing. convert 'method' into 'via' --- lib/routes_upgrader.rb | 8 ++++++-- test/routes_upgrader_test.rb | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/routes_upgrader.rb b/lib/routes_upgrader.rb index 82dea89..3d0ce12 100644 --- a/lib/routes_upgrader.rb +++ b/lib/routes_upgrader.rb @@ -251,11 +251,15 @@ module Rails 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("") diff --git a/test/routes_upgrader_test.rb b/test/routes_upgrader_test.rb index 3d2c6a3..9326ea1 100644 --- a/test/routes_upgrader_test.rb +++ b/test/routes_upgrader_test.rb @@ -139,4 +139,24 @@ end assert_equal new_routes_code, result 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 \ No newline at end of file