Permalink
Browse files

Subclasses of an abstract class work with single-table inheritance. R…

…eferences #5704, closes #7284.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6013 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 7359dc0 commit 06afb8c7465e6b01833edfbae70547cf03c06480 @jeremy jeremy committed Jan 23, 2007
View
@@ -1,5 +1,7 @@
*SVN*
+* Subclasses of an abstract class work with single-table inheritance. #5704, #7284 [BertG, nick+rails@ag.arizona.edu]
+
* Make sure sqlite3 driver closes open connections on disconnect [Rob Rasmussen]
* [DOC] clear up some ambiguity with the way has_and_belongs_to_many creates the default join table name. #7072 [jeremymcanally]
@@ -817,8 +817,13 @@ def human_attribute_name(attribute_key_name) #:nodoc:
attribute_key_name.humanize
end
- def descends_from_active_record? # :nodoc:
- superclass == Base || !columns_hash.include?(inheritance_column)
+ # True if this isn't a concrete subclass needing a STI type condition.
+ def descends_from_active_record?
+ if superclass.abstract_class?
+ superclass.descends_from_active_record?
+ else
+ superclass == Base || !columns_hash.include?(inheritance_column)
+ end
end
@@ -1,4 +1,8 @@
-class Company < ActiveRecord::Base
+class AbstractCompany < ActiveRecord::Base
+ self.abstract_class = true
+end
+
+class Company < AbstractCompany
attr_protected :rating
set_sequence_name :companies_nonstd_seq
@@ -6,6 +6,13 @@
class InheritanceTest < Test::Unit::TestCase
fixtures :companies, :projects, :subscribers, :accounts
+ def test_company_descends_from_active_record
+ assert_raise(NoMethodError) { ActiveRecord::Base.descends_from_active_record? }
+ assert AbstractCompany.descends_from_active_record?, 'AbstractCompany should descend from ActiveRecord::Base'
+ assert Company.descends_from_active_record?, 'Company should descend from ActiveRecord::Base'
+ assert !Class.new(Company).descends_from_active_record?, 'Company subclass should not descend from ActiveRecord::Base'
+ end
+
def test_a_bad_type_column
#SQLServer need to turn Identity Insert On before manually inserting into the Identity column
if current_adapter?(:SQLServerAdapter, :SybaseAdapter)

0 comments on commit 06afb8c

Please sign in to comment.