Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
b0d35ad0
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,发现更多精彩内容 >>
提交
b0d35ad0
编写于
1月 13, 2010
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Test fragment/page cache and send data/file notifications.
上级
da5978c2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
100 addition
and
17 deletion
+100
-17
actionpack/lib/action_controller/railties/subscriber.rb
actionpack/lib/action_controller/railties/subscriber.rb
+5
-5
actionpack/test/controller/subscriber_test.rb
actionpack/test/controller/subscriber_test.rb
+93
-11
actionpack/test/template/subscriber_test.rb
actionpack/test/template/subscriber_test.rb
+2
-1
未找到文件。
actionpack/lib/action_controller/railties/subscriber.rb
浏览文件 @
b0d35ad0
...
...
@@ -24,11 +24,11 @@ def process_action(event)
def
send_file
(
event
)
message
=
if
event
.
payload
[
:x_sendfile
]
header
=
ActionController
::
Streaming
::
X_SENDFILE_HEADER
"Sen
ding
#{
header
}
header %s"
"Sen
t
#{
header
}
header %s"
elsif
event
.
payload
[
:stream
]
"Stream
ing
file %s"
"Stream
ed
file %s"
else
"Sen
ding
file %s"
"Sen
t
file %s"
end
message
<<
" (%.1fms)"
...
...
@@ -40,7 +40,7 @@ def redirect_to(event)
end
def
send_data
(
event
)
info
(
"Sen
ding
data %s (%.1fms)"
%
[
event
.
payload
[
:filename
],
event
.
duration
])
info
(
"Sen
t
data %s (%.1fms)"
%
[
event
.
payload
[
:filename
],
event
.
duration
])
end
%w(write_fragment read_fragment exist_fragment?
...
...
@@ -49,7 +49,7 @@ def send_data(event)
def
#{
method
}
(event)
key_or_path = event.payload[:key] || event.payload[:path]
human_name =
#{
method
.
to_s
.
humanize
.
inspect
}
info("
\#
{human_name}
\#
{key_or_path
.inspect
} (%.1fms)" % event.duration)
info("
\#
{human_name}
\#
{key_or_path} (%.1fms)" % event.duration)
end
METHOD
end
...
...
actionpack/test/controller/subscriber_test.rb
浏览文件 @
b0d35ad0
...
...
@@ -11,11 +11,31 @@ def show
def
redirector
redirect_to
"http://foo.bar/"
end
def
data_sender
send_data
"cool data"
,
:filename
=>
"omg.txt"
end
def
xfile_sender
send_file
File
.
expand_path
(
"company.rb"
,
FIXTURE_LOAD_PATH
),
:x_sendfile
=>
true
end
def
file_sender
send_file
File
.
expand_path
(
"company.rb"
,
FIXTURE_LOAD_PATH
)
end
def
with_fragment_cache
render
:inline
=>
"<%= cache('foo'){ 'bar' } %>"
end
def
with_page_cache
cache_page
(
"Super soaker"
,
"/index.html"
)
render
:nothing
=>
true
end
end
end
module
ActionControllerSubscriberTest
Rails
::
Subscriber
.
add
(
:action_controller
,
ActionController
::
Railties
::
Subscriber
.
new
)
def
self
.
included
(
base
)
base
.
tests
Another
::
SubscribersController
...
...
@@ -28,11 +48,19 @@ def wait
def
setup
@old_logger
=
ActionController
::
Base
.
logger
@cache_path
=
File
.
expand_path
(
'../temp/test_cache'
,
File
.
dirname
(
__FILE__
))
ActionController
::
Base
.
page_cache_directory
=
@cache_path
ActionController
::
Base
.
cache_store
=
:file_store
,
@cache_path
Rails
::
Subscriber
.
add
(
:action_controller
,
ActionController
::
Railties
::
Subscriber
.
new
)
super
end
def
teardown
super
Rails
::
Subscriber
.
subscribers
.
clear
FileUtils
.
rm_rf
(
@cache_path
)
ActionController
::
Base
.
logger
=
@old_logger
end
...
...
@@ -43,34 +71,34 @@ def set_logger(logger)
def
test_process_action
get
:show
wait
assert_equal
3
,
@logger
.
logged
(
:info
)
.
size
assert_match
/Processed\sAnother::SubscribersController#show/
,
@logger
.
logged
(
:info
)
[
0
]
assert_equal
3
,
logs
.
size
assert_match
/Processed\sAnother::SubscribersController#show/
,
logs
[
0
]
end
def
test_process_action_without_parameters
get
:show
wait
assert_nil
@logger
.
logged
(
:info
)
.
detect
{
|
l
|
l
=~
/Parameters/
}
assert_nil
logs
.
detect
{
|
l
|
l
=~
/Parameters/
}
end
def
test_process_action_with_parameters
get
:show
,
:id
=>
'10'
wait
assert_equal
4
,
@logger
.
logged
(
:info
)
.
size
assert_equal
'Parameters: {"id"=>"10"}'
,
@logger
.
logged
(
:info
)
[
1
]
assert_equal
4
,
logs
.
size
assert_equal
'Parameters: {"id"=>"10"}'
,
logs
[
1
]
end
def
test_process_action_with_view_runtime
get
:show
wait
assert_match
/View runtime/
,
@logger
.
logged
(
:info
)
[
1
]
assert_match
/View runtime/
,
logs
[
1
]
end
def
test_process_action_with_status_and_request_uri
get
:show
wait
last
=
@logger
.
logged
(
:info
)
.
last
last
=
logs
.
last
assert_match
/Completed/
,
last
assert_match
/200/
,
last
assert_match
/another\/subscribers\/show/
,
last
...
...
@@ -82,7 +110,7 @@ def test_process_action_with_filter_parameters
get
:show
,
:lifo
=>
'Pratik'
,
:amount
=>
'420'
,
:step
=>
'1'
wait
params
=
@logger
.
logged
(
:info
)
[
1
]
params
=
logs
[
1
]
assert_match
/"amount"=>"\[FILTERED\]"/
,
params
assert_match
/"lifo"=>"\[FILTERED\]"/
,
params
assert_match
/"step"=>"1"/
,
params
...
...
@@ -92,8 +120,62 @@ def test_redirect_to
get
:redirector
wait
assert_equal
3
,
@logger
.
logged
(
:info
).
size
assert_equal
"Redirected to http://foo.bar/ with status 302"
,
@logger
.
logged
(
:info
)[
0
]
assert_equal
3
,
logs
.
size
assert_equal
"Redirected to http://foo.bar/ with status 302"
,
logs
[
0
]
end
def
test_send_data
get
:data_sender
wait
assert_equal
4
,
logs
.
size
assert_match
/Sent data omg\.txt/
,
logs
[
0
]
end
def
test_send_file
get
:file_sender
wait
assert_equal
4
,
logs
.
size
assert_match
/Sent file/
,
logs
[
0
]
assert_match
/test\/fixtures\/company\.rb/
,
logs
[
0
]
end
def
test_send_xfile
get
:xfile_sender
wait
assert_equal
3
,
logs
.
size
assert_match
/Sent X\-Sendfile header/
,
logs
[
0
]
assert_match
/test\/fixtures\/company\.rb/
,
logs
[
0
]
end
def
test_with_fragment_cache
ActionController
::
Base
.
perform_caching
=
true
get
:with_fragment_cache
wait
assert_equal
5
,
logs
.
size
assert_match
/Exist fragment\? views\/foo/
,
logs
[
0
]
assert_match
/Write fragment views\/foo/
,
logs
[
1
]
ensure
ActionController
::
Base
.
perform_caching
=
true
end
def
test_with_page_cache
ActionController
::
Base
.
perform_caching
=
true
get
:with_page_cache
wait
assert_equal
4
,
logs
.
size
assert_match
/Write page/
,
logs
[
0
]
assert_match
/\/index\.html/
,
logs
[
0
]
ensure
ActionController
::
Base
.
perform_caching
=
true
end
def
logs
@logs
||=
@logger
.
logged
(
:info
)
end
class
SyncSubscriberTest
<
ActionController
::
TestCase
...
...
actionpack/test/template/subscriber_test.rb
浏览文件 @
b0d35ad0
...
...
@@ -4,17 +4,18 @@
require
"controller/fake_models"
module
ActionViewSubscriberTest
Rails
::
Subscriber
.
add
(
:action_view
,
ActionView
::
Railties
::
Subscriber
.
new
)
def
setup
@old_logger
=
ActionController
::
Base
.
logger
@view
=
ActionView
::
Base
.
new
(
ActionController
::
Base
.
view_paths
,
{})
Rails
.
stubs
(
:root
).
returns
(
File
.
expand_path
(
FIXTURE_LOAD_PATH
))
Rails
::
Subscriber
.
add
(
:action_view
,
ActionView
::
Railties
::
Subscriber
.
new
)
super
end
def
teardown
super
Rails
::
Subscriber
.
subscribers
.
clear
ActionController
::
Base
.
logger
=
@old_logger
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录