Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
2ecfa817
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,发现更多精彩内容 >>
提交
2ecfa817
编写于
12月 02, 2009
作者:
J
José Valim
提交者:
Yehuda Katz
12月 07, 2009
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Responder redirects to resource if destroy fails.
Signed-off-by:
N
Yehuda Katz
<
wycats@Yehuda-Katz.local
>
上级
324fa688
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
41 addition
and
10 deletion
+41
-10
actionpack/lib/action_controller/metal/responder.rb
actionpack/lib/action_controller/metal/responder.rb
+7
-2
actionpack/test/controller/mime_responds_test.rb
actionpack/test/controller/mime_responds_test.rb
+34
-8
未找到文件。
actionpack/lib/action_controller/metal/responder.rb
浏览文件 @
2ecfa817
...
...
@@ -80,6 +80,11 @@ module ActionController #:nodoc:
class
Responder
attr_reader
:controller
,
:request
,
:format
,
:resource
,
:resources
,
:options
ACTIONS_FOR_VERBS
=
{
:post
=>
:new
,
:put
=>
:edit
}
def
initialize
(
controller
,
resources
,
options
=
{})
@controller
=
controller
@request
=
controller
.
request
...
...
@@ -138,7 +143,7 @@ def to_format
def
navigation_behavior
(
error
)
if
get?
raise
error
elsif
has_errors?
elsif
has_errors?
&&
default_action
render
:action
=>
default_action
else
redirect_to
resource_location
...
...
@@ -209,7 +214,7 @@ def has_errors?
# the verb is post.
#
def
default_action
@action
||
(
request
.
post?
?
:new
:
:edit
)
@action
||
=
ACTIONS_FOR_VERBS
[
request
.
method
]
end
end
end
actionpack/test/controller/mime_responds_test.rb
浏览文件 @
2ecfa817
...
...
@@ -599,14 +599,18 @@ def test_using_resource
end
end
def
test_using_resource_for_post_with_html
def
test_using_resource_for_post_with_html
_redirects_on_success
with_test_route_set
do
post
:using_resource
assert_equal
"text/html"
,
@response
.
content_type
assert_equal
302
,
@response
.
status
assert_equal
"http://www.example.com/customers/13"
,
@response
.
location
assert
@response
.
redirect?
end
end
def
test_using_resource_for_post_with_html_rerender_on_failure
with_test_route_set
do
errors
=
{
:name
=>
:invalid
}
Customer
.
any_instance
.
stubs
(
:errors
).
returns
(
errors
)
post
:using_resource
...
...
@@ -617,16 +621,20 @@ def test_using_resource_for_post_with_html
end
end
def
test_using_resource_for_post_with_xml
def
test_using_resource_for_post_with_xml
_yields_created_on_success
with_test_route_set
do
@request
.
accept
=
"application/xml"
post
:using_resource
assert_equal
"application/xml"
,
@response
.
content_type
assert_equal
201
,
@response
.
status
assert_equal
"<name>david</name>"
,
@response
.
body
assert_equal
"http://www.example.com/customers/13"
,
@response
.
location
end
end
def
test_using_resource_for_post_with_xml_yields_unprocessable_entity_on_failure
with_test_route_set
do
@request
.
accept
=
"application/xml"
errors
=
{
:name
=>
:invalid
}
Customer
.
any_instance
.
stubs
(
:errors
).
returns
(
errors
)
post
:using_resource
...
...
@@ -637,14 +645,18 @@ def test_using_resource_for_post_with_xml
end
end
def
test_using_resource_for_put_with_html
def
test_using_resource_for_put_with_html
_redirects_on_success
with_test_route_set
do
put
:using_resource
assert_equal
"text/html"
,
@response
.
content_type
assert_equal
302
,
@response
.
status
assert_equal
"http://www.example.com/customers/13"
,
@response
.
location
assert
@response
.
redirect?
end
end
def
test_using_resource_for_put_with_html_rerender_on_failure
with_test_route_set
do
errors
=
{
:name
=>
:invalid
}
Customer
.
any_instance
.
stubs
(
:errors
).
returns
(
errors
)
put
:using_resource
...
...
@@ -655,14 +667,16 @@ def test_using_resource_for_put_with_html
end
end
def
test_using_resource_for_put_with_xml
def
test_using_resource_for_put_with_xml
_yields_ok_on_success
@request
.
accept
=
"application/xml"
put
:using_resource
assert_equal
"application/xml"
,
@response
.
content_type
assert_equal
200
,
@response
.
status
assert_equal
" "
,
@response
.
body
end
def
test_using_resource_for_put_with_xml_yields_unprocessable_entity_on_failure
@request
.
accept
=
"application/xml"
errors
=
{
:name
=>
:invalid
}
Customer
.
any_instance
.
stubs
(
:errors
).
returns
(
errors
)
put
:using_resource
...
...
@@ -672,7 +686,7 @@ def test_using_resource_for_put_with_xml
assert_nil
@response
.
location
end
def
test_using_resource_for_delete_with_html
def
test_using_resource_for_delete_with_html
_redirects_on_success
with_test_route_set
do
Customer
.
any_instance
.
stubs
(
:destroyed?
).
returns
(
true
)
delete
:using_resource
...
...
@@ -682,7 +696,7 @@ def test_using_resource_for_delete_with_html
end
end
def
test_using_resource_for_delete_with_xml
def
test_using_resource_for_delete_with_xml
_yields_ok_on_success
Customer
.
any_instance
.
stubs
(
:destroyed?
).
returns
(
true
)
@request
.
accept
=
"application/xml"
delete
:using_resource
...
...
@@ -691,6 +705,18 @@ def test_using_resource_for_delete_with_xml
assert_equal
" "
,
@response
.
body
end
def
test_using_resource_for_delete_with_html_redirects_on_failure
with_test_route_set
do
errors
=
{
:name
=>
:invalid
}
Customer
.
any_instance
.
stubs
(
:errors
).
returns
(
errors
)
Customer
.
any_instance
.
stubs
(
:destroyed?
).
returns
(
false
)
delete
:using_resource
assert_equal
"text/html"
,
@response
.
content_type
assert_equal
302
,
@response
.
status
assert_equal
"http://www.example.com/customers/13"
,
@response
.
location
end
end
def
test_using_resource_with_parent_for_get
@request
.
accept
=
"application/xml"
get
:using_resource_with_parent
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录