Enabled apply_defaults for CastedModel
This commit is contained in:
parent
96f8d1aa96
commit
0647307acd
|
@ -17,7 +17,7 @@ module CouchRest
|
||||||
end
|
end
|
||||||
|
|
||||||
def apply_defaults
|
def apply_defaults
|
||||||
return unless self.respond_to?(:new_document?) && new_document?
|
return if self.respond_to?(:new_document?) && (new_document? == false)
|
||||||
return unless self.class.respond_to?(:properties)
|
return unless self.class.respond_to?(:properties)
|
||||||
return if self.class.properties.empty?
|
return if self.class.properties.empty?
|
||||||
# TODO: cache the default object
|
# TODO: cache the default object
|
||||||
|
|
|
@ -10,6 +10,7 @@ class WithCastedModelMixin < Hash
|
||||||
include CouchRest::CastedModel
|
include CouchRest::CastedModel
|
||||||
property :name
|
property :name
|
||||||
property :no_value
|
property :no_value
|
||||||
|
property :hash, :default => {}
|
||||||
end
|
end
|
||||||
|
|
||||||
class DummyModel < CouchRest::ExtendedDocument
|
class DummyModel < CouchRest::ExtendedDocument
|
||||||
|
@ -68,6 +69,10 @@ describe CouchRest::CastedModel do
|
||||||
it "should return nil for the unknown attribute" do
|
it "should return nil for the unknown attribute" do
|
||||||
@casted_obj["unknown"].should be_nil
|
@casted_obj["unknown"].should be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should return {} for the hash attribute" do
|
||||||
|
@casted_obj.hash.should == {}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "casted as an array of a different type" do
|
describe "casted as an array of a different type" do
|
||||||
|
|
Loading…
Reference in a new issue