lib/chozo/varia_model.rb in chozo-0.2.2 vs lib/chozo/varia_model.rb in chozo-0.2.3

- old
+ new

@@ -59,18 +59,20 @@ types_msg = types.collect { |type| "'#{type}'" } [ :error, "Expected attribute: '#{key}' to be a type of: #{types_msg.join(', ')}" ] end end + # Validate that the attribute on the given model has a non-nil value assigned + # # @param [VariaModel] model # @param [String] key # # @return [Array] def validate_required(model, key) - if model.attributes.dig(key).present? - [ :ok, "" ] - else + if model.attributes.dig(key).nil? [ :error, "A value is required for attribute: '#{key}'" ] + else + [ :ok, "" ] end end private