diff --git a/lib/couchrest/mixins/properties.rb b/lib/couchrest/mixins/properties.rb index 5fec51d..171a056 100644 --- a/lib/couchrest/mixins/properties.rb +++ b/lib/couchrest/mixins/properties.rb @@ -23,8 +23,8 @@ module CouchRest # TODO: cache the default object 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.nil? && (self.respond_to?("#{key}=") || self.key?(key)) + # let's make sure we have a default + if property.default if property.default.class == Proc self[key] = property.default.call else diff --git a/spec/couchrest/more/extended_doc_spec.rb b/spec/couchrest/more/extended_doc_spec.rb index fccd8d9..257614f 100644 --- a/spec/couchrest/more/extended_doc_spec.rb +++ b/spec/couchrest/more/extended_doc_spec.rb @@ -10,7 +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 :read_only_with_default, :default => 'generic', :read_only => true property :name timestamps! end @@ -158,10 +158,10 @@ describe "ExtendedDocument" do obj = WithDefaultValues.new(:tags => ['spec']) obj.tags.should == ['spec'] end - - it "should work with a default value of false" do + + it "should set default value of read-only property" do obj = WithDefaultValues.new - obj.false_default.should == false + obj.read_only_with_default.should == 'generic' end end