Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
bbe86077
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,发现更多精彩内容 >>
提交
bbe86077
编写于
7月 29, 2009
作者:
J
José Valim
提交者:
Yehuda Katz
7月 29, 2009
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added tests for respond_to class method.
Signed-off-by:
N
Yehuda Katz
<
wycats@gmail.com
>
上级
67b2d08c
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
73 addition
and
3 deletion
+73
-3
actionpack/lib/action_controller/base/mime_responds.rb
actionpack/lib/action_controller/base/mime_responds.rb
+1
-1
actionpack/test/controller/mime_responds_test.rb
actionpack/test/controller/mime_responds_test.rb
+68
-2
actionpack/test/fixtures/respond_with/using_defaults.html.erb
...onpack/test/fixtures/respond_with/using_defaults.html.erb
+1
-0
actionpack/test/fixtures/respond_with/using_defaults.js.rjs
actionpack/test/fixtures/respond_with/using_defaults.js.rjs
+1
-0
actionpack/test/fixtures/respond_with/using_defaults_with_type_list.js.rjs
...ixtures/respond_with/using_defaults_with_type_list.js.rjs
+1
-0
actionpack/test/fixtures/respond_with/using_defaults_with_type_list.xml.builder
...es/respond_with/using_defaults_with_type_list.xml.builder
+1
-0
未找到文件。
actionpack/lib/action_controller/base/mime_responds.rb
浏览文件 @
bbe86077
...
...
@@ -151,7 +151,7 @@ def respond_to(*mimes, &block)
block
.
call
(
responder
)
if
block_given?
mimes
=
collect_mimes_from_class_level
if
mimes
.
empty?
mimes
.
each
{
|
mime
|
responder
.
custom
(
mime
)
}
mimes
.
each
{
|
mime
|
responder
.
send
(
mime
)
}
if
format
=
request
.
negotiate_mime
(
responder
.
order
)
# TODO It should be just: self.formats = [ :foo ]
...
...
actionpack/test/controller/mime_responds_test.rb
浏览文件 @
bbe86077
...
...
@@ -166,7 +166,7 @@ def set_layout
end
end
class
Mime
ControllerTest
<
ActionController
::
TestCase
class
RespondTo
ControllerTest
<
ActionController
::
TestCase
tests
RespondToController
def
setup
...
...
@@ -471,8 +471,74 @@ def test_format_with_custom_response_type_and_request_headers
end
end
class
ClassRespondToController
<
ActionController
::
Base
class
RespondWithController
<
ActionController
::
Base
respond_to
:html
respond_to
:xml
,
:except
=>
:using_defaults
respond_to
:js
,
:only
=>
:using_defaults
def
using_defaults
respond_to
do
|
format
|
format
.
csv
{
render
:text
=>
"CSV"
}
end
end
def
using_defaults_with_type_list
respond_to
(
:js
,
:xml
)
end
end
class
RespondWithControllerTest
<
ActionController
::
TestCase
tests
RespondWithController
def
setup
super
ActionController
::
Base
.
use_accept_header
=
true
@request
.
host
=
"www.example.com"
end
def
teardown
super
ActionController
::
Base
.
use_accept_header
=
false
end
def
test_using_defaults
@request
.
accept
=
"*/*"
get
:using_defaults
assert_equal
"text/html"
,
@response
.
content_type
assert_equal
'Hello world!'
,
@response
.
body
@request
.
accept
=
"text/csv"
get
:using_defaults
assert_equal
"text/csv"
,
@response
.
content_type
assert_equal
"CSV"
,
@response
.
body
@request
.
accept
=
"text/javascript"
get
:using_defaults
assert_equal
"text/javascript"
,
@response
.
content_type
assert_equal
'$("body").visualEffect("highlight");'
,
@response
.
body
end
def
test_using_defaults_with_type_list
@request
.
accept
=
"*/*"
get
:using_defaults_with_type_list
assert_equal
"text/javascript"
,
@response
.
content_type
assert_equal
'$("body").visualEffect("highlight");'
,
@response
.
body
@request
.
accept
=
"application/xml"
get
:using_defaults_with_type_list
assert_equal
"application/xml"
,
@response
.
content_type
assert_equal
"<p>Hello world!</p>
\n
"
,
@response
.
body
end
def
test_not_acceptable
@request
.
accept
=
"application/xml"
get
:using_defaults
assert_equal
406
,
@response
.
status
@request
.
accept
=
"text/html"
get
:using_defaults_with_type_list
assert_equal
406
,
@response
.
status
end
end
class
AbstractPostController
<
ActionController
::
Base
...
...
actionpack/test/fixtures/respond_with/using_defaults.html.erb
0 → 100644
浏览文件 @
bbe86077
Hello world!
\ No newline at end of file
actionpack/test/fixtures/respond_with/using_defaults.js.rjs
0 → 100644
浏览文件 @
bbe86077
page[:body].visual_effect :highlight
\ No newline at end of file
actionpack/test/fixtures/respond_with/using_defaults_with_type_list.js.rjs
0 → 100644
浏览文件 @
bbe86077
page[:body].visual_effect :highlight
\ No newline at end of file
actionpack/test/fixtures/respond_with/using_defaults_with_type_list.xml.builder
0 → 100644
浏览文件 @
bbe86077
xml.p "Hello world!"
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录