From 06b8a0f7346f0c2c1cef04d2849b68dd7476f712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Carceles?= Date: Fri, 6 Jan 2023 14:01:59 +0100 Subject: [PATCH] feat(dossier): prefill boolean champs (#8381) --- app/models/champs/boolean_champ.rb | 2 ++ app/models/prefill_params.rb | 4 +++- app/models/type_de_champ.rb | 4 +++- spec/models/prefill_params_spec.rb | 10 ++++++++-- spec/models/type_de_champ_spec.rb | 4 ++-- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/models/champs/boolean_champ.rb b/app/models/champs/boolean_champ.rb index 60a15eee7..1506f0261 100644 --- a/app/models/champs/boolean_champ.rb +++ b/app/models/champs/boolean_champ.rb @@ -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 diff --git a/app/models/prefill_params.rb b/app/models/prefill_params.rb index bf20497f0..631f7225d 100644 --- a/app/models/prefill_params.rb +++ b/app/models/prefill_params.rb @@ -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 diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 54cb6affa..f508b9776 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -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 diff --git a/spec/models/prefill_params_spec.rb b/spec/models/prefill_params_spec.rb index 31a689d04..d33a4e97b 100644 --- a/spec/models/prefill_params_spec.rb +++ b/spec/models/prefill_params_spec.rb @@ -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" diff --git a/spec/models/type_de_champ_spec.rb b/spec/models/type_de_champ_spec.rb index be500ac28..e73989315 100644 --- a/spec/models/type_de_champ_spec.rb +++ b/spec/models/type_de_champ_spec.rb @@ -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