diff options
author | Rick Olson <technoweenie@gmail.com> | 2007-09-04 17:32:48 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2007-09-04 17:32:48 +0000 |
commit | 51977bc261f83091a31c7f3d6f8dbd59cec1d2a3 (patch) | |
tree | b46482717286f9fe446e96dae1c221d8ab946c74 /activerecord | |
parent | 3bbef581afc4bbe1f6280b56a1b6a6a12133c9d9 (diff) | |
download | rails-51977bc261f83091a31c7f3d6f8dbd59cec1d2a3.tar.gz rails-51977bc261f83091a31c7f3d6f8dbd59cec1d2a3.tar.bz2 rails-51977bc261f83091a31c7f3d6f8dbd59cec1d2a3.zip |
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
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/attribute_methods.rb | 2 | ||||
-rwxr-xr-x | activerecord/test/attribute_methods_test.rb | 9 |
3 files changed, 12 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 9660c9641f..61b6b67b07 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -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] diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index d2346c896e..657abc8b8d 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -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}" diff --git a/activerecord/test/attribute_methods_test.rb b/activerecord/test/attribute_methods_test.rb index 0fa13c65ca..c031d78357 100755 --- a/activerecord/test/attribute_methods_test.rb +++ b/activerecord/test/attribute_methods_test.rb @@ -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 |