Fixed linting errors on empty field names validator

This commit is contained in:
Tim Rogers 2025-01-01 10:19:09 -06:00
parent 4da9244584
commit 0717cdd2ce

View File

@ -1,17 +1,15 @@
# frozen_string_literal: true
class EmptyProfileFieldNamesValidator < ActiveModel::Validator
def validate(account)
return if account.fields.empty?
field_names_valid = true
account.fields.each_with_index do |field, index|
if field.name.blank? && !field.value.blank?
field_names_valid = false
end
end
return if field_names_valid
def validate(account)
return if account.fields.empty?
account.errors.add(:fields, 'Names of profile fields cannot be empty')
field_names_valid = true
account.fields.each do |field|
field_names_valid = false if field.name.blank? && field.value.present?
end
return if field_names_valid
account.errors.add(:fields, 'Names of profile fields cannot be empty')
end
end