mirror of https://github.com/rails/rails
STI type is now updated when calling AR::Base.becomes on subclasses [#5953 state:resolved]
This commit is contained in:
parent
296e5c38f1
commit
de2933e1a0
|
@ -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
|
||||
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in New Issue