aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/persistence_test.rb
diff options
context:
space:
mode:
authorJonathan del Strother <jon.delStrother@audioboo.fm>2013-12-24 17:23:47 +0000
committerJonathan del Strother <jon.delStrother@audioboo.fm>2013-12-27 15:54:06 +0000
commitb7bf025374324c2b73b3ab270cd4153f18a942b0 (patch)
treedee9ff4133a497b0ebbf2ab93cae3fe604a97014 /activerecord/test/cases/persistence_test.rb
parentdf09ce966e41b53b3d5723c4efb1e7470c452dd8 (diff)
downloadrails-b7bf025374324c2b73b3ab270cd4153f18a942b0.tar.gz
rails-b7bf025374324c2b73b3ab270cd4153f18a942b0.tar.bz2
rails-b7bf025374324c2b73b3ab270cd4153f18a942b0.zip
Copy changed_attributes across to newly become'd records
Without this, the original record's values won't get saved, since the partial insertions support (https://github.com/rails/rails/commit/144e8691cbfb8bba77f18cfe68d5e7fd48887f5e) checks for changed values and thinks there are none.
Diffstat (limited to 'activerecord/test/cases/persistence_test.rb')
-rw-r--r--activerecord/test/cases/persistence_test.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb
index 6cd3e2154e..6f1e518f45 100644
--- a/activerecord/test/cases/persistence_test.rb
+++ b/activerecord/test/cases/persistence_test.rb
@@ -152,6 +152,20 @@ class PersistenceTest < ActiveRecord::TestCase
assert_equal original_errors, client.errors
end
+ def test_dupd_becomes_persists_changes_from_the_original
+ original = topics(:first)
+ copy = original.dup.becomes(Reply)
+ copy.save!
+ assert_equal "The First Topic", Topic.find(copy.id).title
+ end
+
+ def test_becomes_includes_changed_attributes
+ company = Company.new(name: "37signals")
+ client = company.becomes(Client)
+ assert_equal "37signals", client.name
+ assert_equal %w{name}, client.changed
+ end
+
def test_delete_many
original_count = Topic.count
Topic.delete(deleting = [1, 2])