Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow false as default for properties #48

Merged
merged 1 commit into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 9, 2011
  1. @matthiasjakel
This page is out of date. Refresh to see the latest.
View
2  lib/couch_potato/persistence/simple_property.rb
@@ -57,7 +57,7 @@ def define_accessors(base, name, options)
define_method "#{name}" do
load_attribute_from_document(name) unless instance_variable_defined?("@#{name}")
value = instance_variable_get("@#{name}")
- if value.nil? && options[:default]
+ if value.nil? && !options[:default].nil?
default = clone_attribute(options[:default])
self.instance_variable_set("@#{name}", default)
default
View
6 spec/default_property_spec.rb
@@ -5,6 +5,7 @@ class Test
property :test, :default => 'Test value'
property :complex, :default => [1, 2, 3]
+ property :false_value, :default => false
end
describe 'default properties' do
@@ -35,4 +36,9 @@ class Test
it "should not return the default value when the actual value is empty" do
t = Test.new(:complex => []).complex.should == []
end
+
+ it "uses the default value also if the default is false" do
+ t = Test.new
+ t.false_value.should == false
+ end
end
Something went wrong with that request. Please try again.