Make deep clone of default property values
This commit is contained in:
parent
83b70ec080
commit
b5a2307a95
|
@ -58,8 +58,8 @@ module CouchRest::Model
|
||||||
if default.class == Proc
|
if default.class == Proc
|
||||||
default.call
|
default.call
|
||||||
else
|
else
|
||||||
# Marshal.load(Marshal.dump(default)) # Removed as there are no failing tests and caused mutex errors
|
# TODO identify cause of mutex errors
|
||||||
default
|
Marshal.load(Marshal.dump(default))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -185,6 +185,14 @@ describe "Model Base" do
|
||||||
obj.preset = 'test'
|
obj.preset = 'test'
|
||||||
end
|
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
|
it "should work with a default empty array" do
|
||||||
obj = WithDefaultValues.new(:tags => ['spec'])
|
obj = WithDefaultValues.new(:tags => ['spec'])
|
||||||
obj.tags.should == ['spec']
|
obj.tags.should == ['spec']
|
||||||
|
|
Loading…
Reference in a new issue