Permalink
Browse files

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)
  • Loading branch information...
1 parent f48d32c commit c567ccbb1738969345b29297e40a9aee87a97391 @rsim rsim committed with tenderlove Feb 9, 2011
Showing with 8 additions and 1 deletion.
  1. +3 −1 activerecord/lib/active_record/base.rb
  2. +5 −0 activerecord/test/cases/attribute_methods_test.rb
@@ -553,7 +553,9 @@ def serialize(attr_name, class_name = Object)
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
@@ -8,6 +8,7 @@
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 @@ def title; "private!"; end
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

0 comments on commit c567ccb

Please sign in to comment.