lib/fanforce/validations/validations.rb in fanforce-validations-0.7.0 vs lib/fanforce/validations/validations.rb in fanforce-validations-0.7.1
- old
+ new
@@ -31,11 +31,12 @@
invalid_fields << parse_validation_field_name(field_to_validate, i, opts, params)
end
end
return true if invalid_fields.size == 0
- errors = invalid_fields.inject([]) {|result, f| result << format_validation_error(opts, f, :missing_field) }
+ error_code = (invalid_fields.size == 1) ? :missing_field : :missing_fields
+ errors = invalid_fields.inject([]) {|result, f| result << format_validation_error(opts, f, error_code) }
raise_validation_errors(opts, errors, Fanforce::Error::BadRequest)
end
alias :validates_presence_of :validates_presence_of_all
def validates_presence_of_any(*args)
@@ -49,10 +50,11 @@
invalid_fields << parse_validation_field_name(field_to_validate, i, opts, params)
end
end
return true if invalid_fields.size < fields_to_validate.size
- errors = [format_validation_error(opts, invalid_fields, :invalid_data)]
+ error_code = (invalid_fields.size == 1) ? :missing_field : :missing_field_from_list
+ errors = [format_validation_error(opts, invalid_fields, error_code)]
raise_validation_errors(opts, errors, Fanforce::Error::BadRequest)
end
def validates_true(*args)
opts = extract_options!(args)
\ No newline at end of file