Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

5953 sti type is not updatable #98

Closed
wants to merge 1 commit into from

1 participant

@franckverrot

This should fix https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5953

Lighthouse doesnt want my diff so I'm doing a pull request.. I hope this is the new way of doing it :)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
1  activerecord/lib/active_record/persistence.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
View
9 activerecord/test/cases/persistence_test.rb
@@ -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'
Something went wrong with that request. Please try again.