Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
35933822
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
35933822
编写于
1月 14, 2010
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ensure optional path scopes are properly handled.
上级
2835ec61
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
64 addition
and
8 deletion
+64
-8
actionpack/lib/action_dispatch/routing/mapper.rb
actionpack/lib/action_dispatch/routing/mapper.rb
+12
-8
actionpack/test/dispatch/routing_test.rb
actionpack/test/dispatch/routing_test.rb
+52
-0
未找到文件。
actionpack/lib/action_dispatch/routing/mapper.rb
浏览文件 @
35933822
...
@@ -68,13 +68,9 @@ def using_match_shorthand?(args, options)
...
@@ -68,13 +68,9 @@ def using_match_shorthand?(args, options)
end
end
def
normalize_path
(
path
)
def
normalize_path
(
path
)
path
=
nil
if
path
==
""
path
=
"
#{
@scope
[
:path
]
}#{
path
}
"
path
=
"
#{
@scope
[
:path
]
}#{
path
}
"
if
@scope
[
:path
]
raise
ArgumentError
,
"path is required"
if
path
.
empty?
path
=
Rack
::
Mount
::
Utils
.
normalize_path
(
path
)
if
path
Mapper
.
normalize_path
(
path
)
raise
ArgumentError
,
"path is required"
unless
path
path
end
end
def
app
def
app
...
@@ -160,6 +156,14 @@ def default_controller
...
@@ -160,6 +156,14 @@ def default_controller
end
end
end
end
# Invokes Rack::Mount::Utils.normalize path and ensure that
# (:locale) becomes (/:locale) instead of /(:locale).
def
self
.
normalize_path
(
path
)
path
=
Rack
::
Mount
::
Utils
.
normalize_path
(
path
)
path
.
sub!
(
/^\/\(+\/?:/
,
'(/:'
)
path
end
module
Base
module
Base
def
initialize
(
set
)
def
initialize
(
set
)
@set
=
set
@set
=
set
...
@@ -245,7 +249,7 @@ def scope(*args)
...
@@ -245,7 +249,7 @@ def scope(*args)
if
path
=
options
.
delete
(
:path
)
if
path
=
options
.
delete
(
:path
)
path_set
=
true
path_set
=
true
path
,
@scope
[
:path
]
=
@scope
[
:path
],
Rack
::
Mount
::
Utils
.
normalize_path
(
@scope
[
:path
].
to_s
+
path
.
to_s
)
path
,
@scope
[
:path
]
=
@scope
[
:path
],
Mapper
.
normalize_path
(
@scope
[
:path
].
to_s
+
path
.
to_s
)
else
else
path_set
=
false
path_set
=
false
end
end
...
...
actionpack/test/dispatch/routing_test.rb
浏览文件 @
35933822
...
@@ -129,6 +129,16 @@ def self.matches?(request)
...
@@ -129,6 +129,16 @@ def self.matches?(request)
resources
:rooms
resources
:rooms
end
end
scope
'(:locale)'
,
:locale
=>
/en|pl/
do
resources
:descriptions
end
namespace
:admin
do
scope
'(/:locale)'
,
:locale
=>
/en|pl/
do
resources
:descriptions
end
end
match
'/info'
=>
'projects#info'
,
:as
=>
'info'
match
'/info'
=>
'projects#info'
,
:as
=>
'info'
root
:to
=>
'projects#index'
root
:to
=>
'projects#index'
...
@@ -594,6 +604,48 @@ def test_redirect_with_port
...
@@ -594,6 +604,48 @@ def test_redirect_with_port
self
.
host
=
previous_host
self
.
host
=
previous_host
end
end
def
test_optional_scoped_path
with_test_routes
do
assert_equal
'/en/descriptions'
,
descriptions_path
(
"en"
)
assert_equal
'/descriptions'
,
descriptions_path
(
nil
)
assert_equal
'/en/descriptions/1'
,
description_path
(
"en"
,
1
)
assert_equal
'/descriptions/1'
,
description_path
(
nil
,
1
)
get
'/en/descriptions'
assert_equal
'descriptions#index'
,
@response
.
body
get
'/descriptions'
assert_equal
'descriptions#index'
,
@response
.
body
get
'/en/descriptions/1'
assert_equal
'descriptions#show'
,
@response
.
body
get
'/descriptions/1'
assert_equal
'descriptions#show'
,
@response
.
body
end
end
def
test_nested_optional_scoped_path
with_test_routes
do
assert_equal
'/admin/en/descriptions'
,
admin_descriptions_path
(
"en"
)
assert_equal
'/admin/descriptions'
,
admin_descriptions_path
(
nil
)
assert_equal
'/admin/en/descriptions/1'
,
admin_description_path
(
"en"
,
1
)
assert_equal
'/admin/descriptions/1'
,
admin_description_path
(
nil
,
1
)
get
'/admin/en/descriptions'
assert_equal
'admin/descriptions#index'
,
@response
.
body
get
'/admin/descriptions'
assert_equal
'admin/descriptions#index'
,
@response
.
body
get
'/admin/en/descriptions/1'
assert_equal
'admin/descriptions#show'
,
@response
.
body
get
'/admin/descriptions/1'
assert_equal
'admin/descriptions#show'
,
@response
.
body
end
end
private
private
def
with_test_routes
def
with_test_routes
real_routes
,
temp_routes
=
ActionController
::
Routing
::
Routes
,
Routes
real_routes
,
temp_routes
=
ActionController
::
Routing
::
Routes
,
Routes
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录