fix(Champs::BooleanChamp): validates Champs::BooleanChamp respecting it's validation context.

This commit is contained in:
mfo 2024-04-01 07:16:56 +02:00
parent d7f152f4af
commit 94ea16c894
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC

View file

@ -5,7 +5,10 @@ class Champs::BooleanChamp < Champ
before_validation :set_value_to_nil, if: -> { value.blank? }
before_validation :set_value_to_false, unless: -> { ([nil, TRUE_VALUE, FALSE_VALUE]).include?(value) }
validates :value, inclusion: [TRUE_VALUE, FALSE_VALUE], allow_nil: true, allow_blank: false
validates :value, inclusion: [TRUE_VALUE, FALSE_VALUE],
allow_nil: true,
allow_blank: false,
if: :validate_champ_value?
def true?
value == TRUE_VALUE