diff --git a/lib/couchrest/mixins/properties.rb b/lib/couchrest/mixins/properties.rb index 0049736..5fec51d 100644 --- a/lib/couchrest/mixins/properties.rb +++ b/lib/couchrest/mixins/properties.rb @@ -24,7 +24,7 @@ module CouchRest self.class.properties.each do |property| key = property.name.to_s # let's make sure we have a default and we can assign the value - if property.default && (self.respond_to?("#{key}=") || self.key?(key)) + if !property.default.nil? && (self.respond_to?("#{key}=") || self.key?(key)) if property.default.class == Proc self[key] = property.default.call else diff --git a/lib/couchrest/more/property.rb b/lib/couchrest/more/property.rb index 096f03e..77e2b90 100644 --- a/lib/couchrest/more/property.rb +++ b/lib/couchrest/more/property.rb @@ -30,11 +30,11 @@ module CouchRest @validation_format = options.delete(:format) if options[:format] @read_only = options.delete(:read_only) if options[:read_only] @alias = options.delete(:alias) if options[:alias] - @default = options.delete(:default) if options[:default] + @default = options.delete(:default) unless options[:default].nil? @casted = options[:casted] ? true : false @init_method = options[:send] ? options.delete(:send) : 'new' @options = options end end -end \ No newline at end of file +end diff --git a/spec/couchrest/more/extended_doc_spec.rb b/spec/couchrest/more/extended_doc_spec.rb index 45eb0e3..fccd8d9 100644 --- a/spec/couchrest/more/extended_doc_spec.rb +++ b/spec/couchrest/more/extended_doc_spec.rb @@ -10,6 +10,7 @@ describe "ExtendedDocument" do property :preset, :default => {:right => 10, :top_align => false} property :set_by_proc, :default => Proc.new{Time.now}, :cast_as => 'Time' property :tags, :default => [] + property :false_default, :default => false property :name timestamps! end @@ -157,6 +158,11 @@ describe "ExtendedDocument" do obj = WithDefaultValues.new(:tags => ['spec']) obj.tags.should == ['spec'] end + + it "should work with a default value of false" do + obj = WithDefaultValues.new + obj.false_default.should == false + end end describe "a doc with template values (CR::Model spec)" do