diff options
Diffstat (limited to 'activerecord/test/cases/yaml_serialization_test.rb')
-rw-r--r-- | activerecord/test/cases/yaml_serialization_test.rb | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/activerecord/test/cases/yaml_serialization_test.rb b/activerecord/test/cases/yaml_serialization_test.rb index 56909a8630..5192e5050a 100644 --- a/activerecord/test/cases/yaml_serialization_test.rb +++ b/activerecord/test/cases/yaml_serialization_test.rb @@ -1,15 +1,15 @@ -require 'cases/helper' -require 'models/topic' -require 'models/reply' -require 'models/post' -require 'models/author' +require "cases/helper" +require "models/topic" +require "models/reply" +require "models/post" +require "models/author" class YamlSerializationTest < ActiveRecord::TestCase fixtures :topics, :authors, :posts def test_to_yaml_with_time_with_zone_should_not_raise_exception with_timezone_config aware_attributes: true, zone: "Pacific Time (US & Canada)" do - topic = Topic.new(:written_on => DateTime.now) + topic = Topic.new(written_on: DateTime.now) assert_nothing_raised { topic.to_yaml } end end @@ -22,8 +22,8 @@ class YamlSerializationTest < ActiveRecord::TestCase end def test_roundtrip_serialized_column - topic = Topic.new(:content => {:omg=>:lol}) - assert_equal({:omg=>:lol}, YAML.load(YAML.dump(topic)).content) + topic = Topic.new(content: { omg: :lol }) + assert_equal({ omg: :lol }, YAML.load(YAML.dump(topic)).content) end def test_psych_roundtrip @@ -67,16 +67,16 @@ class YamlSerializationTest < ActiveRecord::TestCase 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 + 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 def test_types_of_virtual_columns_are_not_changed_on_round_trip - author = Author.select('authors.*, count(posts.id) as posts_count') + author = Author.select("authors.*, count(posts.id) as posts_count") .joins(:posts) - .group('authors.id') + .group("authors.id") .first dumped = YAML.load(YAML.dump(author)) @@ -88,7 +88,7 @@ class YamlSerializationTest < ActiveRecord::TestCase coder = {} Topic.first.encode_with(coder) - assert coder['active_record_yaml_version'] + assert coder["active_record_yaml_version"] end def test_deserializing_rails_41_yaml @@ -109,13 +109,23 @@ class YamlSerializationTest < ActiveRecord::TestCase assert_equal("Have a nice day", topic.content) end - private + def test_yaml_encoding_keeps_mutations + author = Author.first + author.name = "Sean" + dumped = YAML.load(YAML.dump(author)) - def yaml_fixture(file_name) - path = File.expand_path( - "../../support/yaml_compatibility_fixtures/#{file_name}.yml", - __FILE__ - ) - File.read(path) + assert_equal "Sean", dumped.name + assert_equal author.name_was, dumped.name_was + assert_equal author.changes, dumped.changes end + + private + + def yaml_fixture(file_name) + path = File.expand_path( + "../../support/yaml_compatibility_fixtures/#{file_name}.yml", + __FILE__ + ) + File.read(path) + end end |