Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
5fb94ec0
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,体验更适合开发者的 AI 搜索 >>
提交
5fb94ec0
编写于
12月 07, 2012
作者:
F
Francesco Rodriguez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use `_action` instead of `_filter` callbacks
上级
9cb91f93
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
32 addition
and
34 deletion
+32
-34
actionpack/lib/action_controller/metal/request_forgery_protection.rb
...lib/action_controller/metal/request_forgery_protection.rb
+6
-6
actionpack/lib/action_dispatch/http/mime_negotiation.rb
actionpack/lib/action_dispatch/http/mime_negotiation.rb
+2
-2
actionpack/test/abstract/callbacks_test.rb
actionpack/test/abstract/callbacks_test.rb
+19
-21
actionpack/test/controller/flash_test.rb
actionpack/test/controller/flash_test.rb
+3
-3
actionpack/test/controller/rescue_test.rb
actionpack/test/controller/rescue_test.rb
+2
-2
未找到文件。
actionpack/lib/action_controller/metal/request_forgery_protection.rb
浏览文件 @
5fb94ec0
...
...
@@ -19,7 +19,7 @@ class InvalidAuthenticityToken < ActionControllerError #:nodoc:
#
# class ApplicationController < ActionController::Base
# protect_from_forgery
# skip_before_
filter
:verify_authenticity_token, if: :json_request?
# skip_before_
action
:verify_authenticity_token, if: :json_request?
#
# protected
#
...
...
@@ -66,15 +66,15 @@ module ClassMethods
#
# You can disable csrf protection on controller-by-controller basis:
#
# skip_before_
filter
:verify_authenticity_token
# skip_before_
action
:verify_authenticity_token
#
# It can also be disabled for specific controller actions:
#
# skip_before_
filter
:verify_authenticity_token, except: [:create]
# skip_before_
action
:verify_authenticity_token, except: [:create]
#
# Valid Options:
#
# * <tt>:only/:except</tt> - Passed to the <tt>before_
filter
</tt> call. Set which actions are verified.
# * <tt>:only/:except</tt> - Passed to the <tt>before_
action
</tt> call. Set which actions are verified.
# * <tt>:with</tt> - Set the method to handle unverified request.
#
# Valid unverified request handling methods are:
...
...
@@ -84,7 +84,7 @@ module ClassMethods
def
protect_from_forgery
(
options
=
{})
include
protection_method_module
(
options
[
:with
]
||
:null_session
)
self
.
request_forgery_protection_token
||=
:authenticity_token
prepend_before_
filter
:verify_authenticity_token
,
options
prepend_before_
action
:verify_authenticity_token
,
options
end
private
...
...
@@ -152,7 +152,7 @@ def handle_unverified_request
end
protected
# The actual before_
filter
that is used. Modify this to change how you handle unverified requests.
# The actual before_
action
that is used. Modify this to change how you handle unverified requests.
def
verify_authenticity_token
unless
verified_request?
logger
.
warn
"Can't verify CSRF token authenticity"
if
logger
...
...
actionpack/lib/action_dispatch/http/mime_negotiation.rb
浏览文件 @
5fb94ec0
...
...
@@ -68,7 +68,7 @@ def formats
# that are not controlled by the extension.
#
# class ApplicationController < ActionController::Base
# before_
filter
:adjust_format_for_iphone
# before_
action
:adjust_format_for_iphone
#
# private
# def adjust_format_for_iphone
...
...
@@ -87,7 +87,7 @@ def format=(extension)
# to the :html format.
#
# class ApplicationController < ActionController::Base
# before_
filter
:adjust_format_for_iphone_with_html_fallback
# before_
action
:adjust_format_for_iphone_with_html_fallback
#
# private
# def adjust_format_for_iphone_with_html_fallback
...
...
actionpack/test/abstract/callbacks_test.rb
浏览文件 @
5fb94ec0
...
...
@@ -28,9 +28,9 @@ class TestCallbacks1 < ActiveSupport::TestCase
end
class
Callback2
<
ControllerWithCallbacks
before_
filter
:first
after_
filter
:second
around_
filter
:aroundz
before_
action
:first
after_
action
:second
around_
action
:aroundz
def
first
@text
=
"Hello world"
...
...
@@ -53,7 +53,7 @@ def index
end
class
Callback2Overwrite
<
Callback2
before_
filter
:first
,
:except
=>
:index
before_
action
:first
,
except:
:index
end
class
TestCallbacks2
<
ActiveSupport
::
TestCase
...
...
@@ -61,22 +61,22 @@ def setup
@controller
=
Callback2
.
new
end
test
"before_
filter
works"
do
test
"before_
action
works"
do
@controller
.
process
(
:index
)
assert_equal
"Hello world"
,
@controller
.
response_body
end
test
"after_
filter
works"
do
test
"after_
action
works"
do
@controller
.
process
(
:index
)
assert_equal
"Goodbye"
,
@controller
.
instance_variable_get
(
"@second"
)
end
test
"around_
filter
works"
do
test
"around_
action
works"
do
@controller
.
process
(
:index
)
assert_equal
"FIRSTSECOND"
,
@controller
.
instance_variable_get
(
"@aroundz"
)
end
test
"before_
filter
with overwritten condition"
do
test
"before_
action
with overwritten condition"
do
@controller
=
Callback2Overwrite
.
new
@controller
.
process
(
:index
)
assert_equal
""
,
@controller
.
response_body
...
...
@@ -102,12 +102,12 @@ def setup
@controller
=
Callback3
.
new
end
test
"before_
filter
works with procs"
do
test
"before_
action
works with procs"
do
@controller
.
process
(
:index
)
assert_equal
"Hello world"
,
@controller
.
response_body
end
test
"after_
filter
works with procs"
do
test
"after_
action
works with procs"
do
@controller
.
process
(
:index
)
assert_equal
"Goodbye"
,
@controller
.
instance_variable_get
(
"@second"
)
end
...
...
@@ -141,25 +141,25 @@ def setup
@controller
=
CallbacksWithConditions
.
new
end
test
"when :only is specified, a before
filter
is triggered on that action"
do
test
"when :only is specified, a before
action
is triggered on that action"
do
@controller
.
process
(
:index
)
assert_equal
"Hello, World"
,
@controller
.
response_body
end
test
"when :only is specified, a before
filter
is not triggered on other actions"
do
test
"when :only is specified, a before
action
is not triggered on other actions"
do
@controller
.
process
(
:sekrit_data
)
assert_equal
"true"
,
@controller
.
response_body
end
test
"when :except is specified, an after
filter
is not triggered on that action"
do
test
"when :except is specified, an after
action
is not triggered on that action"
do
@controller
.
process
(
:index
)
assert
!
@controller
.
instance_variable_defined?
(
"@authenticated"
)
end
end
class
CallbacksWithArrayConditions
<
ControllerWithCallbacks
before_
filter
:list
,
:only
=>
[
:index
,
:listy
]
before_
filter
:authenticate
,
:except
=>
[
:index
,
:listy
]
before_
action
:list
,
only:
[
:index
,
:listy
]
before_
action
:authenticate
,
except:
[
:index
,
:listy
]
def
index
self
.
response_body
=
@list
.
join
(
", "
)
...
...
@@ -185,17 +185,17 @@ def setup
@controller
=
CallbacksWithArrayConditions
.
new
end
test
"when :only is specified with an array, a before
filter
is triggered on that action"
do
test
"when :only is specified with an array, a before
action
is triggered on that action"
do
@controller
.
process
(
:index
)
assert_equal
"Hello, World"
,
@controller
.
response_body
end
test
"when :only is specified with an array, a before
filter
is not triggered on other actions"
do
test
"when :only is specified with an array, a before
action
is not triggered on other actions"
do
@controller
.
process
(
:sekrit_data
)
assert_equal
"true"
,
@controller
.
response_body
end
test
"when :except is specified with an array, an after
filter
is not triggered on that action"
do
test
"when :except is specified with an array, an after
action
is not triggered on that action"
do
@controller
.
process
(
:index
)
assert
!
@controller
.
instance_variable_defined?
(
"@authenticated"
)
end
...
...
@@ -227,7 +227,7 @@ def setup
end
class
SetsResponseBody
<
ControllerWithCallbacks
before_
filter
:set_body
before_
action
:set_body
def
index
self
.
response_body
=
"Fail"
...
...
@@ -265,7 +265,5 @@ class TestCallbacksWithArgs < ActiveSupport::TestCase
assert_equal
"Hello world Howdy!"
,
controller
.
response_body
end
end
end
end
actionpack/test/controller/flash_test.rb
浏览文件 @
5fb94ec0
...
...
@@ -53,8 +53,8 @@ def use_flash_after_reset_session
render
:inline
=>
"hello"
end
# methods for test_sweep_after_halted_
filter
_chain
before_
filter
:halt_and_redir
,
:only
=>
"filter_halting_action"
# methods for test_sweep_after_halted_
action
_chain
before_
action
:halt_and_redir
,
only:
'filter_halting_action'
def
std_action
@flash_copy
=
{}.
update
(
flash
)
...
...
@@ -159,7 +159,7 @@ def test_does_not_set_the_session_if_the_flash_is_empty
assert_nil
session
[
"flash"
]
end
def
test_sweep_after_halted_
filter
_chain
def
test_sweep_after_halted_
action
_chain
get
:std_action
assert_nil
assigns
[
"flash_copy"
][
"foo"
]
get
:filter_halting_action
...
...
actionpack/test/controller/rescue_test.rb
浏览文件 @
5fb94ec0
...
...
@@ -68,9 +68,9 @@ class ResourceUnavailableToRescueAsString < StandardError
render
:text
=>
'io error'
end
before_action
(
only: :before_
filter
_raises
)
{
raise
'umm nice'
}
before_action
(
only: :before_
action
_raises
)
{
raise
'umm nice'
}
def
before_
filter
_raises
def
before_
action
_raises
end
def
raises
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录