From 3a4b792225fc3801d69c63a5ed0c224556f35937 Mon Sep 17 00:00:00 2001 From: Timur Vafin Date: Tue, 30 Jun 2009 22:10:47 +0400 Subject: [PATCH] Added AR:B#dup method for duplicationg object without frozen attributes --- activerecord/lib/active_record/base.rb | 7 +++++++ activerecord/test/cases/base_test.rb | 4 ++++ 2 files changed, 11 insertions(+), 0 deletions(-) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index ff5a836..deab56e 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -2870,6 +2870,13 @@ module ActiveRecord #:nodoc: @attributes.frozen? end + # Returns duplicated record with unfreezed attributes. + def dup + obj = super + obj.instance_variable_set('@attributes', instance_variable_get('@attributes').dup) + obj + end + # Returns +true+ if the record is read only. Records loaded through joins with piggy-back # attributes will be marked as read only since they cannot be saved. def readonly? diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 9627011..f439446 100755 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -2116,4 +2116,8 @@ class BasicsTest < ActiveRecord::TestCase assert_equal custom_datetime, parrot[attribute] end end + + def test_dup + assert !Minimalistic.new.freeze.dup.frozen? + end end -- 1.6.0.2