提交 d4e1a2ef 编写于 作者: A Andrew White 提交者: José Valim

Support optional static segements as well [#4832 state:resolved]

Signed-off-by: NJosé Valim <jose.valim@gmail.com>
上级 59b24ceb
......@@ -194,7 +194,7 @@ def default_controller
# for root cases, where the latter is the correct one.
def self.normalize_path(path)
path = Rack::Mount::Utils.normalize_path(path)
path.sub!(%r{/(\(+)/?([^:]*):}, '\1/\2:') unless path =~ %r{^/\(+:.*\)$}
path.gsub!(%r{/(\(+)/?}, '\1/') unless path =~ %r{^/\(+[^/]+\)$}
path
end
......
......@@ -312,6 +312,12 @@ def self.matches?(request)
get "/groups(/user/:username)" => "groups#index"
get "(/user/:username)/photos" => "photos#index"
scope '(groups)' do
scope '(discussions)' do
resources :messages
end
end
match "whatever/:controller(/:action(/:id))"
resource :profile do
......@@ -1512,6 +1518,34 @@ def test_url_generator_for_optional_prefix_static_and_dynamic_segment
end
end
def test_url_recognition_for_optional_static_segments
with_test_routes do
get '/groups/discussions/messages'
assert_equal 'messages#index', @response.body
get '/groups/discussions/messages/1'
assert_equal 'messages#show', @response.body
get '/groups/messages'
assert_equal 'messages#index', @response.body
get '/groups/messages/1'
assert_equal 'messages#show', @response.body
get '/discussions/messages'
assert_equal 'messages#index', @response.body
get '/discussions/messages/1'
assert_equal 'messages#show', @response.body
get '/messages'
assert_equal 'messages#index', @response.body
get '/messages/1'
assert_equal 'messages#show', @response.body
end
end
private
def with_test_routes
yield
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册