1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test/cases/yaml_serialization_test.rb

47 lines
1.1 KiB
Ruby
Raw Normal View History

require "cases/helper"
require 'models/topic'
class YamlSerializationTest < ActiveRecord::TestCase
2010-12-02 11:44:31 -05:00
fixtures :topics
def test_to_yaml_with_time_with_zone_should_not_raise_exception
Time.zone = ActiveSupport::TimeZone["Pacific Time (US & Canada)"]
ActiveRecord::Base.time_zone_aware_attributes = true
topic = Topic.new(:written_on => DateTime.now)
assert_nothing_raised { topic.to_yaml }
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
def test_encode_with_coder
topic = Topic.first
coder = {}
topic.encode_with coder
assert_equal({'attributes' => topic.attributes}, coder)
end
begin
require 'psych'
def test_psych_roundtrip
topic = Topic.first
assert topic
t = Psych.load Psych.dump topic
assert_equal topic, t
end
2011-01-05 17:03:13 -05:00
def test_psych_roundtrip_new_object
topic = Topic.new
assert topic
t = Psych.load Psych.dump topic
assert_equal topic.attributes, t.attributes
end
rescue LoadError
end
end