Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7284: AbstractClassAndInheritancePatch.diff

File AbstractClassAndInheritancePatch.diff, 2.0 kB (added by BertG, 2 years ago)
  • activerecord/test/inheritance_test.rb

    old new  
    55 
    66class InheritanceTest < Test::Unit::TestCase 
    77  fixtures :companies, :projects, :subscribers, :accounts 
    8  
     8   
     9  def test_company_descends_from_active_record 
     10    assert Company.descends_from_active_record?, 'Company should descend from ActiveRecord' 
     11  end 
     12   
    913  def test_a_bad_type_column 
    1014    #SQLServer need to turn Identity Insert On before manually inserting into the Identity column 
    1115    if current_adapter?(:SQLServerAdapter, :SybaseAdapter) 
  • activerecord/test/fixtures/company.rb

    old new  
    1 class Company < ActiveRecord::Base 
     1class AbstractCompany < ActiveRecord::Base 
     2  self.abstract_class = true 
     3end 
     4 
     5class Company < AbstractCompany 
    26  attr_protected :rating 
    37  set_sequence_name :companies_nonstd_seq 
    48 
  • activerecord/lib/active_record/base.rb

    old new  
    816816      def human_attribute_name(attribute_key_name) #:nodoc: 
    817817        attribute_key_name.humanize 
    818818      end 
    819  
    820       def descends_from_active_record? # :nodoc: 
    821         superclass == Base || !columns_hash.include?(inheritance_column) 
     819       
     820      # Returns true when the class is the first non-abstract class to descend from ActiveRecord::Base  
     821      def descends_from_active_record? 
     822        if superclass.abstract_class? 
     823          superclass.descends_from_active_record? 
     824        else 
     825          superclass == Base || !columns_hash.include?(inheritance_column) 
     826        end 
    822827      end 
    823828 
    824829