Fix bug where unserializing an attribute attempts to modify a frozen @attributes hash for a deleted record. [Rick]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7406 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Rick Olson
2007-09-04 17:32:48 +00:00
parent 3bbef581af
commit 51977bc261
3 changed files with 12 additions and 1 deletions

View File

@@ -1,5 +1,7 @@
*SVN*
* Fix bug where unserializing an attribute attempts to modify a frozen @attributes hash for a deleted record. [Rick]
* Performance: absorb instantiate and initialize_with_callbacks into the Base methods. [Jeremy Kemper]
* Fixed that eager loading queries and with_scope should respect the :group option [DHH]

View File

@@ -207,7 +207,7 @@ module ActiveRecord
unserialized_object = object_from_yaml(@attributes[attr_name])
if unserialized_object.is_a?(self.class.serialized_attributes[attr_name]) || unserialized_object.nil?
@attributes[attr_name] = unserialized_object
@attributes.frozen? ? unserialized_object : @attributes[attr_name] = unserialized_object
else
raise SerializationTypeMismatch,
"#{attr_name} was supposed to be a #{self.class.serialized_attributes[attr_name]}, but was a #{unserialized_object.class.to_s}"

View File

@@ -1,4 +1,5 @@
require 'abstract_unit'
require 'fixtures/topic'
class AttributeMethodsTest < Test::Unit::TestCase
def setup
@@ -46,4 +47,12 @@ class AttributeMethodsTest < Test::Unit::TestCase
assert_equal ['title', 1, 2, 3], topic.send(meth, 1, 2, 3)
end
end
def test_should_unserialize_attributes_for_frozen_records
myobj = {:value1 => :value2}
topic = Topic.create("content" => myobj)
topic.freeze
assert_equal myobj, topic.content
end
end