diff options
Diffstat (limited to 'activerecord')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 6 | ||||
-rwxr-xr-x | activerecord/test/cases/base_test.rb | 4 |
2 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 002af07112..e60e990cd6 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1285,11 +1285,15 @@ module ActiveRecord #:nodoc: with_scope(method_scoping, :overwrite, &block) 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] + extra = @@subclasses[self].inject([]) {|list, subclass| list + subclass.subclasses } end + public :subclasses + # Sets the default options for the model. The format of the # <tt>options</tt> argument is the same as in find. # diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 51b6a8aada..8bff13aa96 100755 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -2053,6 +2053,10 @@ class BasicsTest < ActiveRecord::TestCase assert !SubStiPost.descends_from_active_record? 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 old_class = LooseDescendant Object.send :remove_const, :LooseDescendant |