Don’t use unless

This commit is contained in:
gregoirenovel 2018-01-11 19:04:39 +01:00
parent 8c73851cec
commit 7c34807f46
90 changed files with 164 additions and 157 deletions

View file

@ -5,6 +5,6 @@ class EmailFormatValidator < ActiveModel::Validator
def validate(record)
return if record.email.blank?
record.errors[:base] << "Email invalide" unless email_regex.match(record.email)
record.errors[:base] << "Email invalide" if !email_regex.match(record.email)
end
end

View file

@ -5,6 +5,6 @@ class ProcedurePathFormatValidator < ActiveModel::Validator
def validate(record)
return false if record.path.blank?
record.errors[:path] << "Path invalide" unless path_regex.match(record.path)
record.errors[:path] << "Path invalide" if !path_regex.match(record.path)
end
end

View file

@ -1,9 +1,9 @@
class SiretFormatValidator < ActiveModel::EachValidator
def validate_each(record,attribute,value)
unless value =~ /^\d{14}$/
if !(value =~ /^\d{14}$/)
record.errors.add(attribute, :format)
end
unless value != nil && (luhn_checksum(value) % 10 == 0)
if value.nil? || (luhn_checksum(value) % 10 != 0)
record.errors.add(attribute, :checksum)
end
end