Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix destructive side effects from marshaling an association caused by 6…

  • Loading branch information...
commit d665f91d412a29d7bd93db38b8fdbc07ed50c510 1 parent f58e82c
@jeremy jeremy authored
View
7 activerecord/lib/active_record/associations/association.rb
@@ -154,11 +154,8 @@ def interpolate(sql, record = nil)
# 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)
View
7 activerecord/test/cases/associations/extension_test.rb
@@ -40,9 +40,12 @@ def test_marshalling_extensions
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
Please sign in to comment.
Something went wrong with that request. Please try again.