Handle default values properly
This commit is contained in:
parent
c18567f8fc
commit
f9d8f09ab9
|
@ -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
|
||||
if property.default
|
||||
unless property.default.nil?
|
||||
if property.default.class == Proc
|
||||
self[key] = property.default.call
|
||||
else
|
||||
|
|
|
@ -11,6 +11,7 @@ describe "ExtendedDocument" do
|
|||
property :set_by_proc, :default => Proc.new{Time.now}, :cast_as => 'Time'
|
||||
property :tags, :default => []
|
||||
property :read_only_with_default, :default => 'generic', :read_only => true
|
||||
property :default_false, :default => false
|
||||
property :name
|
||||
timestamps!
|
||||
end
|
||||
|
@ -143,6 +144,10 @@ describe "ExtendedDocument" do
|
|||
@obj.preset.should == {:right => 10, :top_align => false}
|
||||
end
|
||||
|
||||
it "should have the default false value explicitly assigned" do
|
||||
@obj.default_false.should == false
|
||||
end
|
||||
|
||||
it "should automatically call a proc default at initialization" do
|
||||
@obj.set_by_proc.should be_an_instance_of(Time)
|
||||
@obj.set_by_proc.should == @obj.set_by_proc
|
||||
|
|
Loading…
Reference in a new issue