提交 f8eddcc7 编写于 作者: E Emmanuel Oga 提交者: wycats

make ActiveRecord::Base.subclasses a public method

Signed-off-by: Nwycats <wycats@gmail.com>
上级 219c81b9
...@@ -1285,11 +1285,15 @@ def with_exclusive_scope(method_scoping = {}, &block) ...@@ -1285,11 +1285,15 @@ def with_exclusive_scope(method_scoping = {}, &block)
with_scope(method_scoping, :overwrite, &block) with_scope(method_scoping, :overwrite, &block)
end end
def subclasses #:nodoc: # ActiveRecord::Base utilizes the inherited hook to know about new subclasses.
# You can access the list of currently loaded ActiveRecord::Base subclasses using this accessor.
def subclasses
@@subclasses[self] ||= [] @@subclasses[self] ||= []
@@subclasses[self] + extra = @@subclasses[self].inject([]) {|list, subclass| list + subclass.subclasses } @@subclasses[self] + extra = @@subclasses[self].inject([]) {|list, subclass| list + subclass.subclasses }
end end
public :subclasses
# Sets the default options for the model. The format of the # Sets the default options for the model. The format of the
# <tt>options</tt> argument is the same as in find. # <tt>options</tt> argument is the same as in find.
# #
......
...@@ -2053,6 +2053,10 @@ def test_descends_from_active_record ...@@ -2053,6 +2053,10 @@ def test_descends_from_active_record
assert !SubStiPost.descends_from_active_record? assert !SubStiPost.descends_from_active_record?
end end
def test_base_subclasses_is_public_method
assert ActiveRecord::Base.public_methods.include?("subclasses")
end
def test_find_on_abstract_base_class_doesnt_use_type_condition def test_find_on_abstract_base_class_doesnt_use_type_condition
old_class = LooseDescendant old_class = LooseDescendant
Object.send :remove_const, :LooseDescendant Object.send :remove_const, :LooseDescendant
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册