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
|
2011-12-23 18:22:24 -05:00
|
|
|
tz = Time.zone
|
2009-12-11 16:08:00 -05:00
|
|
|
Time.zone = ActiveSupport::TimeZone["Pacific Time (US & Canada)"]
|
|
|
|
ActiveRecord::Base.time_zone_aware_attributes = true
|
2011-12-23 18:22:24 -05:00
|
|
|
|
2009-12-11 16:08:00 -05:00
|
|
|
topic = Topic.new(:written_on => DateTime.now)
|
|
|
|
assert_nothing_raised { topic.to_yaml }
|
2011-12-23 18:22:24 -05:00
|
|
|
|
|
|
|
ensure
|
|
|
|
Time.zone = tz
|
|
|
|
ActiveRecord::Base.time_zone_aware_attributes = false
|
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
|
|
|
|
|
2011-01-05 17:59:19 -05:00
|
|
|
def test_encode_with_coder
|
|
|
|
topic = Topic.first
|
|
|
|
coder = {}
|
|
|
|
topic.encode_with coder
|
|
|
|
assert_equal({'attributes' => topic.attributes}, coder)
|
|
|
|
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
|
2009-12-11 16:08:00 -05:00
|
|
|
end
|