Permalink
Browse files

Support arrays in member/collection options in the routes upgrader: {…

…:member => {:custom => [:get, :put]}}
  • Loading branch information...
1 parent 0fa6a78 commit 5223f9699c39198ebad254a5b447c89ebe1316b4 @xaviershay xaviershay committed with radar Apr 7, 2011
Showing with 9 additions and 2 deletions.
  1. +4 −2 lib/routes_upgrader.rb
  2. +5 −0 test/routes_upgrader_test.rb
View
@@ -304,8 +304,10 @@ def generate_custom_methods_for(group)
method_code = []
RouteRedrawer.stack << self
- @options[group].each do |k, v|
- method_code << "#{v} :#{k}"
+ @options[group].each do |name, methods|
+ [*methods].each do |method|
+ method_code << "#{method} :#{name}"
+ end
end
RouteRedrawer.stack.pop
@@ -89,6 +89,11 @@ def test_generates_code_for_resources_with_special_methods
assert_equal "resources :hats do\ncollection do\npost :toss\nend\nmember do\nget :wear\nend\n\nend\n", route.to_route_code
end
+ def test_generates_code_for_resources_with_multiple_special_methods_per_name
+ route = Rails::Upgrading::FakeResourceRoute.new("hats", {:member => {:wear => [:get, :put]}, :collection => {:toss => [:get, :post]}})
+ assert_equal "resources :hats do\ncollection do\nget :toss\npost :toss\nend\nmember do\nget :wear\nput :wear\nend\n\nend\n", route.to_route_code
+ end
+
def test_generates_code_for_route_with_extra_params
route = Rails::Upgrading::FakeRoute.new("/about", {:controller => 'static', :action => 'about', :something => 'extra'})
assert_equal "match '/about' => 'static#about', :something => 'extra'", route.to_route_code

0 comments on commit 5223f96

Please sign in to comment.