Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
86ed58d9
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,发现更多精彩内容 >>
提交
86ed58d9
编写于
10月 03, 2009
作者:
J
Joshua Peek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use with_routing helper in tests instead of modifying global route set
上级
61411f2a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
125 addition
and
101 deletion
+125
-101
actionpack/test/controller/caching_test.rb
actionpack/test/controller/caching_test.rb
+11
-11
actionpack/test/controller/mime_responds_test.rb
actionpack/test/controller/mime_responds_test.rb
+83
-67
actionpack/test/controller/verification_test.rb
actionpack/test/controller/verification_test.rb
+8
-9
actionpack/test/template/test_test.rb
actionpack/test/template/test_test.rb
+23
-14
未找到文件。
actionpack/test/controller/caching_test.rb
浏览文件 @
86ed58d9
...
...
@@ -46,14 +46,8 @@ def trailing_slash
class
PageCachingTest
<
ActionController
::
TestCase
def
setup
super
ActionController
::
Base
.
perform_caching
=
true
ActionController
::
Routing
::
Routes
.
draw
do
|
map
|
map
.
main
''
,
:controller
=>
'posts'
,
:format
=>
nil
map
.
formatted_posts
'posts.:format'
,
:controller
=>
'posts'
map
.
resources
:posts
map
.
connect
':controller/:action/:id'
end
ActionController
::
Base
.
perform_caching
=
true
@request
=
ActionController
::
TestRequest
.
new
@request
.
host
=
'hostname.com'
...
...
@@ -74,10 +68,16 @@ def teardown
end
def
test_page_caching_resources_saves_to_correct_path_with_extension_even_if_default_route
@params
[
:format
]
=
'rss'
assert_equal
'/posts.rss'
,
@rewriter
.
rewrite
(
@params
)
@params
[
:format
]
=
nil
assert_equal
'/'
,
@rewriter
.
rewrite
(
@params
)
with_routing
do
|
set
|
set
.
draw
do
|
map
|
map
.
main
''
,
:controller
=>
'posts'
,
:format
=>
nil
map
.
formatted_posts
'posts.:format'
,
:controller
=>
'posts'
end
@params
[
:format
]
=
'rss'
assert_equal
'/posts.rss'
,
@rewriter
.
rewrite
(
@params
)
@params
[
:format
]
=
nil
assert_equal
'/'
,
@rewriter
.
rewrite
(
@params
)
end
end
def
test_should_cache_get_with_ok_status
...
...
actionpack/test/controller/mime_responds_test.rb
浏览文件 @
86ed58d9
...
...
@@ -527,12 +527,6 @@ def setup
super
ActionController
::
Base
.
use_accept_header
=
true
@request
.
host
=
"www.example.com"
ActionController
::
Routing
::
Routes
.
draw
do
|
map
|
map
.
resources
:customers
map
.
resources
:quiz_stores
,
:has_many
=>
:customers
map
.
connect
":controller/:action/:id"
end
end
def
teardown
...
...
@@ -593,53 +587,59 @@ def test_using_resource
end
def
test_using_resource_for_post_with_html
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?
errors
=
{
:name
=>
:invalid
}
Customer
.
any_instance
.
stubs
(
:errors
).
returns
(
errors
)
post
:using_resource
assert_equal
"text/html"
,
@response
.
content_type
assert_equal
200
,
@response
.
status
assert_equal
"New world!
\n
"
,
@response
.
body
assert_nil
@response
.
location
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?
errors
=
{
:name
=>
:invalid
}
Customer
.
any_instance
.
stubs
(
:errors
).
returns
(
errors
)
post
:using_resource
assert_equal
"text/html"
,
@response
.
content_type
assert_equal
200
,
@response
.
status
assert_equal
"New world!
\n
"
,
@response
.
body
assert_nil
@response
.
location
end
end
def
test_using_resource_for_post_with_xml
@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
errors
=
{
:name
=>
:invalid
}
Customer
.
any_instance
.
stubs
(
:errors
).
returns
(
errors
)
post
:using_resource
assert_equal
"application/xml"
,
@response
.
content_type
assert_equal
422
,
@response
.
status
assert_equal
errors
.
to_xml
,
@response
.
body
assert_nil
@response
.
location
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
errors
=
{
:name
=>
:invalid
}
Customer
.
any_instance
.
stubs
(
:errors
).
returns
(
errors
)
post
:using_resource
assert_equal
"application/xml"
,
@response
.
content_type
assert_equal
422
,
@response
.
status
assert_equal
errors
.
to_xml
,
@response
.
body
assert_nil
@response
.
location
end
end
def
test_using_resource_for_put_with_html
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?
errors
=
{
:name
=>
:invalid
}
Customer
.
any_instance
.
stubs
(
:errors
).
returns
(
errors
)
put
:using_resource
assert_equal
"text/html"
,
@response
.
content_type
assert_equal
200
,
@response
.
status
assert_equal
"Edit world!
\n
"
,
@response
.
body
assert_nil
@response
.
location
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?
errors
=
{
:name
=>
:invalid
}
Customer
.
any_instance
.
stubs
(
:errors
).
returns
(
errors
)
put
:using_resource
assert_equal
"text/html"
,
@response
.
content_type
assert_equal
200
,
@response
.
status
assert_equal
"Edit world!
\n
"
,
@response
.
body
assert_nil
@response
.
location
end
end
def
test_using_resource_for_put_with_xml
...
...
@@ -660,11 +660,13 @@ def test_using_resource_for_put_with_xml
end
def
test_using_resource_for_delete_with_html
Customer
.
any_instance
.
stubs
(
:destroyed?
).
returns
(
true
)
delete
:using_resource
assert_equal
"text/html"
,
@response
.
content_type
assert_equal
302
,
@response
.
status
assert_equal
"http://www.example.com/customers"
,
@response
.
location
with_test_route_set
do
Customer
.
any_instance
.
stubs
(
:destroyed?
).
returns
(
true
)
delete
:using_resource
assert_equal
"text/html"
,
@response
.
content_type
assert_equal
302
,
@response
.
status
assert_equal
"http://www.example.com/customers"
,
@response
.
location
end
end
def
test_using_resource_for_delete_with_xml
...
...
@@ -685,21 +687,23 @@ def test_using_resource_with_parent_for_get
end
def
test_using_resource_with_parent_for_post
@request
.
accept
=
"application/xml"
post
:using_resource_with_parent
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/quiz_stores/11/customers/13"
,
@response
.
location
errors
=
{
:name
=>
:invalid
}
Customer
.
any_instance
.
stubs
(
:errors
).
returns
(
errors
)
post
:using_resource
assert_equal
"application/xml"
,
@response
.
content_type
assert_equal
422
,
@response
.
status
assert_equal
errors
.
to_xml
,
@response
.
body
assert_nil
@response
.
location
with_test_route_set
do
@request
.
accept
=
"application/xml"
post
:using_resource_with_parent
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/quiz_stores/11/customers/13"
,
@response
.
location
errors
=
{
:name
=>
:invalid
}
Customer
.
any_instance
.
stubs
(
:errors
).
returns
(
errors
)
post
:using_resource
assert_equal
"application/xml"
,
@response
.
content_type
assert_equal
422
,
@response
.
status
assert_equal
errors
.
to_xml
,
@response
.
body
assert_nil
@response
.
location
end
end
def
test_using_resource_with_collection
...
...
@@ -773,6 +777,18 @@ def test_not_acceptable
get
:default_overwritten
assert_equal
406
,
@response
.
status
end
private
def
with_test_route_set
with_routing
do
|
set
|
set
.
draw
do
|
map
|
map
.
resources
:customers
map
.
resources
:quiz_stores
,
:has_many
=>
:customers
map
.
connect
":controller/:action/:id"
end
yield
end
end
end
class
AbstractPostController
<
ActionController
::
Base
...
...
actionpack/test/controller/verification_test.rb
浏览文件 @
86ed58d9
...
...
@@ -111,13 +111,6 @@ def unconditional_redirect
tests
TestController
setup
do
ActionController
::
Routing
::
Routes
.
draw
do
|
map
|
map
.
foo
'/foo'
,
:controller
=>
'test'
,
:action
=>
'foo'
map
.
connect
":controller/:action/:id"
end
end
def
test_using_symbol_back_with_no_referrer
assert_raise
(
ActionController
::
RedirectBackError
)
{
get
:guarded_with_back
}
end
...
...
@@ -130,8 +123,14 @@ def test_using_symbol_back_redirects_to_referrer
def
test_no_deprecation_warning_for_named_route
assert_not_deprecated
do
get
:guarded_one_for_named_route_test
,
:two
=>
"not one"
assert_redirected_to
'/foo'
with_routing
do
|
set
|
set
.
draw
do
|
map
|
map
.
foo
'/foo'
,
:controller
=>
'test'
,
:action
=>
'foo'
map
.
connect
":controller/:action/:id"
end
get
:guarded_one_for_named_route_test
,
:two
=>
"not one"
assert_redirected_to
'/foo'
end
end
end
...
...
actionpack/test/template/test_test.rb
浏览文件 @
86ed58d9
...
...
@@ -19,32 +19,41 @@ def link_to_person(person)
end
class
PeopleHelperTest
<
ActionView
::
TestCase
def
setup
super
ActionController
::
Routing
::
Routes
.
draw
do
|
map
|
map
.
people
'people'
,
:controller
=>
'people'
,
:action
=>
'index'
map
.
connect
':controller/:action/:id'
end
end
def
test_title
assert_equal
"<h1>Ruby on Rails</h1>"
,
title
(
"Ruby on Rails"
)
end
def
test_homepage_path
assert_equal
"/people"
,
homepage_path
with_test_route_set
do
assert_equal
"/people"
,
homepage_path
end
end
def
test_homepage_url
assert_equal
"http://test.host/people"
,
homepage_url
with_test_route_set
do
assert_equal
"http://test.host/people"
,
homepage_url
end
end
def
test_link_to_person
person
=
mock
(
:name
=>
"David"
)
person
.
class
.
extend
ActiveModel
::
Naming
expects
(
:mocha_mock_path
).
with
(
person
).
returns
(
"/people/1"
)
assert_equal
'<a href="/people/1">David</a>'
,
link_to_person
(
person
)
with_test_route_set
do
person
=
mock
(
:name
=>
"David"
)
person
.
class
.
extend
ActiveModel
::
Naming
expects
(
:mocha_mock_path
).
with
(
person
).
returns
(
"/people/1"
)
assert_equal
'<a href="/people/1">David</a>'
,
link_to_person
(
person
)
end
end
private
def
with_test_route_set
with_routing
do
|
set
|
set
.
draw
do
|
map
|
map
.
people
'people'
,
:controller
=>
'people'
,
:action
=>
'index'
map
.
connect
':controller/:action/:id'
end
yield
end
end
end
class
CrazyHelperTest
<
ActionView
::
TestCase
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录