diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2012-09-25 13:20:26 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2012-09-25 13:20:35 -0700 |
commit | d665f91d412a29d7bd93db38b8fdbc07ed50c510 (patch) | |
tree | 2006c2c448b42c9ce8578c541b6fbe913d263f97 | |
parent | f58e82cd736ecaf6edb3cbc5d0a27e9378b9a127 (diff) | |
download | rails-d665f91d412a29d7bd93db38b8fdbc07ed50c510.tar.gz rails-d665f91d412a29d7bd93db38b8fdbc07ed50c510.tar.bz2 rails-d665f91d412a29d7bd93db38b8fdbc07ed50c510.zip |
Fix destructive side effects from marshaling an association caused by 65843e1acc0c8d285ff79f8c9c49d4d1215440be
-rw-r--r-- | activerecord/lib/active_record/associations/association.rb | 7 | ||||
-rw-r--r-- | activerecord/test/cases/associations/extension_test.rb | 7 |
2 files changed, 7 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb index 495f0cde59..ba75c8be41 100644 --- a/activerecord/lib/active_record/associations/association.rb +++ b/activerecord/lib/active_record/associations/association.rb @@ -154,11 +154,8 @@ module ActiveRecord # We can't dump @reflection since it contains the scope proc def marshal_dump - reflection = @reflection - @reflection = nil - - ivars = instance_variables.map { |name| [name, instance_variable_get(name)] } - [reflection.name, ivars] + ivars = (instance_variables - [:@reflection]).map { |name| [name, instance_variable_get(name)] } + [@reflection.name, ivars] end def marshal_load(data) diff --git a/activerecord/test/cases/associations/extension_test.rb b/activerecord/test/cases/associations/extension_test.rb index bd5a426ca8..da767a2a7e 100644 --- a/activerecord/test/cases/associations/extension_test.rb +++ b/activerecord/test/cases/associations/extension_test.rb @@ -40,9 +40,12 @@ class AssociationsExtensionsTest < ActiveRecord::TestCase assert_equal projects(:action_controller), david.projects.find_most_recent marshalled = Marshal.dump(david) - david = Marshal.load(marshalled) - assert_equal projects(:action_controller), david.projects.find_most_recent + # Marshaling an association shouldn't make it unusable by wiping its reflection. + assert_not_nil david.association(:projects).reflection + + david_too = Marshal.load(marshalled) + assert_equal projects(:action_controller), david_too.projects.find_most_recent end def test_marshalling_named_extensions |