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:
parent
865e3f7d2a
commit
7915c8df40
@ -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
|
||||
|
||||
|
@ -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|
|
||||
|
Loading…
Reference in New Issue
Block a user