Casting array type properties now possible
This commit is contained in:
parent
9d724aee47
commit
3f1b2ea0c6
|
@ -1,5 +1,10 @@
|
||||||
# CouchRest Model Change History
|
# CouchRest Model Change History
|
||||||
|
|
||||||
|
## 1.1.2 - 2011-07-XX
|
||||||
|
|
||||||
|
* Minor fix
|
||||||
|
* Removing restriction that prohibited objects that cast as an array to be loaded.
|
||||||
|
|
||||||
## 1.1.1 - 2011-07-04
|
## 1.1.1 - 2011-07-04
|
||||||
|
|
||||||
* Minor fix
|
* Minor fix
|
||||||
|
|
|
@ -43,9 +43,8 @@ module CouchRest::Model
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Cast an individual value, not an array
|
# Cast an individual value
|
||||||
def cast_value(parent, value)
|
def cast_value(parent, value)
|
||||||
raise "An array inside an array cannot be casted, use Embeddable module" if value.is_a?(Array)
|
|
||||||
value = typecast_value(value, self)
|
value = typecast_value(value, self)
|
||||||
associate_casted_value_to_parent(parent, value)
|
associate_casted_value_to_parent(parent, value)
|
||||||
end
|
end
|
||||||
|
|
|
@ -442,14 +442,17 @@ describe "Property Class" do
|
||||||
ary.last.should eql(Date.new(2011, 05, 22))
|
ary.last.should eql(Date.new(2011, 05, 22))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should raise and error if value is array when type is not" do
|
it "should cast an object that provides an array" do
|
||||||
property = CouchRest::Model::Property.new(:test, Date)
|
prop = Class.new do
|
||||||
parent = mock("FooClass")
|
attr_accessor :ary
|
||||||
lambda {
|
def initialize(val); self.ary = val; end
|
||||||
cast = property.cast(parent, [Date.new(2010, 6, 1)])
|
def as_json; ary; end
|
||||||
}.should raise_error
|
end
|
||||||
|
property = CouchRest::Model::Property.new(:test, prop)
|
||||||
|
parent = mock("FooClass")
|
||||||
|
cast = property.cast(parent, [1, 2])
|
||||||
|
cast.ary.should eql([1, 2])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
it "should set parent as casted_by object in CastedArray" do
|
it "should set parent as casted_by object in CastedArray" do
|
||||||
property = CouchRest::Model::Property.new(:test, [Object])
|
property = CouchRest::Model::Property.new(:test, [Object])
|
||||||
|
|
Loading…
Reference in a new issue