Second fix to route upgrade bug for :requirements Regexp conversion. Also handles string values, adds additional test and tests pass.

This commit is contained in:
Neil Cook 2010-06-11 23:19:42 +08:00 committed by Jeremy McAnally
parent 865e3f7d2a
commit 7915c8df40
2 changed files with 16 additions and 1 deletions

View File

@ -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

View File

@ -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|