diff --git a/lib/routes_upgrader.rb b/lib/routes_upgrader.rb index a47f024..82dea89 100644 --- a/lib/routes_upgrader.rb +++ b/lib/routes_upgrader.rb @@ -185,7 +185,17 @@ module Rails end def opts_to_string(opts) - opts.is_a?(Hash) ? opts.to_a.map {|o, v| ":#{o} => '#{v}'"}.join(", ") : nil + opts.is_a?(Hash) ? opts.map {|k, v| + ":#{k} => " + (v.is_a?(Hash) ? ('{ ' + opts_to_string(v) + ' }') : "#{value_to_string(v)}") + }.join(", ") : opts.to_s + end + + def value_to_string(value) + case value + when Regexp then value.inspect + when String then "'" + value.to_s + "'" + else value.to_s + end end end diff --git a/test/routes_upgrader_test.rb b/test/routes_upgrader_test.rb index e9b7ca9..3d2c6a3 100644 --- a/test/routes_upgrader_test.rb +++ b/test/routes_upgrader_test.rb @@ -94,6 +94,11 @@ end assert_equal "match '/about' => 'static#about', :something => 'extra'", route.to_route_code end + def test_generates_code_for_route_with_requirements + route = Rails::Upgrading::FakeRoute.new("/foo", {:controller => 'foo', :action => 'bar', :requirements => {:digit => /%d/}}) + assert_equal "match '/foo' => 'foo#bar', :constraints => { :digit => /%d/ }", route.to_route_code + end + def test_generates_code_for_root routes_code = " ActionController::Routing::Routes.draw do |map|