type_name should check for blank because people may have messed up databases

This commit is contained in:
Aaron Patterson 2010-09-30 16:02:49 -07:00
parent 15419a5dc6
commit 0238228e5d
2 changed files with 15 additions and 1 deletions

View File

@ -890,7 +890,7 @@ module ActiveRecord #:nodoc:
end
def find_sti_class(type_name)
if type_name.nil? || !columns_hash.include?(inheritance_column)
if type_name.blank? || !columns_hash.include?(inheritance_column)
self
else
begin

View File

@ -14,6 +14,20 @@ class InheritanceTest < ActiveRecord::TestCase
ActiveRecord::Base.store_full_sti_class = old
end
def test_class_with_blank_sti_name
company = Company.find(:first)
company = company.clone
company.extend(Module.new {
def read_attribute(name)
return ' ' if name == 'type'
super
end
})
company.save!
company = Company.find(:all).find { |x| x.id == company.id }
assert_equal ' ', company.type
end
def test_class_without_store_full_sti_class_returns_demodulized_name
old = ActiveRecord::Base.store_full_sti_class
ActiveRecord::Base.store_full_sti_class = false