aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-12-01 01:15:16 +0000
committerJon Leighton <j@jonathanleighton.com>2011-12-01 01:15:16 +0000
commit52eedf5e2b0b39026ab5c63c5f28fe70f88ee8db (patch)
tree20c04be8cd8bd321dc4a2894b8906d97d2d3efc5 /activerecord
parent1c783c6040afd9a7ce0199e042e5c6549d0539b4 (diff)
downloadrails-52eedf5e2b0b39026ab5c63c5f28fe70f88ee8db.tar.gz
rails-52eedf5e2b0b39026ab5c63c5f28fe70f88ee8db.tar.bz2
rails-52eedf5e2b0b39026ab5c63c5f28fe70f88ee8db.zip
Add hackery to make Syck use encode_with/init_with. Fixes 1.8 after recent changes to attribute serialization.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/base.rb20
-rw-r--r--activerecord/test/cases/yaml_serialization_test.rb5
2 files changed, 25 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index ee2833c5dc..76aa121ade 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -1935,6 +1935,26 @@ MSG
"#<#{self.class} #{inspection}>"
end
+ # Hackery to accomodate Syck. Remove for 4.0.
+ def to_yaml(opts = {}) #:nodoc:
+ if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck?
+ super
+ else
+ coder = {}
+ encode_with(coder)
+ YAML.quick_emit(self, opts) do |out|
+ out.map(taguri, to_yaml_style) do |map|
+ coder.each { |k, v| map.add(k, v) }
+ end
+ end
+ end
+ end
+
+ # Hackery to accomodate Syck. Remove for 4.0.
+ def yaml_initialize(tag, coder) #:nodoc:
+ init_with(coder)
+ end
+
protected
def clone_attributes(reader_method = :read_attribute, attributes = {})
attribute_names.each do |name|
diff --git a/activerecord/test/cases/yaml_serialization_test.rb b/activerecord/test/cases/yaml_serialization_test.rb
index 0b54c309d1..5a38f2c6ee 100644
--- a/activerecord/test/cases/yaml_serialization_test.rb
+++ b/activerecord/test/cases/yaml_serialization_test.rb
@@ -18,6 +18,11 @@ class YamlSerializationTest < ActiveRecord::TestCase
assert_equal topic, t
end
+ def test_roundtrip_serialized_column
+ topic = Topic.new(:content => {:omg=>:lol})
+ assert_equal({:omg=>:lol}, YAML.load(YAML.dump(topic)).content)
+ end
+
def test_encode_with_coder
topic = Topic.first
coder = {}