Permalink
Browse files

fix translation of route conditions

- `:method => xxx` is invalid rails 2 route syntax.  must be `:conditions => {:method => xxx}`
- preserve symbols in value_to_string. e.g. `:delete`
- preserve arrays in value_to_string. e.g. `[:delete, :get]`
  • Loading branch information...
1 parent 200ce0a commit 795ef872628d32a54bef3c4848fb775d9c65432a Jordan Brough committed Jun 14, 2011
Showing with 21 additions and 7 deletions.
  1. +1 −5 lib/routes_upgrader.rb
  2. +20 −2 test/routes_upgrader_test.rb
View
@@ -174,7 +174,7 @@ def opts_to_string(opts)
def value_to_string(value)
case value
- when Regexp then value.inspect
+ when Regexp, Symbol, Array then value.inspect
when String then "'" + value.to_s + "'"
else value.to_s
end
@@ -240,10 +240,6 @@ def to_route_code
@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)
@@ -183,13 +183,31 @@ def test_preserves_resources_only_option
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
+ map.sign_out '/sign_out', :controller => 'sessions', :action => 'destroy', :conditions => {:method => :delete}
end
}
new_routes_code = %Q{
MyApplication::Application.routes.draw do
- match '/sign_out' => 'sessions#destroy', :as => :sign_out, :via => 'delete'
+ 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.strip, upgrader.generate_new_routes.strip
+ 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', :conditions => {:method => [:delete, :get]}
+end
+ }
+
+ new_routes_code = %Q{
+MyApplication::Application.routes.draw do
+ match '/sign_out' => 'sessions#destroy', :as => :sign_out, :via => [:delete, :get]
end
}

0 comments on commit 795ef87

Please sign in to comment.