Merge pull request #10272 from tchak/fix-no-validate-on-hidden-fields

fix(champ): do not validate hidden champs
This commit is contained in:
Paul Chavard 2024-04-05 11:33:10 +00:00 committed by GitHub
commit 12fa05935a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 36 additions and 11 deletions

View file

@ -259,6 +259,8 @@ class Champ < ApplicationRecord
private private
def validate_champ_value? def validate_champ_value?
return false unless visible?
case validation_context case validation_context
when :champs_public_value when :champs_public_value
public? public?

View file

@ -1,11 +1,11 @@
describe Champs::CheckboxChamp do describe Champs::CheckboxChamp do
it_behaves_like "a boolean champ" do it_behaves_like "a boolean champ" do
let(:boolean_champ) { Champs::CheckboxChamp.new(value: value) } let(:boolean_champ) { build(:champ_checkbox, value: value) }
end end
# TODO remove when normalize_checkbox_values is over # TODO remove when normalize_checkbox_values is over
describe '#true?' do describe '#true?' do
let(:checkbox_champ) { Champs::CheckboxChamp.new(value: value) } let(:checkbox_champ) { build(:champ_checkbox, value: value) }
subject { checkbox_champ.true? } subject { checkbox_champ.true? }
context "when the checkbox value is 'on'" do context "when the checkbox value is 'on'" do

View file

@ -1,5 +1,5 @@
describe Champs::CnafChamp, type: :model do describe Champs::CnafChamp, type: :model do
let(:champ) { described_class.new } let(:champ) { build(:champ_cnaf) }
describe 'numero_allocataire and code_postal' do describe 'numero_allocataire and code_postal' do
before do before do

View file

@ -1,5 +1,5 @@
describe Champs::DgfipChamp, type: :model do describe Champs::DgfipChamp, type: :model do
let(:champ) { described_class.new } let(:champ) { build(:champ_dgfip) }
describe 'numero_fiscal and reference_avis' do describe 'numero_fiscal and reference_avis' do
before do before do

View file

@ -1,5 +1,5 @@
describe Champs::YesNoChamp do describe Champs::YesNoChamp do
it_behaves_like "a boolean champ" do it_behaves_like "a boolean champ" do
let(:boolean_champ) { Champs::YesNoChamp.new(value: value) } let(:boolean_champ) { build(:champ_yes_no, value: value) }
end end
end end

View file

@ -1,10 +1,12 @@
describe ChampConditionalConcern do describe ChampConditionalConcern do
include Logic include Logic
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :number }, { type: :number }]) } let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :decimal_number, stable_id: 99 }, { type: :decimal_number, condition: }]) }
let(:dossier) { create(:dossier, revision: procedure.active_revision) } let(:dossier) { create(:dossier, revision: procedure.active_revision) }
let(:types_de_champ) { procedure.active_revision.types_de_champ_public } let(:types_de_champ) { procedure.active_revision.types_de_champ_public }
let(:champ) { create(:champ, dossier:, type_de_champ: types_de_champ.first, value: 1) } let(:champ) { create(:champ_decimal_number, dossier:, type_de_champ: types_de_champ.first, value: '1.1234') }
let(:last_champ) { create(:champ_decimal_number, dossier:, type_de_champ: types_de_champ.last, value: '1.1234') }
let(:condition) { nil }
describe '#dependent_conditions?' do describe '#dependent_conditions?' do
context "when there are no condition" do context "when there are no condition" do
@ -12,12 +14,33 @@ describe ChampConditionalConcern do
end end
context "when other tdc has a condition" do context "when other tdc has a condition" do
before do let(:condition) { ds_eq(champ_value(99), constant(1)) }
condition = ds_eq(champ_value(champ.stable_id), constant(1))
types_de_champ.last.update!(condition:)
end
it { expect(champ.dependent_conditions?).to eq(true) } it { expect(champ.dependent_conditions?).to eq(true) }
end end
end end
describe '#visible?' do
context "when there are no condition" do
it {
expect(champ.visible?).to eq(true)
expect(champ.valid?(:champs_public_value)).to eq(false)
expect(last_champ.visible?).to eq(true)
expect(last_champ.valid?(:champs_public_value)).to eq(false)
}
end
context "when other tdc has a condition" do
let(:condition) { ds_eq(champ_value(99), constant(1)) }
it {
expect(champ.visible?).to eq(true)
expect(champ.valid?(:champs_public_value)).to eq(false)
expect(last_champ.visible?).to eq(false)
expect(last_champ.valid?(:champs_public_value)).to eq(true)
}
end
end
end end