From b5a2307a952a18a1339afd1f9866d49757460b78 Mon Sep 17 00:00:00 2001 From: Greg Sterndale Date: Wed, 22 Dec 2010 11:09:42 -0500 Subject: [PATCH] Make deep clone of default property values --- lib/couchrest/model/property.rb | 4 ++-- spec/couchrest/base_spec.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/couchrest/model/property.rb b/lib/couchrest/model/property.rb index d1aec7b..f08405c 100644 --- a/lib/couchrest/model/property.rb +++ b/lib/couchrest/model/property.rb @@ -58,8 +58,8 @@ module CouchRest::Model if default.class == Proc default.call else - # Marshal.load(Marshal.dump(default)) # Removed as there are no failing tests and caused mutex errors - default + # TODO identify cause of mutex errors + Marshal.load(Marshal.dump(default)) end end diff --git a/spec/couchrest/base_spec.rb b/spec/couchrest/base_spec.rb index e10d9be..d64641c 100644 --- a/spec/couchrest/base_spec.rb +++ b/spec/couchrest/base_spec.rb @@ -184,6 +184,14 @@ describe "Model Base" do obj = WithDefaultValues.new(:preset => 'test') obj.preset = 'test' end + + it "should keep default values for new instances" do + obj = WithDefaultValues.new + obj.preset[:alpha] = 123 + obj.preset.should == {:right => 10, :top_align => false, :alpha => 123} + another = WithDefaultValues.new + another.preset.should == {:right => 10, :top_align => false} + end it "should work with a default empty array" do obj = WithDefaultValues.new(:tags => ['spec'])