diff options
author | Raimonds Simanovskis <raimonds.simanovskis@gmail.com> | 2011-02-09 13:11:06 +0200 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-09 09:19:56 -0800 |
commit | c567ccbb1738969345b29297e40a9aee87a97391 (patch) | |
tree | 7510e1521643180ddd8ec4aee1af96e527f16c75 /activerecord | |
parent | f48d32c0cff36cb505443ff72738def3a82c2886 (diff) | |
download | rails-c567ccbb1738969345b29297e40a9aee87a97391.tar.gz rails-c567ccbb1738969345b29297e40a9aee87a97391.tar.bz2 rails-c567ccbb1738969345b29297e40a9aee87a97391.zip |
bugfix for serialized_attributes to be class specific
previously serialized_attributes were kept as class attribute of ActiveRecord::Base - if some attribute was defined as serialized in one subclass then it was serialized in all other subclasses as well (if it had the same name)
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/base.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/attribute_methods_test.rb | 5 |
2 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 2d5c166075..16bdd7bb58 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -553,7 +553,9 @@ module ActiveRecord #:nodoc: Coders::YAMLColumn.new(class_name) end - serialized_attributes[attr_name.to_s] = coder + # merge new serialized attribute and create new hash to ensure that each class in inheritance hierarchy + # has its own hash of own serialized attributes + self.serialized_attributes = serialized_attributes.merge(attr_name.to_s => coder) end # Guesses the table name (in forced lower-case) based on the name of the class in the diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index 88eaea62e8..dfacf58da8 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -8,6 +8,7 @@ require 'models/topic' require 'models/company' require 'models/category' require 'models/reply' +require 'models/contact' class AttributeMethodsTest < ActiveRecord::TestCase fixtures :topics, :developers, :companies, :computers @@ -609,6 +610,10 @@ class AttributeMethodsTest < ActiveRecord::TestCase Object.send(:undef_method, :title) # remove test method from object end + def test_list_of_serialized_attributes + assert_equal %w(content), Topic.serialized_attributes.keys + assert_equal %w(preferences), Contact.serialized_attributes.keys + end private def cached_columns |