feat(dossier): prefill boolean champs (#8381)

This commit is contained in:
Sébastien Carceles 2023-01-06 14:01:59 +01:00 committed by GitHub
parent 3dbfd81d95
commit 06b8a0f734
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 6 deletions

View file

@ -27,6 +27,8 @@ 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
def true?
value == TRUE_VALUE
end

View file

@ -34,7 +34,9 @@ class PrefillParams
NEED_VALIDATION_TYPES_DE_CHAMPS = [
TypeDeChamp.type_champs.fetch(:decimal_number),
TypeDeChamp.type_champs.fetch(:integer_number),
TypeDeChamp.type_champs.fetch(:civilite)
TypeDeChamp.type_champs.fetch(:civilite),
TypeDeChamp.type_champs.fetch(:yes_no),
TypeDeChamp.type_champs.fetch(:checkbox)
]
attr_reader :champ, :value

View file

@ -260,7 +260,9 @@ class TypeDeChamp < ApplicationRecord
TypeDeChamp.type_champs.fetch(:email),
TypeDeChamp.type_champs.fetch(:phone),
TypeDeChamp.type_champs.fetch(:iban),
TypeDeChamp.type_champs.fetch(:civilite)
TypeDeChamp.type_champs.fetch(:civilite),
TypeDeChamp.type_champs.fetch(:yes_no),
TypeDeChamp.type_champs.fetch(:checkbox)
])
end

View file

@ -110,6 +110,10 @@ RSpec.describe PrefillParams do
it_behaves_like "a champ public value that is authorized", :phone, "value"
it_behaves_like "a champ public value that is authorized", :iban, "value"
it_behaves_like "a champ public value that is authorized", :civilite, "M."
it_behaves_like "a champ public value that is authorized", :yes_no, "true"
it_behaves_like "a champ public value that is authorized", :yes_no, "false"
it_behaves_like "a champ public value that is authorized", :checkbox, "true"
it_behaves_like "a champ public value that is authorized", :checkbox, "false"
it_behaves_like "a champ private value that is authorized", :text, "value"
it_behaves_like "a champ private value that is authorized", :textarea, "value"
@ -119,6 +123,10 @@ RSpec.describe PrefillParams do
it_behaves_like "a champ private value that is authorized", :phone, "value"
it_behaves_like "a champ private value that is authorized", :iban, "value"
it_behaves_like "a champ private value that is authorized", :civilite, "M."
it_behaves_like "a champ private value that is authorized", :yes_no, "true"
it_behaves_like "a champ private value that is authorized", :yes_no, "false"
it_behaves_like "a champ private value that is authorized", :checkbox, "true"
it_behaves_like "a champ private value that is authorized", :checkbox, "false"
it_behaves_like "a champ public value that is unauthorized", :decimal_number, "non decimal string"
it_behaves_like "a champ public value that is unauthorized", :integer_number, "non integer string"
@ -126,9 +134,7 @@ RSpec.describe PrefillParams do
it_behaves_like "a champ public value that is unauthorized", :communes, "value"
it_behaves_like "a champ public value that is unauthorized", :dossier_link, "value"
it_behaves_like "a champ public value that is unauthorized", :titre_identite, "value"
it_behaves_like "a champ public value that is unauthorized", :checkbox, "value"
it_behaves_like "a champ public value that is unauthorized", :civilite, "value"
it_behaves_like "a champ public value that is unauthorized", :yes_no, "value"
it_behaves_like "a champ public value that is unauthorized", :date, "value"
it_behaves_like "a champ public value that is unauthorized", :datetime, "value"
it_behaves_like "a champ public value that is unauthorized", :drop_down_list, "value"

View file

@ -243,13 +243,13 @@ describe TypeDeChamp do
it_behaves_like "a prefillable type de champ", :type_de_champ_phone
it_behaves_like "a prefillable type de champ", :type_de_champ_iban
it_behaves_like "a prefillable type de champ", :type_de_champ_civilite
it_behaves_like "a prefillable type de champ", :type_de_champ_yes_no
it_behaves_like "a prefillable type de champ", :type_de_champ_checkbox
it_behaves_like "a non-prefillable type de champ", :type_de_champ_number
it_behaves_like "a non-prefillable type de champ", :type_de_champ_communes
it_behaves_like "a non-prefillable type de champ", :type_de_champ_dossier_link
it_behaves_like "a non-prefillable type de champ", :type_de_champ_checkbox
it_behaves_like "a non-prefillable type de champ", :type_de_champ_titre_identite
it_behaves_like "a non-prefillable type de champ", :type_de_champ_yes_no
it_behaves_like "a non-prefillable type de champ", :type_de_champ_date
it_behaves_like "a non-prefillable type de champ", :type_de_champ_datetime
it_behaves_like "a non-prefillable type de champ", :type_de_champ_drop_down_list