Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
9b4514c3
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,发现更多精彩内容 >>
提交
9b4514c3
编写于
5月 11, 2012
作者:
A
Andrew White
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Copy literal route constraints to defaults - fixes #3571 and #6224.
上级
0d48b12f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
69 addition
and
3 deletion
+69
-3
actionpack/CHANGELOG.md
actionpack/CHANGELOG.md
+5
-0
actionpack/lib/action_dispatch/routing/mapper.rb
actionpack/lib/action_dispatch/routing/mapper.rb
+19
-0
actionpack/test/dispatch/routing_assertions_test.rb
actionpack/test/dispatch/routing_assertions_test.rb
+3
-3
actionpack/test/dispatch/routing_test.rb
actionpack/test/dispatch/routing_test.rb
+42
-0
未找到文件。
actionpack/CHANGELOG.md
浏览文件 @
9b4514c3
## Rails 4.0.0 (unreleased) ##
*
Copy literal route constraints to defaults so that url generation know about them.
The copied constraints are
`:protocol`
,
`:subdomain`
,
`:domain`
,
`:host`
and
`:port`
.
*Andrew White*
*
`respond_to`
and
`respond_with`
now raise ActionController::UnknownFormat instead
of directly returning head 406. The exception is rescued and converted to 406
in the exception handling middleware.
*Steven Soroka*
...
...
actionpack/lib/action_dispatch/routing/mapper.rb
浏览文件 @
9b4514c3
require
'active_support/core_ext/hash/except'
require
'active_support/core_ext/hash/reverse_merge'
require
'active_support/core_ext/hash/slice'
require
'active_support/core_ext/object/blank'
require
'active_support/core_ext/enumerable'
require
'active_support/inflector'
...
...
@@ -100,6 +101,10 @@ def normalize_options!
raise
ArgumentError
,
"Regexp multiline option not allowed in routing requirements:
#{
requirement
.
inspect
}
"
end
end
if
@options
[
:constraints
].
is_a?
(
Hash
)
(
@options
[
:defaults
]
||=
{}).
reverse_merge!
(
defaults_from_constraints
(
@options
[
:constraints
]))
end
end
# match "account/overview"
...
...
@@ -245,6 +250,11 @@ def default_controller
def
default_action
@options
[
:action
]
||
@scope
[
:action
]
end
def
defaults_from_constraints
(
constraints
)
url_keys
=
[
:protocol
,
:subdomain
,
:domain
,
:host
,
:port
]
constraints
.
slice
(
*
url_keys
).
select
{
|
k
,
v
|
v
.
is_a?
(
String
)
||
v
.
is_a?
(
Fixnum
)
}
end
end
# Invokes Rack::Mount::Utils.normalize path and ensure that
...
...
@@ -641,6 +651,10 @@ def scope(*args)
block
,
options
[
:constraints
]
=
options
[
:constraints
],
{}
end
if
options
[
:constraints
].
is_a?
(
Hash
)
(
options
[
:defaults
]
||=
{}).
reverse_merge!
(
defaults_from_constraints
(
options
[
:constraints
]))
end
scope_options
.
each
do
|
option
|
if
value
=
options
.
delete
(
option
)
recover
[
option
]
=
@scope
[
option
]
...
...
@@ -849,6 +863,11 @@ def merge_shallow_scope(parent, child) #:nodoc:
def
override_keys
(
child
)
#:nodoc:
child
.
key?
(
:only
)
||
child
.
key?
(
:except
)
?
[
:only
,
:except
]
:
[]
end
def
defaults_from_constraints
(
constraints
)
url_keys
=
[
:protocol
,
:subdomain
,
:domain
,
:host
,
:port
]
constraints
.
slice
(
*
url_keys
).
select
{
|
k
,
v
|
v
.
is_a?
(
String
)
||
v
.
is_a?
(
Fixnum
)
}
end
end
# Resource routing allows you to quickly declare all of the common routes
...
...
actionpack/test/dispatch/routing_assertions_test.rb
浏览文件 @
9b4514c3
...
...
@@ -47,7 +47,7 @@ def test_assert_recognizes
def
test_assert_recognizes_with_extras
assert_recognizes
({
:controller
=>
'articles'
,
:action
=>
'index'
,
:page
=>
'1'
},
'/articles'
,
{
:page
=>
'1'
})
end
def
test_assert_recognizes_with_method
assert_recognizes
({
:controller
=>
'articles'
,
:action
=>
'create'
},
{
:path
=>
'/articles'
,
:method
=>
:post
})
assert_recognizes
({
:controller
=>
'articles'
,
:action
=>
'update'
,
:id
=>
'1'
},
{
:path
=>
'/articles/1'
,
:method
=>
:put
})
...
...
@@ -57,7 +57,7 @@ def test_assert_recognizes_with_hash_constraint
assert_raise
(
ActionController
::
RoutingError
)
do
assert_recognizes
({
:controller
=>
'secure_articles'
,
:action
=>
'index'
},
'http://test.host/secure/articles'
)
end
assert_recognizes
({
:controller
=>
'secure_articles'
,
:action
=>
'index'
},
'https://test.host/secure/articles'
)
assert_recognizes
({
:controller
=>
'secure_articles'
,
:action
=>
'index'
,
:protocol
=>
'https://'
},
'https://test.host/secure/articles'
)
end
def
test_assert_recognizes_with_block_constraint
...
...
@@ -90,7 +90,7 @@ def test_assert_routing_with_hash_constraint
assert_raise
(
ActionController
::
RoutingError
)
do
assert_routing
(
'http://test.host/secure/articles'
,
{
:controller
=>
'secure_articles'
,
:action
=>
'index'
})
end
assert_routing
(
'https://test.host/secure/articles'
,
{
:controller
=>
'secure_articles'
,
:action
=>
'index'
})
assert_routing
(
'https://test.host/secure/articles'
,
{
:controller
=>
'secure_articles'
,
:action
=>
'index'
,
:protocol
=>
'https://'
})
end
def
test_assert_routing_with_block_constraint
...
...
actionpack/test/dispatch/routing_test.rb
浏览文件 @
9b4514c3
...
...
@@ -2606,3 +2606,45 @@ def app; Routes end
assert_raises
(
ActionController
::
RoutingError
)
{
product_path
(
nil
)
}
end
end
class
TestUrlConstraints
<
ActionDispatch
::
IntegrationTest
Routes
=
ActionDispatch
::
Routing
::
RouteSet
.
new
.
tap
do
|
app
|
app
.
draw
do
ok
=
lambda
{
|
env
|
[
200
,
{
'Content-Type'
=>
'text/plain'
},
[]]
}
constraints
:subdomain
=>
'admin'
do
get
'/'
=>
ok
,
:as
=>
:admin_root
end
scope
:constraints
=>
{
:protocol
=>
'https://'
}
do
get
'/'
=>
ok
,
:as
=>
:secure_root
end
get
'/'
=>
ok
,
:as
=>
:alternate_root
,
:constraints
=>
{
:port
=>
8080
}
end
end
include
Routes
.
url_helpers
def
app
;
Routes
end
test
"constraints are copied to defaults when using constraints method"
do
assert_equal
'http://admin.example.com/'
,
admin_root_url
get
'http://admin.example.com/'
assert_response
:success
end
test
"constraints are copied to defaults when using scope constraints hash"
do
assert_equal
'https://www.example.com/'
,
secure_root_url
get
'https://www.example.com/'
assert_response
:success
end
test
"constraints are copied to defaults when using route constraints hash"
do
assert_equal
'http://www.example.com:8080/'
,
alternate_root_url
get
'http://www.example.com:8080/'
assert_response
:success
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录