Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
196f780e
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,发现更多精彩内容 >>
提交
196f780e
编写于
6月 01, 2009
作者:
Y
Yehuda Katz + Carl Lerche
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Get all the callback tests to work on new base
上级
dcba6e11
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
62 addition
and
25 deletion
+62
-25
actionpack/lib/action_controller/abstract/callbacks.rb
actionpack/lib/action_controller/abstract/callbacks.rb
+6
-0
actionpack/test/controller/filters_test.rb
actionpack/test/controller/filters_test.rb
+46
-22
activesupport/lib/active_support/new_callbacks.rb
activesupport/lib/active_support/new_callbacks.rb
+10
-3
未找到文件。
actionpack/lib/action_controller/abstract/callbacks.rb
浏览文件 @
196f780e
...
...
@@ -26,6 +26,12 @@ def _normalize_callback_options(options)
end
end
def
skip_filter
(
*
names
,
&
blk
)
skip_before_filter
(
*
names
,
&
blk
)
skip_after_filter
(
*
names
,
&
blk
)
skip_around_filter
(
*
names
,
&
blk
)
end
[
:before
,
:after
,
:around
].
each
do
|
filter
|
class_eval
<<-
RUBY_EVAL
,
__FILE__
,
__LINE__
+
1
def
#{
filter
}
_filter(*names, &blk)
...
...
actionpack/test/controller/filters_test.rb
浏览文件 @
196f780e
...
...
@@ -231,24 +231,29 @@ def find_user
end
class
ConditionalParentOfConditionalSkippingController
<
ConditionalFilterController
before_filter
:conditional_in_parent
,
:only
=>
[
:show
,
:another_action
]
after_filter
:conditional_in_parent
,
:only
=>
[
:show
,
:another_action
]
before_filter
:conditional_in_parent
_before
,
:only
=>
[
:show
,
:another_action
]
after_filter
:conditional_in_parent
_after
,
:only
=>
[
:show
,
:another_action
]
private
def
conditional_in_parent
def
conditional_in_parent
_before
@ran_filter
||=
[]
@ran_filter
<<
'conditional_in_parent'
@ran_filter
<<
'conditional_in_parent_before'
end
def
conditional_in_parent_after
@ran_filter
||=
[]
@ran_filter
<<
'conditional_in_parent_after'
end
end
class
ChildOfConditionalParentController
<
ConditionalParentOfConditionalSkippingController
skip_before_filter
:conditional_in_parent
,
:only
=>
:another_action
skip_after_filter
:conditional_in_parent
,
:only
=>
:another_action
skip_before_filter
:conditional_in_parent
_before
,
:only
=>
:another_action
skip_after_filter
:conditional_in_parent
_after
,
:only
=>
:another_action
end
class
AnotherChildOfConditionalParentController
<
ConditionalParentOfConditionalSkippingController
skip_before_filter
:conditional_in_parent
,
:only
=>
:show
skip_before_filter
:conditional_in_parent
_before
,
:only
=>
:show
end
class
ProcController
<
PrependingController
...
...
@@ -593,11 +598,22 @@ def test_having_properties_in_around_filter
assert_equal
"before and after"
,
assigns
[
"execution_log"
]
end
def
test_prepending_and_appending_around_filter
controller
=
test_process
(
MixedFilterController
)
assert_equal
" before aroundfilter before procfilter before appended aroundfilter "
+
" after appended aroundfilter after aroundfilter after procfilter "
,
MixedFilterController
.
execution_log
for_tag
(
:old_base
)
do
def
test_prepending_and_appending_around_filter
controller
=
test_process
(
MixedFilterController
)
assert_equal
" before aroundfilter before procfilter before appended aroundfilter "
+
" after appended aroundfilter after aroundfilter after procfilter "
,
MixedFilterController
.
execution_log
end
end
for_tag
(
:new_base
)
do
def
test_prepending_and_appending_around_filter
controller
=
test_process
(
MixedFilterController
)
assert_equal
" before aroundfilter before procfilter before appended aroundfilter "
+
" after appended aroundfilter after procfilter after aroundfilter "
,
MixedFilterController
.
execution_log
end
end
def
test_rendering_breaks_filtering_chain
...
...
@@ -658,18 +674,18 @@ def test_conditional_skipping_of_filters
def
test_conditional_skipping_of_filters_when_parent_filter_is_also_conditional
test_process
(
ChildOfConditionalParentController
)
assert_equal
%w( conditional_in_parent
conditional_in_parent
)
,
assigns
[
'ran_filter'
]
assert_equal
%w( conditional_in_parent
_before conditional_in_parent_after
)
,
assigns
[
'ran_filter'
]
test_process
(
ChildOfConditionalParentController
,
'another_action'
)
assert_nil
assigns
[
'ran_filter'
]
end
def
test_condition_skipping_of_filters_when_siblings_also_have_conditions
test_process
(
ChildOfConditionalParentController
)
assert_equal
%w( conditional_in_parent
conditional_in_parent )
,
assigns
[
'ran_filter'
],
"1"
assert_equal
%w( conditional_in_parent
_before conditional_in_parent_after )
,
assigns
[
'ran_filter'
]
test_process
(
AnotherChildOfConditionalParentController
)
assert_equal
nil
,
assigns
[
'ran_filter'
]
assert_equal
%w( conditional_in_parent_after )
,
assigns
[
'ran_filter'
]
test_process
(
ChildOfConditionalParentController
)
assert_equal
%w( conditional_in_parent
conditional_in_parent
)
,
assigns
[
'ran_filter'
]
assert_equal
%w( conditional_in_parent
_before conditional_in_parent_after
)
,
assigns
[
'ran_filter'
]
end
def
test_changing_the_requirements
...
...
@@ -823,7 +839,9 @@ def around_again
end
class
ControllerWithTwoLessFilters
<
ControllerWithAllTypesOfFilters
$vbf
=
true
skip_filter
:around_again
$vbf
=
false
skip_filter
:after
end
...
...
@@ -886,9 +904,18 @@ def test_nested_filters
end
end
def
test_filter_order_with_all_filter_types
test_process
(
ControllerWithAllTypesOfFilters
,
'no_raise'
)
assert_equal
'before around (before yield) around_again (before yield) around_again (after yield) around (after yield) after'
,
assigns
[
'ran_filter'
].
join
(
' '
)
for_tag
(
:old_base
)
do
def
test_filter_order_with_all_filter_types
test_process
(
ControllerWithAllTypesOfFilters
,
'no_raise'
)
assert_equal
'before around (before yield) around_again (before yield) around_again (after yield) around (after yield) after'
,
assigns
[
'ran_filter'
].
join
(
' '
)
end
end
for_tag
(
:new_base
)
do
def
test_filter_order_with_all_filter_types
test_process
(
ControllerWithAllTypesOfFilters
,
'no_raise'
)
assert_equal
'before around (before yield) around_again (before yield) around_again (after yield) after around (after yield)'
,
assigns
[
'ran_filter'
].
join
(
' '
)
end
end
def
test_filter_order_with_skip_filter_method
...
...
@@ -901,7 +928,6 @@ def test_first_filter_in_multiple_before_filter_chain_halts
response
=
test_process
(
controller
,
'fail_1'
)
assert_equal
' '
,
response
.
body
assert_equal
1
,
controller
.
instance_variable_get
(
:@try
)
assert
controller
.
instance_variable_get
(
:@before_filter_chain_aborted
)
end
def
test_second_filter_in_multiple_before_filter_chain_halts
...
...
@@ -909,7 +935,6 @@ def test_second_filter_in_multiple_before_filter_chain_halts
response
=
test_process
(
controller
,
'fail_2'
)
assert_equal
' '
,
response
.
body
assert_equal
2
,
controller
.
instance_variable_get
(
:@try
)
assert
controller
.
instance_variable_get
(
:@before_filter_chain_aborted
)
end
def
test_last_filter_in_multiple_before_filter_chain_halts
...
...
@@ -917,7 +942,6 @@ def test_last_filter_in_multiple_before_filter_chain_halts
response
=
test_process
(
controller
,
'fail_3'
)
assert_equal
' '
,
response
.
body
assert_equal
3
,
controller
.
instance_variable_get
(
:@try
)
assert
controller
.
instance_variable_get
(
:@before_filter_chain_aborted
)
end
protected
...
...
activesupport/lib/active_support/new_callbacks.rb
浏览文件 @
196f780e
...
...
@@ -286,7 +286,14 @@ def _compile_filter(filter)
filter
when
Proc
@klass
.
send
(
:define_method
,
method_name
,
&
filter
)
method_name
<<
(
filter
.
arity
==
1
?
"(self)"
:
""
)
method_name
<<
case
filter
.
arity
when
1
"(self)"
when
2
" self, Proc.new "
else
""
end
when
Method
@klass
.
send
(
:define_method
,
"
#{
method_name
}
_method"
)
{
filter
}
@klass
.
class_eval
<<-
RUBY_EVAL
,
__FILE__
,
__LINE__
+
1
...
...
@@ -378,7 +385,7 @@ module ClassMethods
# The _run_save_callbacks method can optionally take a key, which
# will be used to compile an optimized callback method for each
# key. See #define_callbacks for more information.
def
_define_runner
(
symbol
,
str
,
options
)
def
_define_runner
(
symbol
,
str
,
options
)
str
=
<<-
RUBY_EVAL
def _run_
#{
symbol
}
_callbacks(key = nil)
if key
...
...
@@ -492,7 +499,7 @@ def self.skip_#{symbol}_callback(*filters, &blk)
filter = self._
#{
symbol
}
_callbacks.find {|c| c.matches?(type, :
#{
symbol
}
, filter) }
per_key = options[:per_key] || {}
if filter
if filter
&& options.any?
filter.recompile!(options, per_key)
else
self._
#{
symbol
}
_callbacks.delete(filter)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录