Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
fbef982e
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,发现更多精彩内容 >>
提交
fbef982e
编写于
7月 15, 2008
作者:
S
Stefan Kaes
提交者:
Jeremy Kemper
7月 15, 2008
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Observers not longer add an after_find method to the observed class.
[#625 state:resolved]
上级
c7acfbb2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
14 addition
and
7 deletion
+14
-7
activerecord/lib/active_record/observer.rb
activerecord/lib/active_record/observer.rb
+4
-5
activerecord/test/cases/lifecycle_test.rb
activerecord/test/cases/lifecycle_test.rb
+10
-2
未找到文件。
activerecord/lib/active_record/observer.rb
浏览文件 @
fbef982e
...
@@ -20,7 +20,7 @@ module ClassMethods
...
@@ -20,7 +20,7 @@ module ClassMethods
# ActiveRecord::Base.observers = Cacher, GarbageCollector
# ActiveRecord::Base.observers = Cacher, GarbageCollector
#
#
# Note: Setting this does not instantiate the observers yet. +instantiate_observers+ is
# Note: Setting this does not instantiate the observers yet. +instantiate_observers+ is
# called during startup, and before each development request.
# called during startup, and before each development request.
def
observers
=
(
*
observers
)
def
observers
=
(
*
observers
)
@observers
=
observers
.
flatten
@observers
=
observers
.
flatten
end
end
...
@@ -130,11 +130,11 @@ def inherited(subclass)
...
@@ -130,11 +130,11 @@ def inherited(subclass)
# Observers register themselves in the model class they observe, since it is the class that
# Observers register themselves in the model class they observe, since it is the class that
# notifies them of events when they occur. As a side-effect, when an observer is loaded its
# notifies them of events when they occur. As a side-effect, when an observer is loaded its
# corresponding model class is loaded.
# corresponding model class is loaded.
#
#
# Up to (and including) Rails 2.0.2 observers were instantiated between plugins and
# Up to (and including) Rails 2.0.2 observers were instantiated between plugins and
# application initializers. Now observers are loaded after application initializers,
# application initializers. Now observers are loaded after application initializers,
# so observed models can make use of extensions.
# so observed models can make use of extensions.
#
#
# If by any chance you are using observed models in the initialization you can still
# If by any chance you are using observed models in the initialization you can still
# load their observers by calling <tt>ModelObserver.instance</tt> before. Observers are
# load their observers by calling <tt>ModelObserver.instance</tt> before. Observers are
# singletons and that call instantiates and registers them.
# singletons and that call instantiates and registers them.
...
@@ -189,7 +189,6 @@ def observed_subclasses
...
@@ -189,7 +189,6 @@ def observed_subclasses
def
add_observer!
(
klass
)
def
add_observer!
(
klass
)
klass
.
add_observer
(
self
)
klass
.
add_observer
(
self
)
klass
.
class_eval
'def after_find() end'
unless
klass
.
method_defined?
(
:after_find
)
end
end
end
end
end
end
activerecord/test/cases/lifecycle_test.rb
浏览文件 @
fbef982e
...
@@ -143,12 +143,20 @@ def test_observing_subclasses
...
@@ -143,12 +143,20 @@ def test_observing_subclasses
assert_equal
developer
.
name
,
multi_observer
.
record
.
name
assert_equal
developer
.
name
,
multi_observer
.
record
.
name
end
end
def
test_
observing_after_find_when
_not_defined_on_the_model
def
test_
after_find_cannot_be_observed_when_its
_not_defined_on_the_model
observer
=
MinimalisticObserver
.
instance
observer
=
MinimalisticObserver
.
instance
assert_equal
Minimalistic
,
MinimalisticObserver
.
observed_class
assert_equal
Minimalistic
,
MinimalisticObserver
.
observed_class
minimalistic
=
Minimalistic
.
find
(
1
)
minimalistic
=
Minimalistic
.
find
(
1
)
assert_equal
minimalistic
,
observer
.
minimalistic
assert_nil
observer
.
minimalistic
end
def
test_after_find_can_be_observed_when_its_defined_on_the_model
observer
=
TopicObserver
.
instance
assert_equal
Topic
,
TopicObserver
.
observed_class
topic
=
Topic
.
find
(
1
)
assert_equal
topic
,
observer
.
topic
end
end
def
test_invalid_observer
def
test_invalid_observer
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录