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