Support arrays in member/collection options in the routes upgrader: {:member => {:custom => [:get, :put]}}

This commit is contained in:
Xavier Shay 2011-04-08 08:17:50 +10:00 committed by Ryan Bigg
parent 0fa6a78f62
commit 5223f9699c
2 changed files with 9 additions and 2 deletions

View File

@ -304,8 +304,10 @@ module Rails
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

View File

@ -89,6 +89,11 @@ end
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