diff options
author | Caleb Thompson <cjaysson@gmail.com> | 2013-04-13 00:11:04 -0400 |
---|---|---|
committer | Caleb Thompson <cjaysson@gmail.com> | 2013-04-15 19:57:28 -0400 |
commit | d5867a01a82d14216541c8bfc38e466b02580376 (patch) | |
tree | 1a23a58200e8566ec77df6b832a4350871b7e14b /activerecord/test/cases | |
parent | ae4a02a7f02042514d50e2024f9751afbdb21cf0 (diff) | |
download | rails-d5867a01a82d14216541c8bfc38e466b02580376.tar.gz rails-d5867a01a82d14216541c8bfc38e466b02580376.tar.bz2 rails-d5867a01a82d14216541c8bfc38e466b02580376.zip |
Fix freeze applying to cloned objects
Previously, freezing a cloned ActiveRecord object froze the original
too. By cloning `@attributes` before freezing, we prevent cloned objects
(which in Ruby share state of ivars) from being effected by `#freeze`.
Resolves issue #4936, which has further information on this issue, as
well as steps to reproduce.
* Add a test case for `#freeze` not causing `cloned.frozen?` to be true.
* Clone @attributes before freezing in `ActiveRecord::Core`, then
reassign the cloned, frozen hash to the frozen model's `@attributes`
ivar.
/cc @steveklabnik
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/clone_test.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/test/cases/clone_test.rb b/activerecord/test/cases/clone_test.rb index d91646efca..5e43082c33 100644 --- a/activerecord/test/cases/clone_test.rb +++ b/activerecord/test/cases/clone_test.rb @@ -29,5 +29,12 @@ module ActiveRecord 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 |