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
def validate_champ_value?
return false unless visible?
case validation_context
when :champs_public_value
public?

View file

@ -1,11 +1,11 @@
describe Champs::CheckboxChamp 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
# TODO remove when normalize_checkbox_values is over
describe '#true?' do
let(:checkbox_champ) { Champs::CheckboxChamp.new(value: value) }
let(:checkbox_champ) { build(:champ_checkbox, value: value) }
subject { checkbox_champ.true? }
context "when the checkbox value is 'on'" do

View file

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

View file

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

View file

@ -1,5 +1,5 @@
describe Champs::YesNoChamp 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

View file

@ -1,10 +1,12 @@
describe ChampConditionalConcern do
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(: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
context "when there are no condition" do
@ -12,12 +14,33 @@ describe ChampConditionalConcern do
end
context "when other tdc has a condition" do
before do
condition = ds_eq(champ_value(champ.stable_id), constant(1))
types_de_champ.last.update!(condition:)
end
let(:condition) { ds_eq(champ_value(99), constant(1)) }
it { expect(champ.dependent_conditions?).to eq(true) }
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