aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/yaml_serialization_test.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2015-03-10 11:54:17 -0600
committerSean Griffin <sean@thoughtbot.com>2015-03-10 11:56:45 -0600
commit4e7217027f1933d5860ba459b3d23f454272f709 (patch)
treeaf7c4945c79c3abf42099d4bcec012b01280dc6f /activerecord/test/cases/yaml_serialization_test.rb
parentafc124c3b417b5327ed4d85dc34393f3d19bfbcf (diff)
downloadrails-4e7217027f1933d5860ba459b3d23f454272f709.tar.gz
rails-4e7217027f1933d5860ba459b3d23f454272f709.tar.bz2
rails-4e7217027f1933d5860ba459b3d23f454272f709.zip
Add YAML compatibility for objects from Rails 4.2
As of Ruby 2.2, Psych can handle any object which is marshallable. This was not true on previous versions of Ruby, so our delegator types had to provide their own implementation of `init_with` and `encode_with`. Unfortunately, this doesn't match up with what Psych will do today. Since by the time we hit this layer, the objects will have already been created, I think it makes the most sense to just grab the current type from the class.
Diffstat (limited to 'activerecord/test/cases/yaml_serialization_test.rb')
-rw-r--r--activerecord/test/cases/yaml_serialization_test.rb44
1 files changed, 18 insertions, 26 deletions
diff --git a/activerecord/test/cases/yaml_serialization_test.rb b/activerecord/test/cases/yaml_serialization_test.rb
index 65cd54e380..56909a8630 100644
--- a/activerecord/test/cases/yaml_serialization_test.rb
+++ b/activerecord/test/cases/yaml_serialization_test.rb
@@ -92,31 +92,7 @@ class YamlSerializationTest < ActiveRecord::TestCase
end
def test_deserializing_rails_41_yaml
- yaml = <<-YAML.strip_heredoc
- --- !ruby/object:Topic
- attributes:
- id:
- title: The First Topic
- author_name: David
- author_email_address: david@loudthinking.com
- written_on: 2003-07-16 14:28:11.223300000 Z
- bonus_time: 2000-01-01 14:28:00.000000000 Z
- last_read: 2004-04-15
- content: |
- ---
- :omg: :lol
- important:
- approved: false
- replies_count: 1
- unique_replies_count: 0
- parent_id:
- parent_title:
- type:
- group:
- created_at: 2015-03-10 17:05:42.000000000 Z
- updated_at: 2015-03-10 17:05:42.000000000 Z
- YAML
- topic = YAML.load(yaml)
+ topic = YAML.load(yaml_fixture("rails_4_1"))
assert topic.new_record?
assert_equal nil, topic.id
@@ -124,6 +100,22 @@ class YamlSerializationTest < ActiveRecord::TestCase
assert_equal({ omg: :lol }, topic.content)
end
- def test_deserializing_rails_42_yaml
+ def test_deserializing_rails_4_2_0_yaml
+ topic = YAML.load(yaml_fixture("rails_4_2_0"))
+
+ assert_not topic.new_record?
+ assert_equal 1, topic.id
+ assert_equal "The First Topic", topic.title
+ assert_equal("Have a nice day", topic.content)
+ end
+
+ private
+
+ def yaml_fixture(file_name)
+ path = File.expand_path(
+ "../../support/yaml_compatibility_fixtures/#{file_name}.yml",
+ __FILE__
+ )
+ File.read(path)
end
end