Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
46c853f3
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,发现更多精彩内容 >>
提交
46c853f3
编写于
1月 08, 2015
作者:
D
David Heinemeier Hansson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #18371 from brainopia/remove_hide_actions
Remove ActionController::HideActions (closes #18336)
上级
17136c20
08d3f0e3
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
7 addition
and
93 deletion
+7
-93
actionpack/CHANGELOG.md
actionpack/CHANGELOG.md
+4
-0
actionpack/lib/abstract_controller/base.rb
actionpack/lib/abstract_controller/base.rb
+2
-14
actionpack/lib/action_controller/base.rb
actionpack/lib/action_controller/base.rb
+0
-1
actionpack/lib/action_controller/metal/hide_actions.rb
actionpack/lib/action_controller/metal/hide_actions.rb
+0
-40
actionpack/test/controller/base_test.rb
actionpack/test/controller/base_test.rb
+1
-38
未找到文件。
actionpack/CHANGELOG.md
浏览文件 @
46c853f3
*
Remove
`ActionController::HideActions`
*Ravil Bayramgalin*
*
Remove
`respond_to`
/
`respond_with`
placeholder methods, this functionality
has been extracted to the
`responders`
gem.
...
...
actionpack/lib/abstract_controller/base.rb
浏览文件 @
46c853f3
...
...
@@ -57,21 +57,11 @@ def internal_methods
controller
.
public_instance_methods
(
true
)
end
# The list of hidden actions. Defaults to an empty array.
# This can be modified by other modules or subclasses
# to specify particular actions as hidden.
#
# ==== Returns
# * <tt>Array</tt> - An array of method names that should not be considered actions.
def
hidden_actions
[]
end
# A list of method names that should be considered actions. This
# includes all public instance methods on a controller, less
# any internal methods (see internal_methods), adding back in
# any methods that are internal, but still exist on the class
# itself.
Finally, hidden_actions are removed.
# itself.
#
# ==== Returns
# * <tt>Set</tt> - A set of all methods that should be considered actions.
...
...
@@ -82,9 +72,7 @@ def action_methods
# Except for public instance methods of Base and its ancestors
internal_methods
+
# Be sure to include shadowed public instance methods of this class
public_instance_methods
(
false
)).
uniq
.
map
(
&
:to_s
)
-
# And always exclude explicitly hidden actions
hidden_actions
.
to_a
public_instance_methods
(
false
)).
uniq
.
map
(
&
:to_s
)
methods
.
to_set
end
...
...
actionpack/lib/action_controller/base.rb
浏览文件 @
46c853f3
...
...
@@ -206,7 +206,6 @@ def self.without_modules(*modules)
AbstractController
::
AssetPaths
,
Helpers
,
HideActions
,
UrlFor
,
Redirecting
,
ActionView
::
Layouts
,
...
...
actionpack/lib/action_controller/metal/hide_actions.rb
已删除
100644 → 0
浏览文件 @
17136c20
module
ActionController
# Adds the ability to prevent public methods on a controller to be called as actions.
module
HideActions
extend
ActiveSupport
::
Concern
included
do
class_attribute
:hidden_actions
self
.
hidden_actions
=
Set
.
new
.
freeze
end
private
# Overrides AbstractController::Base#action_method? to return false if the
# action name is in the list of hidden actions.
def
method_for_action
(
action_name
)
self
.
class
.
visible_action?
(
action_name
)
&&
super
end
module
ClassMethods
# Sets all of the actions passed in as hidden actions.
#
# ==== Parameters
# * <tt>args</tt> - A list of actions
def
hide_action
(
*
args
)
self
.
hidden_actions
=
hidden_actions
.
dup
.
merge
(
args
.
map
(
&
:to_s
)).
freeze
end
def
visible_action?
(
action_name
)
not
hidden_actions
.
include?
(
action_name
)
end
# Overrides AbstractController::Base#action_methods to remove any methods
# that are listed as hidden methods.
def
action_methods
@action_methods
||=
Set
.
new
(
super
.
reject
{
|
name
|
hidden_actions
.
include?
(
name
)
}).
freeze
end
end
end
end
actionpack/test/controller/base_test.rb
浏览文件 @
46c853f3
require
'abstract_unit'
require
'active_support/logger'
require
'controller/fake_models'
require
'pp'
# require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late
# Provide some controller to run the tests on.
module
Submodule
class
ContainedEmptyController
<
ActionController
::
Base
end
class
ContainedNonEmptyController
<
ActionController
::
Base
def
public_action
render
:nothing
=>
true
end
hide_action
:hidden_action
def
hidden_action
raise
"Noooo!"
end
def
another_hidden_action
end
hide_action
:another_hidden_action
end
class
SubclassedController
<
ContainedNonEmptyController
hide_action
:public_action
# Hiding it here should not affect the superclass.
end
end
class
EmptyController
<
ActionController
::
Base
...
...
@@ -35,10 +15,6 @@ class NonEmptyController < ActionController::Base
def
public_action
render
:nothing
=>
true
end
hide_action
:hidden_action
def
hidden_action
end
end
class
DefaultUrlOptionsController
<
ActionController
::
Base
...
...
@@ -108,10 +84,7 @@ class ControllerInstanceTests < ActiveSupport::TestCase
def
setup
@empty
=
EmptyController
.
new
@contained
=
Submodule
::
ContainedEmptyController
.
new
@empty_controllers
=
[
@empty
,
@contained
,
Submodule
::
SubclassedController
.
new
]
@non_empty_controllers
=
[
NonEmptyController
.
new
,
Submodule
::
ContainedNonEmptyController
.
new
]
@empty_controllers
=
[
@empty
,
@contained
]
end
def
test_performed?
...
...
@@ -124,10 +97,6 @@ def test_action_methods
@empty_controllers
.
each
do
|
c
|
assert_equal
Set
.
new
,
c
.
class
.
action_methods
,
"
#{
c
.
controller_path
}
should be empty!"
end
@non_empty_controllers
.
each
do
|
c
|
assert_equal
Set
.
new
(
%w(public_action)
),
c
.
class
.
action_methods
,
"
#{
c
.
controller_path
}
should not be empty!"
end
end
def
test_temporary_anonymous_controllers
...
...
@@ -161,12 +130,6 @@ def test_process_should_be_precise
assert_equal
"The action 'non_existent' could not be found for EmptyController"
,
exception
.
message
end
def
test_get_on_hidden_should_fail
use_controller
NonEmptyController
assert_raise
(
AbstractController
::
ActionNotFound
)
{
get
:hidden_action
}
assert_raise
(
AbstractController
::
ActionNotFound
)
{
get
:another_hidden_action
}
end
def
test_action_missing_should_work
use_controller
ActionMissingController
get
:arbitrary_action
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录