From 0647307acdeb373c1ba78aae6505baac4a1b5e3a Mon Sep 17 00:00:00 2001 From: Eric Watson Date: Mon, 25 May 2009 11:40:01 -0500 Subject: [PATCH] Enabled apply_defaults for CastedModel --- lib/couchrest/mixins/properties.rb | 2 +- spec/couchrest/more/casted_model_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/couchrest/mixins/properties.rb b/lib/couchrest/mixins/properties.rb index 16643ed..19d33d1 100644 --- a/lib/couchrest/mixins/properties.rb +++ b/lib/couchrest/mixins/properties.rb @@ -17,7 +17,7 @@ module CouchRest end def apply_defaults - return unless self.respond_to?(:new_document?) && new_document? + return if self.respond_to?(:new_document?) && (new_document? == false) return unless self.class.respond_to?(:properties) return if self.class.properties.empty? # TODO: cache the default object diff --git a/spec/couchrest/more/casted_model_spec.rb b/spec/couchrest/more/casted_model_spec.rb index 81bd7c2..269f03e 100644 --- a/spec/couchrest/more/casted_model_spec.rb +++ b/spec/couchrest/more/casted_model_spec.rb @@ -10,6 +10,7 @@ class WithCastedModelMixin < Hash include CouchRest::CastedModel property :name property :no_value + property :hash, :default => {} end class DummyModel < CouchRest::ExtendedDocument @@ -68,6 +69,10 @@ describe CouchRest::CastedModel do it "should return nil for the unknown attribute" do @casted_obj["unknown"].should be_nil end + + it "should return {} for the hash attribute" do + @casted_obj.hash.should == {} + end end describe "casted as an array of a different type" do