STI type is now updated when calling AR::Base.becomes on subclasses [#5953 state:resolved]

This commit is contained in:
Franck Verrot 2010-11-12 01:37:12 +08:00 committed by José Valim
parent 296e5c38f1
commit de2933e1a0
2 changed files with 10 additions and 0 deletions

View File

@ -96,6 +96,7 @@ module ActiveRecord
became.instance_variable_set("@attributes_cache", @attributes_cache)
became.instance_variable_set("@persisted", persisted?)
became.instance_variable_set("@destroyed", destroyed?)
became.type = klass.name unless self.class.descends_from_active_record?
became
end

View File

@ -241,6 +241,15 @@ class PersistencesTest < ActiveRecord::TestCase
assert_nothing_raised { minimalistic.save }
end
def test_update_sti_type
assert_instance_of Reply, topics(:second)
topic = topics(:second).becomes(Topic)
assert_instance_of Topic, topic
topic.save!
assert_instance_of Topic, Topic.find(topic.id)
end
def test_delete
topic = Topic.find(1)
assert_equal topic, topic.delete, 'topic.delete did not return self'