Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
b6561344
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,发现更多精彩内容 >>
提交
b6561344
编写于
5月 02, 2012
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6125 from ncri/master
Adding proc evaluation for action caching layout parameter
上级
2914b920
9a41edf0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
3 deletion
+36
-3
actionpack/lib/action_controller/caching/actions.rb
actionpack/lib/action_controller/caching/actions.rb
+4
-2
actionpack/test/controller/caching_test.rb
actionpack/test/controller/caching_test.rb
+32
-1
未找到文件。
actionpack/lib/action_controller/caching/actions.rb
浏览文件 @
b6561344
...
@@ -133,6 +133,8 @@ def initialize(options, &block)
...
@@ -133,6 +133,8 @@ def initialize(options, &block)
end
end
def
filter
(
controller
)
def
filter
(
controller
)
cache_layout
=
@cache_layout
.
respond_to?
(
:call
)
?
@cache_layout
.
call
(
controller
)
:
@cache_layout
path_options
=
if
@cache_path
.
respond_to?
(
:call
)
path_options
=
if
@cache_path
.
respond_to?
(
:call
)
controller
.
instance_exec
(
controller
,
&
@cache_path
)
controller
.
instance_exec
(
controller
,
&
@cache_path
)
else
else
...
@@ -144,13 +146,13 @@ def filter(controller)
...
@@ -144,13 +146,13 @@ def filter(controller)
body
=
controller
.
read_fragment
(
cache_path
.
path
,
@store_options
)
body
=
controller
.
read_fragment
(
cache_path
.
path
,
@store_options
)
unless
body
unless
body
controller
.
action_has_layout
=
false
unless
@
cache_layout
controller
.
action_has_layout
=
false
unless
cache_layout
yield
yield
controller
.
action_has_layout
=
true
controller
.
action_has_layout
=
true
body
=
controller
.
_save_fragment
(
cache_path
.
path
,
@store_options
)
body
=
controller
.
_save_fragment
(
cache_path
.
path
,
@store_options
)
end
end
body
=
controller
.
render_to_string
(
:text
=>
body
,
:layout
=>
true
)
unless
@
cache_layout
body
=
controller
.
render_to_string
(
:text
=>
body
,
:layout
=>
true
)
unless
cache_layout
controller
.
response_body
=
body
controller
.
response_body
=
body
controller
.
content_type
=
Mime
[
cache_path
.
extension
||
:html
]
controller
.
content_type
=
Mime
[
cache_path
.
extension
||
:html
]
...
...
actionpack/test/controller/caching_test.rb
浏览文件 @
b6561344
...
@@ -236,6 +236,7 @@ class ActionCachingTestController < CachingController
...
@@ -236,6 +236,7 @@ class ActionCachingTestController < CachingController
caches_action
:with_layout
caches_action
:with_layout
caches_action
:with_format_and_http_param
,
:cache_path
=>
Proc
.
new
{
|
c
|
{
:key
=>
'value'
}
}
caches_action
:with_format_and_http_param
,
:cache_path
=>
Proc
.
new
{
|
c
|
{
:key
=>
'value'
}
}
caches_action
:layout_false
,
:layout
=>
false
caches_action
:layout_false
,
:layout
=>
false
caches_action
:with_layout_proc_param
,
:layout
=>
Proc
.
new
{
|
c
|
c
.
params
[
:layout
]
}
caches_action
:record_not_found
,
:four_oh_four
,
:simple_runtime_error
caches_action
:record_not_found
,
:four_oh_four
,
:simple_runtime_error
caches_action
:streaming
caches_action
:streaming
...
@@ -282,6 +283,7 @@ def simple_runtime_error
...
@@ -282,6 +283,7 @@ def simple_runtime_error
alias_method
:edit
,
:index
alias_method
:edit
,
:index
alias_method
:destroy
,
:index
alias_method
:destroy
,
:index
alias_method
:layout_false
,
:with_layout
alias_method
:layout_false
,
:with_layout
alias_method
:with_layout_proc_param
,
:with_layout
def
expire
def
expire
expire_action
:controller
=>
'action_caching_test'
,
:action
=>
'index'
expire_action
:controller
=>
'action_caching_test'
,
:action
=>
'index'
...
@@ -403,11 +405,40 @@ def test_action_cache_with_layout_and_layout_cache_false
...
@@ -403,11 +405,40 @@ def test_action_cache_with_layout_and_layout_cache_false
get
:layout_false
get
:layout_false
assert_response
:success
assert_response
:success
assert_not_equal
cached_time
,
@response
.
body
assert_not_equal
cached_time
,
@response
.
body
body
=
body_to_string
(
read_fragment
(
'hostname.com/action_caching_test/layout_false'
))
body
=
body_to_string
(
read_fragment
(
'hostname.com/action_caching_test/layout_false'
))
assert_equal
cached_time
,
body
assert_equal
cached_time
,
body
end
end
def
test_action_cache_with_layout_and_layout_cache_false_via_proc
get
:with_layout_proc_param
,
:layout
=>
false
assert_response
:success
cached_time
=
content_to_cache
assert_not_equal
cached_time
,
@response
.
body
assert
fragment_exist?
(
'hostname.com/action_caching_test/with_layout_proc_param'
)
reset!
get
:with_layout_proc_param
,
:layout
=>
false
assert_response
:success
assert_not_equal
cached_time
,
@response
.
body
body
=
body_to_string
(
read_fragment
(
'hostname.com/action_caching_test/with_layout_proc_param'
))
assert_equal
cached_time
,
body
end
def
test_action_cache_with_layout_and_layout_cache_true_via_proc
get
:with_layout_proc_param
,
:layout
=>
true
assert_response
:success
cached_time
=
content_to_cache
assert_not_equal
cached_time
,
@response
.
body
assert
fragment_exist?
(
'hostname.com/action_caching_test/with_layout_proc_param'
)
reset!
get
:with_layout_proc_param
,
:layout
=>
true
assert_response
:success
assert_not_equal
cached_time
,
@response
.
body
body
=
body_to_string
(
read_fragment
(
'hostname.com/action_caching_test/with_layout_proc_param'
))
assert_equal
@response
.
body
,
body
end
def
test_action_cache_conditional_options
def
test_action_cache_conditional_options
@request
.
env
[
'HTTP_ACCEPT'
]
=
'application/json'
@request
.
env
[
'HTTP_ACCEPT'
]
=
'application/json'
get
:index
get
:index
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录