Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
eb0e8e21
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,发现更多精彩内容 >>
提交
eb0e8e21
编写于
12月 11, 2015
作者:
A
Arthur Nogueira Neves
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #22511 from jonatack/redirect-to-302
Show redirect response code in assert_response messages
上级
a42770cd
c6fe614e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
17 deletion
+36
-17
actionpack/lib/action_dispatch/testing/assertions/response.rb
...onpack/lib/action_dispatch/testing/assertions/response.rb
+8
-10
actionpack/test/assertions/response_assertions_test.rb
actionpack/test/assertions/response_assertions_test.rb
+28
-7
未找到文件。
actionpack/lib/action_dispatch/testing/assertions/response.rb
浏览文件 @
eb0e8e21
...
...
@@ -85,17 +85,15 @@ def normalize_argument_to_redirection(fragment)
end
end
def
generate_response_message
(
type
)
message
=
"Expected response to be a <
#{
type
}
>, but was"
if
@response
.
redirection?
redirect_is
=
normalize_argument_to_redirection
(
@response
.
location
)
message
<<
" a redirect to <
#{
redirect_is
}
>"
else
message
<<
" <
#{
@response
.
response_code
}
>"
end
def
generate_response_message
(
type
,
code
=
@response
.
response_code
)
"Expected response to be a <
#{
type
}
>, but was a <
#{
code
}
>"
.
concat
location_if_redirected
end
message
def
location_if_redirected
return
''
unless
@response
.
redirection?
&&
@response
.
location
.
present?
location
=
normalize_argument_to_redirection
(
@response
.
location
)
" redirect to <
#{
location
}
>"
end
end
end
...
...
actionpack/test/assertions/response_assertions_test.rb
浏览文件 @
eb0e8e21
...
...
@@ -64,14 +64,35 @@ def test_assert_response_sym_typo
}
end
def
test_message_when_response_is_redirect_but_asserted_for_status_other_than_redirect
@response
=
FakeResponse
.
new
:redirection
,
"http://test.host/posts/redirect/1"
error
=
assert_raises
(
Minitest
::
Assertion
)
do
assert_response
:success
end
def
test_error_message_shows_404_when_404_asserted_for_success
@response
=
ActionDispatch
::
Response
.
new
@response
.
status
=
404
error
=
assert_raises
(
Minitest
::
Assertion
)
{
assert_response
:success
}
expected
=
"Expected response to be a <success>, but was a <404>"
assert_match
expected
,
error
.
message
end
def
test_error_message_shows_302_redirect_when_302_asserted_for_success
@response
=
ActionDispatch
::
Response
.
new
@response
.
status
=
302
@response
.
location
=
'http://test.host/posts/redirect/1'
error
=
assert_raises
(
Minitest
::
Assertion
)
{
assert_response
:success
}
expected
=
"Expected response to be a <success>, but was a <302>"
\
" redirect to <http://test.host/posts/redirect/1>"
assert_match
expected
,
error
.
message
end
def
test_error_message_shows_302_redirect_when_302_asserted_for_301
@response
=
ActionDispatch
::
Response
.
new
@response
.
status
=
302
@response
.
location
=
'http://test.host/posts/redirect/2'
expected
=
"Expected response to be a <success>, but was a redirect to <http://test.host/posts/redirect/1>"
assert_equal
expected
,
error
.
message
error
=
assert_raises
(
Minitest
::
Assertion
)
{
assert_response
301
}
expected
=
"Expected response to be a <301>, but was a <302>"
\
" redirect to <http://test.host/posts/redirect/2>"
assert_match
expected
,
error
.
message
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录