Permalink
Browse files

STI type is now updated when calling AR::Base.becomes on subclasses [#…

…5953 state:resolved]
  • Loading branch information...
1 parent 296e5c3 commit e781853208b78c1106c567bb305fba885f3aec7d @franckverrot committed Nov 11, 2010
Showing with 10 additions and 0 deletions.
  1. +1 −0 activerecord/lib/active_record/persistence.rb
  2. +9 −0 activerecord/test/cases/persistence_test.rb
@@ -96,6 +96,7 @@ def becomes(klass)
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
@@ -241,6 +241,15 @@ def test_update_for_record_with_only_primary_key
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'

0 comments on commit e781853

Please sign in to comment.