Skip to content

Commit

Permalink
fixed up rails-3 verb routing. convert 'method' into 'via'
Browse files Browse the repository at this point in the history
  • Loading branch information
mchung committed Feb 26, 2011
1 parent 56b0337 commit 075c128
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/routes_upgrader.rb
Expand Up @@ -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("")

Expand Down
20 changes: 20 additions & 0 deletions test/routes_upgrader_test.rb
Expand Up @@ -139,4 +139,24 @@ def test_generates_code_for_default_route

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

0 comments on commit 075c128

Please sign in to comment.