lib/service_contract/assertions.rb in service_contract-0.2.0 vs lib/service_contract/assertions.rb in service_contract-0.2.1
- old
+ new
@@ -10,10 +10,11 @@
assert data.is_a?(Array), "expected #{type.name} to be an Array; instead got: #{data.inspect} (#{data.class.name})"
data.each do |datum|
assert_data_matches_type(datum, type.subtype, allow_nil)
end
elsif type.complex?
-
+ # Skip out of the complex object is nil and allowed to be nil
+ return true if data.nil? && allow_nil
# type should have fields
type.fields.each do |field|
#Does data contain attributes that the contract doesn't specify?
data_extra_attrs = (data.keys.map(&:to_sym) - type.fields.map{|n| n.name.to_sym})
\ No newline at end of file