Skip to content
Browse files

Merge pull request #10200 from calebthompson/ct-fix-freeze-freezing-c…

…loned-models

Fix freeze applying to cloned objects
  • Loading branch information...
2 parents 30f9237 + d5867a0 commit 77fec1344bfbf7c01f595afbf752633c0eaeed10 @jonleighton jonleighton committed Apr 19, 2013
Showing with 11 additions and 2 deletions.
  1. +4 −2 activerecord/lib/active_record/core.rb
  2. +7 −0 activerecord/test/cases/clone_test.rb
View
6 activerecord/lib/active_record/core.rb
@@ -307,9 +307,11 @@ def hash
id.hash
end
- # Freeze the attributes hash such that associations are still accessible, even on destroyed records.
+ # Clone and freeze the attributes hash such that associations are still
+ # accessible, even on destroyed records, but cloned models will not be
+ # frozen.
def freeze
- @attributes.freeze
+ @attributes = @attributes.clone.freeze
self
end
View
7 activerecord/test/cases/clone_test.rb
@@ -29,5 +29,12 @@ def test_shallow
topic.author_name = 'Aaron'
assert_equal 'Aaron', cloned.author_name
end
+
+ def test_freezing_a_cloned_model_does_not_freeze_clone
+ cloned = Topic.new
+ clone = cloned.clone
+ cloned.freeze
+ assert_not clone.frozen?
+ end
end
end

0 comments on commit 77fec13

Please sign in to comment.
Something went wrong with that request. Please try again.