Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
485512c5
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,发现更多精彩内容 >>
提交
485512c5
编写于
4月 04, 2010
作者:
W
wycats
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Whitespace
上级
209fb519
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
33 addition
and
34 deletion
+33
-34
actionpack/test/abstract/abstract_controller_test.rb
actionpack/test/abstract/abstract_controller_test.rb
+33
-34
未找到文件。
actionpack/test/abstract/abstract_controller_test.rb
浏览文件 @
485512c5
...
...
@@ -2,21 +2,21 @@
module
AbstractController
module
Testing
# Test basic dispatching.
# ====
# * Call process
# * Test that the response_body is set correctly
class
SimpleController
<
AbstractController
::
Base
end
class
Me
<
SimpleController
def
index
self
.
response_body
=
"Hello world"
"Something else"
end
end
end
class
TestBasic
<
ActiveSupport
::
TestCase
test
"dispatching works"
do
controller
=
Me
.
new
...
...
@@ -24,7 +24,7 @@ class TestBasic < ActiveSupport::TestCase
assert_equal
"Hello world"
,
controller
.
response_body
end
end
# Test Render mixin
# ====
class
RenderingController
<
AbstractController
::
Base
...
...
@@ -36,19 +36,18 @@ def render(options = {})
if
options
.
is_a?
(
String
)
options
=
{
:_template_name
=>
options
}
end
options
[
:_prefix
]
=
_prefix
super
end
append_view_path
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"views"
))
end
class
Me2
<
RenderingController
def
index
render
"index.erb"
end
def
index_to_string
self
.
response_body
=
render_to_string
"index.erb"
...
...
@@ -58,7 +57,7 @@ def action_with_ivars
@my_ivar
=
"Hello"
render
"action_with_ivars.erb"
end
def
naked_render
render
end
...
...
@@ -81,7 +80,7 @@ def setup
@controller
.
process
(
:index
)
assert_equal
"Hello from index.erb"
,
@controller
.
response_body
end
test
"render_to_string works with a String as an argument"
do
@controller
.
process
(
:index_to_string
)
assert_equal
"Hello from index.erb"
,
@controller
.
response_body
...
...
@@ -91,7 +90,7 @@ def setup
@controller
.
process
(
:action_with_ivars
)
assert_equal
"Hello from index_with_ivars.erb"
,
@controller
.
response_body
end
test
"rendering with no template name"
do
@controller
.
process
(
:naked_render
)
assert_equal
"Hello from naked_render.erb"
,
@controller
.
response_body
...
...
@@ -107,7 +106,7 @@ def setup
assert_equal
"Hello from naked_render.erb"
,
@controller
.
response_body
end
end
# Test rendering with prefixes
# ====
# * self._prefix is used when defined
...
...
@@ -116,23 +115,23 @@ class PrefixedViews < RenderingController
def
self
.
prefix
name
.
underscore
end
def
_prefix
self
.
class
.
prefix
end
end
class
Me3
<
PrefixedViews
def
index
render
end
def
formatted
self
.
formats
=
[
:html
]
render
end
end
class
TestPrefixedViews
<
ActiveSupport
::
TestCase
def
setup
@controller
=
Me3
.
new
...
...
@@ -148,13 +147,13 @@ def setup
assert_equal
"Hello from me3/formatted.html.erb"
,
@controller
.
response_body
end
end
# Test rendering with layouts
# ====
# self._layout is used when defined
class
WithLayouts
<
PrefixedViews
include
Layouts
private
def
self
.
layout
(
formats
)
begin
...
...
@@ -170,21 +169,21 @@ def self.layout(formats)
def
render_to_body
(
options
=
{})
options
[
:_layout
]
=
options
[
:layout
]
||
_default_layout
({})
super
end
end
end
class
Me4
<
WithLayouts
def
index
render
end
end
class
Me5
<
WithLayouts
def
index
render
end
end
class
TestLayouts
<
ActiveSupport
::
TestCase
test
"layouts are included"
do
controller
=
Me4
.
new
...
...
@@ -192,7 +191,7 @@ class TestLayouts < ActiveSupport::TestCase
assert_equal
"Me4 Enter : Hello from me4/index.erb : Exit"
,
controller
.
response_body
end
end
# respond_to_action?(action_name)
# ====
# * A method can be used as an action only if this method
...
...
@@ -201,7 +200,7 @@ class TestLayouts < ActiveSupport::TestCase
class
DefaultRespondToActionController
<
AbstractController
::
Base
def
index
()
self
.
response_body
=
"success"
end
end
class
ActionMissingRespondToActionController
<
AbstractController
::
Base
# No actions
private
...
...
@@ -209,19 +208,19 @@ def action_missing(action_name)
self
.
response_body
=
"success"
end
end
class
RespondToActionController
<
AbstractController
::
Base
;
def
index
()
self
.
response_body
=
"success"
end
def
fail
()
self
.
response_body
=
"fail"
end
private
def
method_for_action
(
action_name
)
action_name
.
to_s
!=
"fail"
&&
action_name
end
end
class
TestRespondToAction
<
ActiveSupport
::
TestCase
def
assert_dispatch
(
klass
,
body
=
"success"
,
action
=
:index
)
...
...
@@ -229,27 +228,27 @@ def assert_dispatch(klass, body = "success", action = :index)
controller
.
process
(
action
)
assert_equal
body
,
controller
.
response_body
end
test
"an arbitrary method is available as an action by default"
do
assert_dispatch
DefaultRespondToActionController
,
"success"
,
:index
end
test
"raises ActionNotFound when method does not exist and action_missing is not defined"
do
assert_raise
(
ActionNotFound
)
{
DefaultRespondToActionController
.
new
.
process
(
:fail
)
}
end
test
"dispatches to action_missing when method does not exist and action_missing is defined"
do
assert_dispatch
ActionMissingRespondToActionController
,
"success"
,
:ohai
end
test
"a method is available as an action if respond_to_action? returns true"
do
assert_dispatch
RespondToActionController
,
"success"
,
:index
end
test
"raises ActionNotFound if method is defined but respond_to_action? returns false"
do
assert_raise
(
ActionNotFound
)
{
RespondToActionController
.
new
.
process
(
:fail
)
}
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录