2012-01-04 11:30:57 -05:00
|
|
|
require 'cases/helper'
|
2009-12-11 16:08:00 -05:00
|
|
|
require 'models/topic'
|
|
|
|
|
|
|
|
class YamlSerializationTest < ActiveRecord::TestCase
|
2010-12-02 11:44:31 -05:00
|
|
|
fixtures :topics
|
|
|
|
|
2009-12-11 16:08:00 -05:00
|
|
|
def test_to_yaml_with_time_with_zone_should_not_raise_exception
|
2013-10-24 15:26:23 -04:00
|
|
|
with_timezone_config aware_attributes: true, zone: "Pacific Time (US & Canada)" do
|
|
|
|
topic = Topic.new(:written_on => DateTime.now)
|
|
|
|
assert_nothing_raised { topic.to_yaml }
|
|
|
|
end
|
2009-12-11 16:08:00 -05:00
|
|
|
end
|
2010-12-02 11:44:31 -05:00
|
|
|
|
|
|
|
def test_roundtrip
|
|
|
|
topic = Topic.first
|
|
|
|
assert topic
|
|
|
|
t = YAML.load YAML.dump topic
|
|
|
|
assert_equal topic, t
|
|
|
|
end
|
2011-01-05 17:01:47 -05:00
|
|
|
|
2011-11-30 20:15:16 -05:00
|
|
|
def test_roundtrip_serialized_column
|
|
|
|
topic = Topic.new(:content => {:omg=>:lol})
|
|
|
|
assert_equal({:omg=>:lol}, YAML.load(YAML.dump(topic)).content)
|
|
|
|
end
|
|
|
|
|
2012-01-04 11:30:57 -05:00
|
|
|
def test_psych_roundtrip
|
|
|
|
topic = Topic.first
|
|
|
|
assert topic
|
|
|
|
t = Psych.load Psych.dump topic
|
|
|
|
assert_equal topic, t
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_psych_roundtrip_new_object
|
|
|
|
topic = Topic.new
|
|
|
|
assert topic
|
|
|
|
t = Psych.load Psych.dump topic
|
|
|
|
assert_equal topic.attributes, t.attributes
|
2011-01-05 17:01:47 -05:00
|
|
|
end
|
2013-11-03 09:35:44 -05:00
|
|
|
|
|
|
|
def test_active_record_relation_serialization
|
|
|
|
[Topic.all].to_yaml
|
|
|
|
end
|
2014-05-30 16:06:05 -04:00
|
|
|
|
|
|
|
def test_raw_types_are_not_changed_on_round_trip
|
|
|
|
topic = Topic.new(parent_id: "123")
|
|
|
|
assert_equal "123", topic.parent_id_before_type_cast
|
|
|
|
assert_equal "123", YAML.load(YAML.dump(topic)).parent_id_before_type_cast
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_cast_types_are_not_changed_on_round_trip
|
|
|
|
topic = Topic.new(parent_id: "123")
|
|
|
|
assert_equal 123, topic.parent_id
|
|
|
|
assert_equal 123, YAML.load(YAML.dump(topic)).parent_id
|
|
|
|
end
|
2009-12-11 16:08:00 -05:00
|
|
|
end
|