aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorGuillermo Iguaran <guilleiguaran@gmail.com>2014-06-01 18:53:46 -0500
committerGuillermo Iguaran <guilleiguaran@gmail.com>2014-06-01 18:53:46 -0500
commitfab8d0795a4213e9210c7aa88d3b5653232bb221 (patch)
treee61c768fa2fc42e612c17b2fb19e758d062a454d /activerecord/test
parent87cc918daab39174c82b0aeb617fb8e4b4f107fb (diff)
parente08494a912c89b1eb444c5c358e9aa880b2e4c66 (diff)
downloadrails-fab8d0795a4213e9210c7aa88d3b5653232bb221.tar.gz
rails-fab8d0795a4213e9210c7aa88d3b5653232bb221.tar.bz2
rails-fab8d0795a4213e9210c7aa88d3b5653232bb221.zip
Merge pull request #15444 from sgrif/sg-yaml-new-record
New records should remain new after yaml serialization
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/yaml_serialization_test.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/activerecord/test/cases/yaml_serialization_test.rb b/activerecord/test/cases/yaml_serialization_test.rb
index f7af9a35cd..d4f8ef5b4d 100644
--- a/activerecord/test/cases/yaml_serialization_test.rb
+++ b/activerecord/test/cases/yaml_serialization_test.rb
@@ -52,4 +52,21 @@ class YamlSerializationTest < ActiveRecord::TestCase
assert_equal 123, topic.parent_id
assert_equal 123, YAML.load(YAML.dump(topic)).parent_id
end
+
+ def test_new_records_remain_new_after_round_trip
+ topic = Topic.new
+
+ assert topic.new_record?, "Sanity check that new records are new"
+ assert YAML.load(YAML.dump(topic)).new_record?, "Record should be new after deserialization"
+
+ topic.save!
+
+ assert_not topic.new_record?, "Saved records are not new"
+ assert_not YAML.load(YAML.dump(topic)).new_record?, "Saved record should not be new after deserialization"
+
+ topic = Topic.select('title').last
+
+ assert_not topic.new_record?, "Loaded records without ID are not new"
+ assert_not YAML.load(YAML.dump(topic)).new_record?, "Record should not be new after deserialization"
+ end
end