Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
46ea7698
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,体验更适合开发者的 AI 搜索 >>
提交
46ea7698
编写于
9月 16, 2020
作者:
A
Akira Matsuda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
URL helper methods on controllers are public methods
上级
666897a0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
61 addition
and
64 deletion
+61
-64
actionpack/test/controller/base_test.rb
actionpack/test/controller/base_test.rb
+13
-13
actionpack/test/controller/routing_test.rb
actionpack/test/controller/routing_test.rb
+43
-46
actionpack/test/controller/url_for_test.rb
actionpack/test/controller/url_for_test.rb
+5
-5
未找到文件。
actionpack/test/controller/base_test.rb
浏览文件 @
46ea7698
...
...
@@ -226,7 +226,7 @@ def test_url_options_override
get
:from_view
,
params:
{
route:
"from_view_url"
}
assert_equal
"http://www.override.com/from_view"
,
@response
.
body
assert_equal
"http://www.override.com/from_view"
,
@controller
.
send
(
:from_view_url
)
assert_equal
"http://www.override.com/from_view"
,
@controller
.
from_view_url
assert_equal
"http://www.override.com/default_url_options/index"
,
@controller
.
url_for
(
controller:
"default_url_options"
)
end
end
...
...
@@ -263,7 +263,7 @@ def test_default_url_options_override
get
:from_view
,
params:
{
route:
"from_view_url"
}
assert_equal
"http://www.override.com/from_view?locale=en"
,
@response
.
body
assert_equal
"http://www.override.com/from_view?locale=en"
,
@controller
.
send
(
:from_view_url
)
assert_equal
"http://www.override.com/from_view?locale=en"
,
@controller
.
from_view_url
assert_equal
"http://www.override.com/default_url_options/new?locale=en"
,
@controller
.
url_for
(
controller:
"default_url_options"
)
end
end
...
...
@@ -283,16 +283,16 @@ def test_default_url_options_are_used_in_non_positional_parameters
get
:from_view
,
params:
{
route:
"description_path(1)"
}
assert_equal
"/en/descriptions/1"
,
@response
.
body
assert_equal
"/en/descriptions"
,
@controller
.
send
(
:descriptions_path
)
assert_equal
"/pl/descriptions"
,
@controller
.
send
(
:descriptions_path
,
"pl"
)
assert_equal
"/pl/descriptions"
,
@controller
.
send
(
:descriptions_path
,
locale:
"pl"
)
assert_equal
"/pl/descriptions.xml"
,
@controller
.
send
(
:descriptions_path
,
"pl"
,
"xml"
)
assert_equal
"/en/descriptions.xml"
,
@controller
.
send
(
:descriptions_path
,
format:
"xml"
)
assert_equal
"/en/descriptions/1"
,
@controller
.
send
(
:description_path
,
1
)
assert_equal
"/pl/descriptions/1"
,
@controller
.
send
(
:description_path
,
"pl"
,
1
)
assert_equal
"/pl/descriptions/1"
,
@controller
.
send
(
:description_path
,
1
,
locale:
"pl"
)
assert_equal
"/pl/descriptions/1.xml"
,
@controller
.
send
(
:description_path
,
"pl"
,
1
,
"xml"
)
assert_equal
"/en/descriptions/1.xml"
,
@controller
.
send
(
:description_path
,
1
,
format:
"xml"
)
assert_equal
"/en/descriptions"
,
@controller
.
descriptions_path
assert_equal
"/pl/descriptions"
,
@controller
.
descriptions_path
(
"pl"
)
assert_equal
"/pl/descriptions"
,
@controller
.
descriptions_path
(
locale:
"pl"
)
assert_equal
"/pl/descriptions.xml"
,
@controller
.
descriptions_path
(
"pl"
,
"xml"
)
assert_equal
"/en/descriptions.xml"
,
@controller
.
descriptions_path
(
format:
"xml"
)
assert_equal
"/en/descriptions/1"
,
@controller
.
description_path
(
1
)
assert_equal
"/pl/descriptions/1"
,
@controller
.
description_path
(
"pl"
,
1
)
assert_equal
"/pl/descriptions/1"
,
@controller
.
description_path
(
1
,
locale:
"pl"
)
assert_equal
"/pl/descriptions/1.xml"
,
@controller
.
description_path
(
"pl"
,
1
,
"xml"
)
assert_equal
"/en/descriptions/1.xml"
,
@controller
.
description_path
(
1
,
format:
"xml"
)
end
end
end
...
...
@@ -331,7 +331,7 @@ def test_named_routes_with_path_without_doing_a_request_first
resources
:things
end
assert_equal
"/things"
,
@controller
.
send
(
:things_path
)
assert_equal
"/things"
,
@controller
.
things_path
end
end
end
actionpack/test/controller/routing_test.rb
浏览文件 @
46ea7698
...
...
@@ -418,7 +418,7 @@ def test_basic_named_route
rs
.
draw
do
root
to:
"content#list"
,
as:
"home"
end
assert_equal
(
"http://test.host/"
,
setup_for_named_route
.
send
(
:home_url
)
)
assert_equal
(
"http://test.host/"
,
setup_for_named_route
.
home_url
)
end
def
test_named_route_with_option
...
...
@@ -427,7 +427,7 @@ def test_named_route_with_option
end
assert_equal
(
"http://test.host/page/new%20stuff"
,
setup_for_named_route
.
send
(
:page_url
,
title:
"new stuff"
))
setup_for_named_route
.
page_url
(
title:
"new stuff"
))
end
def
test_named_route_with_default
...
...
@@ -436,7 +436,7 @@ def test_named_route_with_default
end
assert_equal
(
"http://test.host/page/AboutRails"
,
setup_for_named_route
.
send
(
:page_url
,
title:
"AboutRails"
))
setup_for_named_route
.
page_url
(
title:
"AboutRails"
))
end
def
test_named_route_with_path_prefix
...
...
@@ -446,8 +446,7 @@ def test_named_route_with_path_prefix
end
end
assert_equal
(
"http://test.host/my/page"
,
setup_for_named_route
.
send
(
:page_url
))
assert_equal
(
"http://test.host/my/page"
,
setup_for_named_route
.
page_url
)
end
def
test_named_route_with_blank_path_prefix
...
...
@@ -457,8 +456,7 @@ def test_named_route_with_blank_path_prefix
end
end
assert_equal
(
"http://test.host/page"
,
setup_for_named_route
.
send
(
:page_url
))
assert_equal
(
"http://test.host/page"
,
setup_for_named_route
.
page_url
)
end
def
test_named_route_with_nested_controller
...
...
@@ -466,8 +464,7 @@ def test_named_route_with_nested_controller
get
"admin/user"
=>
"admin/user#index"
,
:as
=>
"users"
end
assert_equal
(
"http://test.host/admin/user"
,
setup_for_named_route
.
send
(
:users_url
))
assert_equal
(
"http://test.host/admin/user"
,
setup_for_named_route
.
users_url
)
end
def
test_optimised_named_route_with_host
...
...
@@ -495,8 +492,8 @@ def test_named_route_root
root
to:
"hello#index"
end
routes
=
setup_for_named_route
assert_equal
(
"http://test.host/"
,
routes
.
send
(
:root_url
)
)
assert_equal
(
"/"
,
routes
.
send
(
:root_path
)
)
assert_equal
(
"http://test.host/"
,
routes
.
root_url
)
assert_equal
(
"/"
,
routes
.
root_path
)
end
def
test_named_route_root_without_hash
...
...
@@ -504,8 +501,8 @@ def test_named_route_root_without_hash
root
"hello#index"
end
routes
=
setup_for_named_route
assert_equal
(
"http://test.host/"
,
routes
.
send
(
:root_url
)
)
assert_equal
(
"/"
,
routes
.
send
(
:root_path
)
)
assert_equal
(
"http://test.host/"
,
routes
.
root_url
)
assert_equal
(
"/"
,
routes
.
root_path
)
end
def
test_named_route_root_with_hash
...
...
@@ -514,8 +511,8 @@ def test_named_route_root_with_hash
end
routes
=
setup_for_named_route
assert_equal
(
"http://test.host/"
,
routes
.
send
(
:index_url
)
)
assert_equal
(
"/"
,
routes
.
send
(
:index_path
)
)
assert_equal
(
"http://test.host/"
,
routes
.
index_url
)
assert_equal
(
"/"
,
routes
.
index_path
)
end
def
test_root_without_path_raises_argument_error
...
...
@@ -530,8 +527,8 @@ def test_named_route_root_with_trailing_slash
end
routes
=
setup_for_named_route
(
trailing_slash:
true
)
assert_equal
(
"http://test.host/"
,
routes
.
send
(
:root_url
)
)
assert_equal
(
"http://test.host/?foo=bar"
,
routes
.
send
(
:root_url
,
foo: :bar
))
assert_equal
(
"http://test.host/"
,
routes
.
root_url
)
assert_equal
(
"http://test.host/?foo=bar"
,
routes
.
root_url
(
foo: :bar
))
end
def
test_named_route_with_regexps
...
...
@@ -547,7 +544,7 @@ def test_named_route_with_regexps
routes
=
setup_for_named_route
assert_equal
"http://test.host/page/2005/6/10/hi"
,
routes
.
send
(
:article_url
,
title:
"hi"
,
day:
10
,
year:
2005
,
month:
6
)
routes
.
article_url
(
title:
"hi"
,
day:
10
,
year:
2005
,
month:
6
)
end
def
test_changing_controller
...
...
@@ -585,7 +582,7 @@ def test_paths_slashes_unescaped_with_ordered_parameters
end
# No / to %2F in URI, only for query params.
assert_equal
(
"/file/hello/world"
,
setup_for_named_route
.
send
(
:path_path
,
[
"hello"
,
"world"
]))
assert_equal
(
"/file/hello/world"
,
setup_for_named_route
.
path_path
(
[
"hello"
,
"world"
]))
end
def
test_non_controllers_cannot_be_matched
...
...
@@ -715,7 +712,7 @@ def test_both_requirement_and_optional
assert_equal
"/test"
,
url_for
(
rs
,
controller:
"post"
,
action:
"show"
)
assert_equal
"/test"
,
url_for
(
rs
,
controller:
"post"
,
action:
"show"
,
year:
nil
)
assert_equal
(
"http://test.host/test"
,
setup_for_named_route
.
send
(
:blog_url
)
)
assert_equal
(
"http://test.host/test"
,
setup_for_named_route
.
blog_url
)
end
def
test_set_to_nil_forgets
...
...
@@ -765,7 +762,7 @@ def test_named_root_url_generation_with_controller_and_action
assert_equal
"/"
,
url_for
(
rs
,
controller:
"content"
,
action:
"index"
)
assert_equal
"/"
,
url_for
(
rs
,
controller:
"content"
)
assert_equal
(
"http://test.host/"
,
setup_for_named_route
.
send
(
:home_url
)
)
assert_equal
(
"http://test.host/"
,
setup_for_named_route
.
home_url
)
end
def
test_named_route_method
...
...
@@ -877,7 +874,7 @@ def test_failed_constraints_raises_exception_with_violated_constraints
end
assert_raise
(
ActionController
::
UrlGenerationError
)
do
setup_for_named_route
.
send
(
:foo_with_requirement_url
,
"I am Against the constraints"
)
setup_for_named_route
.
foo_with_requirement_url
(
"I am Against the constraints"
)
end
end
...
...
@@ -1042,78 +1039,78 @@ def setup_named_route_test
def
test_named_route_url_method
controller
=
setup_named_route_test
assert_equal
"http://test.host/people/5"
,
controller
.
s
end
(
:show_url
,
id:
5
)
assert_equal
"/people/5"
,
controller
.
s
end
(
:show_path
,
id:
5
)
assert_equal
"http://test.host/people/5"
,
controller
.
s
how_url
(
id:
5
)
assert_equal
"/people/5"
,
controller
.
s
how_path
(
id:
5
)
assert_equal
"http://test.host/people"
,
controller
.
send
(
:index_url
)
assert_equal
"/people"
,
controller
.
send
(
:index_path
)
assert_equal
"http://test.host/people"
,
controller
.
index_url
assert_equal
"/people"
,
controller
.
index_path
assert_equal
"http://test.host/admin/users"
,
controller
.
send
(
:users_url
)
assert_equal
"/admin/users"
,
controller
.
send
(
:users_path
)
assert_equal
"http://test.host/admin/users"
,
controller
.
users_url
assert_equal
"/admin/users"
,
controller
.
users_path
end
def
test_named_route_url_method_with_anchor
controller
=
setup_named_route_test
assert_equal
"http://test.host/people/5#location"
,
controller
.
s
end
(
:show_url
,
id:
5
,
anchor:
"location"
)
assert_equal
"/people/5#location"
,
controller
.
s
end
(
:show_path
,
id:
5
,
anchor:
"location"
)
assert_equal
"http://test.host/people/5#location"
,
controller
.
s
how_url
(
id:
5
,
anchor:
"location"
)
assert_equal
"/people/5#location"
,
controller
.
s
how_path
(
id:
5
,
anchor:
"location"
)
assert_equal
"http://test.host/people#location"
,
controller
.
send
(
:index_url
,
anchor:
"location"
)
assert_equal
"/people#location"
,
controller
.
send
(
:index_path
,
anchor:
"location"
)
assert_equal
"http://test.host/people#location"
,
controller
.
index_url
(
anchor:
"location"
)
assert_equal
"/people#location"
,
controller
.
index_path
(
anchor:
"location"
)
assert_equal
"http://test.host/admin/users#location"
,
controller
.
send
(
:users_url
,
anchor:
"location"
)
assert_equal
"/admin/users#location"
,
controller
.
send
(
:users_path
,
anchor:
"location"
)
assert_equal
"http://test.host/admin/users#location"
,
controller
.
users_url
(
anchor:
"location"
)
assert_equal
"/admin/users#location"
,
controller
.
users_path
(
anchor:
"location"
)
assert_equal
"http://test.host/people/go/7/hello/joe/5#location"
,
controller
.
send
(
:multi_url
,
7
,
"hello"
,
5
,
anchor:
"location"
)
controller
.
multi_url
(
7
,
"hello"
,
5
,
anchor:
"location"
)
assert_equal
"http://test.host/people/go/7/hello/joe/5?baz=bar#location"
,
controller
.
send
(
:multi_url
,
7
,
"hello"
,
5
,
baz:
"bar"
,
anchor:
"location"
)
controller
.
multi_url
(
7
,
"hello"
,
5
,
baz:
"bar"
,
anchor:
"location"
)
assert_equal
"http://test.host/people?baz=bar#location"
,
controller
.
send
(
:index_url
,
baz:
"bar"
,
anchor:
"location"
)
controller
.
index_url
(
baz:
"bar"
,
anchor:
"location"
)
assert_equal
"http://test.host/people"
,
controller
.
send
(
:index_url
,
anchor:
nil
)
assert_equal
"http://test.host/people"
,
controller
.
send
(
:index_url
,
anchor:
false
)
assert_equal
"http://test.host/people"
,
controller
.
index_url
(
anchor:
nil
)
assert_equal
"http://test.host/people"
,
controller
.
index_url
(
anchor:
false
)
end
def
test_named_route_url_method_with_port
controller
=
setup_named_route_test
assert_equal
"http://test.host:8080/people/5"
,
controller
.
s
end
(
:show_url
,
5
,
port:
8080
)
assert_equal
"http://test.host:8080/people/5"
,
controller
.
s
how_url
(
5
,
port:
8080
)
end
def
test_named_route_url_method_with_host
controller
=
setup_named_route_test
assert_equal
"http://some.example.com/people/5"
,
controller
.
s
end
(
:show_url
,
5
,
host:
"some.example.com"
)
assert_equal
"http://some.example.com/people/5"
,
controller
.
s
how_url
(
5
,
host:
"some.example.com"
)
end
def
test_named_route_url_method_with_protocol
controller
=
setup_named_route_test
assert_equal
"https://test.host/people/5"
,
controller
.
s
end
(
:show_url
,
5
,
protocol:
"https"
)
assert_equal
"https://test.host/people/5"
,
controller
.
s
how_url
(
5
,
protocol:
"https"
)
end
def
test_named_route_url_method_with_ordered_parameters
controller
=
setup_named_route_test
assert_equal
"http://test.host/people/go/7/hello/joe/5"
,
controller
.
send
(
:multi_url
,
7
,
"hello"
,
5
)
controller
.
multi_url
(
7
,
"hello"
,
5
)
end
def
test_named_route_url_method_with_ordered_parameters_and_hash
controller
=
setup_named_route_test
assert_equal
"http://test.host/people/go/7/hello/joe/5?baz=bar"
,
controller
.
send
(
:multi_url
,
7
,
"hello"
,
5
,
baz:
"bar"
)
controller
.
multi_url
(
7
,
"hello"
,
5
,
baz:
"bar"
)
end
def
test_named_route_url_method_with_ordered_parameters_and_empty_hash
controller
=
setup_named_route_test
assert_equal
"http://test.host/people/go/7/hello/joe/5"
,
controller
.
send
(
:multi_url
,
7
,
"hello"
,
5
,
{})
controller
.
multi_url
(
7
,
"hello"
,
5
,
{})
end
def
test_named_route_url_method_with_no_positional_arguments
controller
=
setup_named_route_test
assert_equal
"http://test.host/people?baz=bar"
,
controller
.
send
(
:index_url
,
baz:
"bar"
)
controller
.
index_url
(
baz:
"bar"
)
end
def
test_draw_default_route
...
...
actionpack/test/controller/url_for_test.rb
浏览文件 @
46ea7698
...
...
@@ -290,11 +290,11 @@ def test_named_routes
controller
=
kls
.
new
assert_respond_to
controller
,
:home_url
assert_equal
"http://www.basecamphq.com/home/sweet/home/again"
,
controller
.
send
(
:home_url
,
host:
"www.basecamphq.com"
,
user:
"again"
)
controller
.
home_url
(
host:
"www.basecamphq.com"
,
user:
"again"
)
assert_equal
(
"/home/sweet/home/alabama"
,
controller
.
send
(
:home_path
,
user:
"alabama"
,
host:
"unused"
))
assert_equal
(
"http://www.basecamphq.com/home/sweet/home/alabama"
,
controller
.
send
(
:home_url
,
user:
"alabama"
,
host:
"www.basecamphq.com"
))
assert_equal
(
"http://www.basecamphq.com/this/is/verbose"
,
controller
.
send
(
:no_args_url
,
host:
"www.basecamphq.com"
))
assert_equal
(
"/home/sweet/home/alabama"
,
controller
.
home_path
(
user:
"alabama"
,
host:
"unused"
))
assert_equal
(
"http://www.basecamphq.com/home/sweet/home/alabama"
,
controller
.
home_url
(
user:
"alabama"
,
host:
"www.basecamphq.com"
))
assert_equal
(
"http://www.basecamphq.com/this/is/verbose"
,
controller
.
no_args_url
(
host:
"www.basecamphq.com"
))
end
end
...
...
@@ -308,7 +308,7 @@ def test_relative_url_root_is_respected_for_named_routes
controller
=
kls
.
new
assert_equal
"http://www.basecamphq.com/subdir/home/sweet/home/again"
,
controller
.
send
(
:home_url
,
host:
"www.basecamphq.com"
,
user:
"again"
,
script_name:
"/subdir"
)
controller
.
home_url
(
host:
"www.basecamphq.com"
,
user:
"again"
,
script_name:
"/subdir"
)
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录