Guest User

Untitled

a guest
Jun 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. diff --git a/lib/couchrest/mixins/properties.rb b/lib/couchrest/mixins/properties.rb
  2. index 171a056..61e2ab2 100644
  3. --- a/lib/couchrest/mixins/properties.rb
  4. +++ b/lib/couchrest/mixins/properties.rb
  5. @@ -24,7 +24,7 @@ module CouchRest
  6. self.class.properties.each do |property|
  7. key = property.name.to_s
  8. # let's make sure we have a default
  9. - if property.default
  10. + if property.default != nil
  11. if property.default.class == Proc
  12. self[key] = property.default.call
  13. else
  14. diff --git a/spec/couchrest/more/extended_doc_spec.rb b/spec/couchrest/more/extended_doc_spec.rb
  15. index 257614f..fd37276 100644
  16. --- a/spec/couchrest/more/extended_doc_spec.rb
  17. +++ b/spec/couchrest/more/extended_doc_spec.rb
  18. @@ -11,6 +11,7 @@ describe "ExtendedDocument" do
  19. property :set_by_proc, :default => Proc.new{Time.now}, :cast_as => 'Time'
  20. property :tags, :default => []
  21. property :read_only_with_default, :default => 'generic', :read_only => true
  22. + property :default_false, :default => false
  23. property :name
  24. timestamps!
  25. end
  26. @@ -143,6 +144,10 @@ describe "ExtendedDocument" do
  27. @obj.preset.should == {:right => 10, :top_align => false}
  28. end
  29.  
  30. + it "should have the default false value explicitly assigned" do
  31. + @obj.default_false.should == false
  32. + end
  33. +
  34. it "should automatically call a proc default at initialization" do
  35. @obj.set_by_proc.should be_an_instance_of(Time)
  36. @obj.set_by_proc.should == @obj.set_by_proc
Add Comment
Please, Sign In to add comment