Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
98b83095
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,发现更多精彩内容 >>
未验证
提交
98b83095
编写于
5月 23, 2016
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove deprecated support to non-keyword arguments #process
上级
31639eab
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
21 addition
and
181 deletion
+21
-181
actionpack/CHANGELOG.md
actionpack/CHANGELOG.md
+5
-0
actionpack/lib/action_controller/test_case.rb
actionpack/lib/action_controller/test_case.rb
+16
-70
actionpack/test/controller/test_case_test.rb
actionpack/test/controller/test_case_test.rb
+0
-111
未找到文件。
actionpack/CHANGELOG.md
浏览文件 @
98b83095
*
Remove deprecated support to non-keyword arguments in
`ActionController::TestCase#process`
,
`#get`
,
`#post`
,
`#patch`
,
`#put`
,
`#delete`
, and
`#head`
.
*Rafael Mendonça França*
*
Remove deprecated
`xml_http_request`
and
`xhr`
methods in
`ActionController::TestCase`
.
*Rafael Mendonça França*
...
...
actionpack/lib/action_controller/test_case.rb
浏览文件 @
98b83095
...
...
@@ -386,40 +386,40 @@ def determine_default_controller_class(name)
#
# Note that the request method is not verified. The different methods are
# available to make the tests more expressive.
def
get
(
action
,
*
args
)
res
=
process
_with_kwargs
(
"GET"
,
action
,
*
args
)
def
get
(
action
,
*
*
args
)
res
=
process
(
action
,
method:
"GET"
,
*
*
args
)
cookies
.
update
res
.
cookies
res
end
# Simulate a POST request with the given parameters and set/volley the response.
# See +get+ for more details.
def
post
(
action
,
*
args
)
process
_with_kwargs
(
"POST"
,
action
,
*
args
)
def
post
(
action
,
*
*
args
)
process
(
action
,
method:
"POST"
,
*
*
args
)
end
# Simulate a PATCH request with the given parameters and set/volley the response.
# See +get+ for more details.
def
patch
(
action
,
*
args
)
process
_with_kwargs
(
"PATCH"
,
action
,
*
args
)
def
patch
(
action
,
*
*
args
)
process
(
action
,
method:
"PATCH"
,
*
*
args
)
end
# Simulate a PUT request with the given parameters and set/volley the response.
# See +get+ for more details.
def
put
(
action
,
*
args
)
process
_with_kwargs
(
"PUT"
,
action
,
*
args
)
def
put
(
action
,
*
*
args
)
process
(
action
,
method:
"PUT"
,
*
*
args
)
end
# Simulate a DELETE request with the given parameters and set/volley the response.
# See +get+ for more details.
def
delete
(
action
,
*
args
)
process
_with_kwargs
(
"DELETE"
,
action
,
*
args
)
def
delete
(
action
,
*
*
args
)
process
(
action
,
method:
"DELETE"
,
*
*
args
)
end
# Simulate a HEAD request with the given parameters and set/volley the response.
# See +get+ for more details.
def
head
(
action
,
*
args
)
process
_with_kwargs
(
"HEAD"
,
action
,
*
args
)
def
head
(
action
,
*
*
args
)
process
(
action
,
method:
"HEAD"
,
*
*
args
)
end
# Simulate an HTTP request to +action+ by specifying request method,
...
...
@@ -452,36 +452,14 @@ def head(action, *args)
# respectively which will make tests more expressive.
#
# Note that the request method is not verified.
def
process
(
action
,
*
args
)
def
process
(
action
,
method:
"GET"
,
params:
{},
session:
nil
,
body:
nil
,
flash:
{},
format:
nil
,
xhr:
false
,
as:
nil
)
check_required_ivars
if
kwarg_request?
(
args
)
parameters
,
session
,
body
,
flash
,
http_method
,
format
,
xhr
,
as
=
args
[
0
].
values_at
(
:params
,
:session
,
:body
,
:flash
,
:method
,
:format
,
:xhr
,
:as
)
else
http_method
,
parameters
,
session
,
flash
=
args
format
=
nil
if
parameters
.
is_a?
(
String
)
&&
http_method
!=
"HEAD"
body
=
parameters
parameters
=
nil
end
if
parameters
||
session
||
flash
non_kwarg_request_warning
end
end
if
body
@request
.
set_header
"RAW_POST_DATA"
,
body
end
if
http_method
http_method
=
http_method
.
to_s
.
upcase
else
http_method
=
"GET"
end
parameters
||=
{}
http_method
=
method
.
to_s
.
upcase
@html_document
=
nil
...
...
@@ -502,12 +480,12 @@ def process(action, *args)
format
||=
as
end
parameters
=
params
.
symbolize_keys
if
format
parameters
[
:format
]
=
format
end
parameters
=
parameters
.
symbolize_keys
generated_extras
=
@routes
.
generate_extras
(
parameters
.
merge
(
controller:
controller_class_name
,
action:
action
.
to_s
))
generated_path
=
generated_path
(
generated_extras
)
query_string_keys
=
query_parameter_names
(
generated_extras
)
...
...
@@ -626,38 +604,6 @@ def scrub_env!(env)
env
end
def
process_with_kwargs
(
http_method
,
action
,
*
args
)
if
kwarg_request?
(
args
)
args
.
first
.
merge!
(
method:
http_method
)
process
(
action
,
*
args
)
else
non_kwarg_request_warning
if
args
.
any?
args
=
args
.
unshift
(
http_method
)
process
(
action
,
*
args
)
end
end
REQUEST_KWARGS
=
%i(params session flash method body xhr)
def
kwarg_request?
(
args
)
args
[
0
].
respond_to?
(
:keys
)
&&
(
(
args
[
0
].
key?
(
:format
)
&&
args
[
0
].
keys
.
size
==
1
)
||
args
[
0
].
keys
.
any?
{
|
k
|
REQUEST_KWARGS
.
include?
(
k
)
}
)
end
def
non_kwarg_request_warning
ActiveSupport
::
Deprecation
.
warn
(
<<-
MSG
.
strip_heredoc
)
ActionController::TestCase HTTP request methods will accept only
keyword arguments in future Rails versions.
Examples:
get :show, params: { id: 1 }, session: { user_id: 1 }
process :update, method: :post, params: { id: 1 }
MSG
end
def
document_root_element
html_document
.
root
end
...
...
actionpack/test/controller/test_case_test.rb
浏览文件 @
98b83095
...
...
@@ -229,14 +229,6 @@ def test_body_stream
assert_equal
params
.
to_query
,
@response
.
body
end
def
test_deprecated_body_stream
params
=
Hash
[
:page
,
{
name:
"page name"
},
"some key"
,
123
]
assert_deprecated
{
post
:render_body
,
params
.
dup
}
assert_equal
params
.
to_query
,
@response
.
body
end
def
test_document_body_and_params_with_post
post
:test_params
,
params:
{
id:
1
}
assert_equal
({
"id"
=>
"1"
,
"controller"
=>
"test_case_test/test"
,
"action"
=>
"test_params"
},
::
JSON
.
parse
(
@response
.
body
))
...
...
@@ -247,21 +239,11 @@ def test_document_body_with_post
assert_equal
"document body"
,
@response
.
body
end
def
test_deprecated_document_body_with_post
assert_deprecated
{
post
:render_body
,
"document body"
}
assert_equal
"document body"
,
@response
.
body
end
def
test_document_body_with_put
put
:render_body
,
body:
"document body"
assert_equal
"document body"
,
@response
.
body
end
def
test_deprecated_document_body_with_put
assert_deprecated
{
put
:render_body
,
"document body"
}
assert_equal
"document body"
,
@response
.
body
end
def
test_head
head
:test_params
assert_equal
200
,
@response
.
status
...
...
@@ -272,11 +254,6 @@ def test_process_without_flash
assert_equal
"><"
,
flash
[
"test"
]
end
def
test_deprecated_process_with_flash
assert_deprecated
{
process
:set_flash
,
"GET"
,
nil
,
nil
,
"test"
=>
"value"
}
assert_equal
">value<"
,
flash
[
"test"
]
end
def
test_process_with_flash
process
:set_flash
,
method:
"GET"
,
...
...
@@ -284,11 +261,6 @@ def test_process_with_flash
assert_equal
">value<"
,
flash
[
"test"
]
end
def
test_deprecated_process_with_flash_now
assert_deprecated
{
process
:set_flash_now
,
"GET"
,
nil
,
nil
,
"test_now"
=>
"value_now"
}
assert_equal
">value_now<"
,
flash
[
"test_now"
]
end
def
test_process_with_flash_now
process
:set_flash_now
,
method:
"GET"
,
...
...
@@ -311,14 +283,6 @@ def test_process_with_session
assert_equal
"it works"
,
session
[
:symbol
],
"Test session hash should allow indifferent access"
end
def
test_process_with_session_arg
assert_deprecated
{
process
:no_op
,
"GET"
,
nil
,
"string"
=>
"value1"
,
symbol:
"value2"
}
assert_equal
"value1"
,
session
[
"string"
]
assert_equal
"value1"
,
session
[
:string
]
assert_equal
"value2"
,
session
[
"symbol"
]
assert_equal
"value2"
,
session
[
:symbol
]
end
def
test_process_with_session_kwarg
process
:no_op
,
method:
"GET"
,
session:
{
"string"
=>
"value1"
,
symbol:
"value2"
}
assert_equal
"value1"
,
session
[
"string"
]
...
...
@@ -327,15 +291,6 @@ def test_process_with_session_kwarg
assert_equal
"value2"
,
session
[
:symbol
]
end
def
test_deprecated_process_merges_session_arg
session
[
:foo
]
=
"bar"
assert_deprecated
{
get
:no_op
,
nil
,
bar:
"baz"
}
assert_equal
"bar"
,
session
[
:foo
]
assert_equal
"baz"
,
session
[
:bar
]
end
def
test_process_merges_session_arg
session
[
:foo
]
=
"bar"
get
:no_op
,
session:
{
bar:
"baz"
}
...
...
@@ -343,15 +298,6 @@ def test_process_merges_session_arg
assert_equal
"baz"
,
session
[
:bar
]
end
def
test_deprecated_merged_session_arg_is_retained_across_requests
assert_deprecated
{
get
:no_op
,
nil
,
foo:
"bar"
}
assert_equal
"bar"
,
session
[
:foo
]
get
:no_op
assert_equal
"bar"
,
session
[
:foo
]
end
def
test_merged_session_arg_is_retained_across_requests
get
:no_op
,
session:
{
foo:
"bar"
}
assert_equal
"bar"
,
session
[
:foo
]
...
...
@@ -393,11 +339,6 @@ def test_process_with_symbol_method
assert_equal
"/test_case_test/test/test_uri"
,
@response
.
body
end
def
test_deprecated_process_with_request_uri_with_params
assert_deprecated
{
process
:test_uri
,
"GET"
,
id:
7
}
assert_equal
"/test_case_test/test/test_uri/7"
,
@response
.
body
end
def
test_process_with_request_uri_with_params
process
:test_uri
,
method:
"GET"
,
...
...
@@ -406,12 +347,6 @@ def test_process_with_request_uri_with_params
assert_equal
"/test_case_test/test/test_uri/7"
,
@response
.
body
end
def
test_deprecated_process_with_request_uri_with_params_with_explicit_uri
@request
.
env
[
"PATH_INFO"
]
=
"/explicit/uri"
assert_deprecated
{
process
:test_uri
,
"GET"
,
id:
7
}
assert_equal
"/explicit/uri"
,
@response
.
body
end
def
test_process_with_request_uri_with_params_with_explicit_uri
@request
.
env
[
"PATH_INFO"
]
=
"/explicit/uri"
process
:test_uri
,
method:
"GET"
,
params:
{
id:
7
}
...
...
@@ -491,20 +426,6 @@ def test_assert_routing_with_glob
end
end
def
test_deprecated_params_passing
assert_deprecated
{
get
:test_params
,
page:
{
name:
"Page name"
,
month:
"4"
,
year:
"2004"
,
day:
"6"
}
}
parsed_params
=
::
JSON
.
parse
(
@response
.
body
)
assert_equal
(
{
"controller"
=>
"test_case_test/test"
,
"action"
=>
"test_params"
,
"page"
=>
{
"name"
=>
"Page name"
,
"month"
=>
"4"
,
"year"
=>
"2004"
,
"day"
=>
"6"
}
},
parsed_params
)
end
def
test_params_passing
get
:test_params
,
params:
{
page:
{
...
...
@@ -589,16 +510,6 @@ def test_params_passing_path_parameter_is_string_when_not_html_request
)
end
def
test_deprecated_params_passing_path_parameter_is_string_when_not_html_request
assert_deprecated
{
get
:test_params
,
format:
"json"
,
id:
1
}
parsed_params
=
::
JSON
.
parse
(
@response
.
body
)
assert_equal
(
{
"controller"
=>
"test_case_test/test"
,
"action"
=>
"test_params"
,
"format"
=>
"json"
,
"id"
=>
"1"
},
parsed_params
)
end
def
test_params_passing_with_frozen_values
assert_nothing_raised
do
get
:test_params
,
params:
{
...
...
@@ -683,11 +594,6 @@ def test_id_converted_to_string
assert_kind_of
String
,
@request
.
path_parameters
[
:id
]
end
def
test_deprecared_id_converted_to_string
assert_deprecated
{
get
:test_params
,
id:
20
,
foo:
Object
.
new
}
assert_kind_of
String
,
@request
.
path_parameters
[
:id
]
end
def
test_array_path_parameter_handled_properly
with_routing
do
|
set
|
set
.
draw
do
...
...
@@ -757,14 +663,6 @@ def test_xhr_with_session
assert_equal
"it works"
,
session
[
:symbol
],
"Test session hash should allow indifferent access"
end
def
test_deprecated_params_reset_between_post_requests
assert_deprecated
{
post
:no_op
,
foo:
"bar"
}
assert_equal
"bar"
,
@request
.
params
[
:foo
]
post
:no_op
assert
@request
.
params
[
:foo
].
blank?
end
def
test_params_reset_between_post_requests
post
:no_op
,
params:
{
foo:
"bar"
}
assert_equal
"bar"
,
@request
.
params
[
:foo
]
...
...
@@ -964,15 +862,6 @@ def test_fixture_file_upload_ignores_nil_fixture_path
assert_equal
File
.
open
(
"
#{
FILES_DIR
}
/mona_lisa.jpg"
,
READ_PLAIN
).
read
,
uploaded_file
.
read
end
def
test_deprecated_action_dispatch_uploaded_file_upload
filename
=
"mona_lisa.jpg"
path
=
"
#{
FILES_DIR
}
/
#{
filename
}
"
assert_deprecated
{
post
:test_file_upload
,
file:
Rack
::
Test
::
UploadedFile
.
new
(
path
,
"image/jpg"
,
true
)
}
assert_equal
"159528"
,
@response
.
body
end
def
test_action_dispatch_uploaded_file_upload
filename
=
"mona_lisa.jpg"
path
=
"
#{
FILES_DIR
}
/
#{
filename
}
"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录