Merge commit 'mattetti/master'

This commit is contained in:
Peter Gumeson 2009-06-20 21:05:00 -07:00
commit ce02d05eac
2 changed files with 6 additions and 1 deletions

View file

@ -24,7 +24,7 @@ module CouchRest
self.class.properties.each do |property| self.class.properties.each do |property|
key = property.name.to_s key = property.name.to_s
# let's make sure we have a default # let's make sure we have a default
if property.default unless property.default.nil?
if property.default.class == Proc if property.default.class == Proc
self[key] = property.default.call self[key] = property.default.call
else else

View file

@ -12,6 +12,7 @@ describe "ExtendedDocument" do
property :set_by_proc, :default => Proc.new{Time.now}, :cast_as => 'Time' property :set_by_proc, :default => Proc.new{Time.now}, :cast_as => 'Time'
property :tags, :default => [] property :tags, :default => []
property :read_only_with_default, :default => 'generic', :read_only => true property :read_only_with_default, :default => 'generic', :read_only => true
property :default_false, :default => false
property :name property :name
timestamps! timestamps!
end end
@ -173,6 +174,10 @@ describe "ExtendedDocument" do
it "should have the default value set at initalization" do it "should have the default value set at initalization" do
@obj.preset.should == {:right => 10, :top_align => false} @obj.preset.should == {:right => 10, :top_align => false}
end 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 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 be_an_instance_of(Time)