Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c7c35be8
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,发现更多精彩内容 >>
提交
c7c35be8
编写于
5月 29, 2009
作者:
J
Joshua Peek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
AS::Concern includes InstanceMethods module if it exists
上级
69742ca8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
15 addition
and
12 deletion
+15
-12
actionpack/lib/action_controller/base/chained/filters.rb
actionpack/lib/action_controller/base/chained/filters.rb
+1
-6
activerecord/lib/active_record/validations.rb
activerecord/lib/active_record/validations.rb
+0
-2
activesupport/lib/active_support/concern.rb
activesupport/lib/active_support/concern.rb
+1
-0
activesupport/test/concern_test.rb
activesupport/test/concern_test.rb
+13
-4
未找到文件。
actionpack/lib/action_controller/base/chained/filters.rb
浏览文件 @
c7c35be8
module
ActionController
#:nodoc:
module
Filters
#:nodoc:
def
self
.
included
(
base
)
base
.
class_eval
do
extend
ClassMethods
include
ActionController
::
Filters
::
InstanceMethods
end
end
extend
ActiveSupport
::
Concern
class
FilterChain
<
ActiveSupport
::
Callbacks
::
CallbackChain
#:nodoc:
def
append_filter_to_chain
(
filters
,
filter_type
,
&
block
)
...
...
activerecord/lib/active_record/validations.rb
浏览文件 @
c7c35be8
...
...
@@ -106,8 +106,6 @@ module Validations
depends_on
ActiveModel
::
Validations
included
do
include
Validations
::
InstanceMethods
alias_method_chain
:save
,
:validation
alias_method_chain
:save!
,
:validation
...
...
activesupport/lib/active_support/concern.rb
浏览文件 @
c7c35be8
...
...
@@ -7,6 +7,7 @@ module Concern
def
append_features
(
base
)
if
super
base
.
extend
const_get
(
"ClassMethods"
)
if
const_defined?
(
"ClassMethods"
)
base
.
send
:include
,
const_get
(
"InstanceMethods"
)
if
const_defined?
(
"InstanceMethods"
)
base
.
class_eval
(
&
@_included_block
)
if
instance_variable_defined?
(
"@_included_block"
)
end
end
...
...
activesupport/test/concern_test.rb
浏览文件 @
c7c35be8
...
...
@@ -19,6 +19,9 @@ def included_ran
end
end
module
InstanceMethods
end
included
do
self
.
included_ran
=
true
end
...
...
@@ -55,11 +58,11 @@ def setup
def
test_module_is_included_normally
@klass
.
send
(
:include
,
Baz
)
assert_equal
"baz"
,
@klass
.
new
.
baz
assert
_equal
ConcernTest
::
Baz
,
@klass
.
included_modules
[
0
]
assert
@klass
.
included_modules
.
include?
(
ConcernTest
::
Baz
)
@klass
.
send
(
:include
,
Baz
)
assert_equal
"baz"
,
@klass
.
new
.
baz
assert
_equal
ConcernTest
::
Baz
,
@klass
.
included_modules
[
0
]
assert
@klass
.
included_modules
.
include?
(
ConcernTest
::
Baz
)
end
def
test_class_methods_are_extended
...
...
@@ -68,6 +71,12 @@ def test_class_methods_are_extended
assert_equal
ConcernTest
::
Baz
::
ClassMethods
,
(
class
<<
@klass
;
self
.
included_modules
;
end
)[
0
]
end
def
test_instance_methods_are_included
@klass
.
send
(
:include
,
Baz
)
assert_equal
"baz"
,
@klass
.
new
.
baz
assert
@klass
.
included_modules
.
include?
(
ConcernTest
::
Baz
::
InstanceMethods
)
end
def
test_included_block_is_ran
@klass
.
send
(
:include
,
Baz
)
assert_equal
true
,
@klass
.
included_ran
...
...
@@ -78,11 +87,11 @@ def test_modules_dependencies_are_met
assert_equal
"bar"
,
@klass
.
new
.
bar
assert_equal
"bar+baz"
,
@klass
.
new
.
baz
assert_equal
"baz"
,
@klass
.
baz
assert
_equal
[
ConcernTest
::
Bar
,
ConcernTest
::
Baz
],
@klass
.
included_modules
[
0
..
1
]
assert
@klass
.
included_modules
.
include?
(
ConcernTest
::
Bar
)
end
def
test_depends_on_with_multiple_modules
@klass
.
send
(
:include
,
Foo
)
assert_equal
[
ConcernTest
::
Foo
,
ConcernTest
::
Bar
,
ConcernTest
::
Baz
],
@klass
.
included_modules
[
0
..
2
]
assert_equal
[
ConcernTest
::
Foo
,
ConcernTest
::
Bar
,
ConcernTest
::
Baz
::
InstanceMethods
,
ConcernTest
::
Baz
],
@klass
.
included_modules
[
0
..
3
]
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录