refactor(champs): validate only champs in current revision
This commit is contained in:
parent
8ccf2bed4c
commit
f7cd7e615d
14 changed files with 55 additions and 14 deletions
|
@ -16,9 +16,9 @@ module ChampsValidateConcern
|
|||
def validate_champ_value?
|
||||
case validation_context
|
||||
when :champs_public_value
|
||||
public? && visible?
|
||||
public? && in_dossier_revision? && visible?
|
||||
when :champs_private_value
|
||||
private? && visible?
|
||||
private? && in_dossier_revision? && visible?
|
||||
else
|
||||
false
|
||||
end
|
||||
|
@ -27,5 +27,9 @@ module ChampsValidateConcern
|
|||
def validate_champ_value_or_prefill?
|
||||
validate_champ_value? || validation_context == :prefill
|
||||
end
|
||||
|
||||
def in_dossier_revision?
|
||||
dossier.revision.types_de_champ.any? { _1.stable_id = stable_id }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
|
||||
describe Champs::CnafChamp, type: :model do
|
||||
let(:champ) { described_class.new(dossier: build(:dossier)) }
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_cnaf)) }
|
||||
before do
|
||||
allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_cnaf))
|
||||
allow(champ).to receive(:in_dossier_revision?).and_return(true)
|
||||
end
|
||||
describe 'numero_allocataire and code_postal' do
|
||||
before do
|
||||
champ.numero_allocataire = '1234567'
|
||||
|
|
|
@ -6,6 +6,7 @@ describe Champs::DecimalNumberChamp do
|
|||
before do
|
||||
allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_decimal_number))
|
||||
allow(champ).to receive(:visible?).and_return(true)
|
||||
allow(champ).to receive(:in_dossier_revision?).and_return(true)
|
||||
champ.run_callbacks(:validation)
|
||||
end
|
||||
subject { champ.validate(:champs_public_value) }
|
||||
|
|
|
@ -4,7 +4,10 @@ describe Champs::DepartementChamp, type: :model do
|
|||
describe 'validations' do
|
||||
describe 'external link' do
|
||||
let(:champ) { described_class.new(external_id: external_id, dossier: build(:dossier)) }
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_departements)) }
|
||||
before do
|
||||
allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_departements))
|
||||
allow(champ).to receive(:in_dossier_revision?).and_return(true)
|
||||
end
|
||||
subject { champ.validate(:champs_public_value) }
|
||||
|
||||
context 'when nil' do
|
||||
|
|
|
@ -40,7 +40,10 @@ describe Champs::DgfipChamp, type: :model do
|
|||
let(:numero_fiscal) { '1122299999092' }
|
||||
let(:reference_avis) { 'FC22299999092' }
|
||||
let(:champ) { described_class.new(dossier: build(:dossier)) }
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_dgfip)) }
|
||||
before do
|
||||
allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_dgfip))
|
||||
allow(champ).to receive(:in_dossier_revision?).and_return(true)
|
||||
end
|
||||
let(:validation_context) { :champs_public_value }
|
||||
|
||||
subject { champ.valid?(validation_context) }
|
||||
|
|
|
@ -4,7 +4,10 @@ describe Champs::DropDownListChamp do
|
|||
describe 'validations' do
|
||||
describe 'inclusion' do
|
||||
let(:champ) { described_class.new(other:, value:, dossier: build(:dossier)) }
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_drop_down_list, drop_down_other: other)) }
|
||||
before do
|
||||
allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_drop_down_list, drop_down_other: other))
|
||||
allow(champ).to receive(:in_dossier_revision?).and_return(true)
|
||||
end
|
||||
subject { champ.validate(:champs_public_value) }
|
||||
|
||||
context 'when the other value is accepted' do
|
||||
|
|
|
@ -3,7 +3,10 @@
|
|||
describe Champs::EmailChamp do
|
||||
describe 'validation' do
|
||||
let(:champ) { described_class.new(value:, dossier: build(:dossier)) }
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_email)) }
|
||||
before do
|
||||
allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_email))
|
||||
allow(champ).to receive(:in_dossier_revision?).and_return(true)
|
||||
end
|
||||
subject { champ.validate(:champs_public_value) }
|
||||
|
||||
context 'when nil' do
|
||||
|
|
|
@ -7,7 +7,10 @@ describe Champs::EngagementJuridiqueChamp do
|
|||
.new(dossier: build(:dossier))
|
||||
.tap { _1.value = value }
|
||||
end
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_engagement_juridique)) }
|
||||
before {
|
||||
allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_engagement_juridique))
|
||||
allow(champ).to receive(:in_dossier_revision?).and_return(true)
|
||||
}
|
||||
subject { champ.validate(:champs_public_value) }
|
||||
|
||||
context 'with [A-Z]' do
|
|
@ -6,7 +6,10 @@ describe Champs::EpciChamp, type: :model do
|
|||
|
||||
describe 'code_departement' do
|
||||
let(:champ) { Champs::EpciChamp.new(code_departement: code_departement, dossier: build(:dossier)) }
|
||||
before { allow(champ).to receive(:visible?).and_return(true) }
|
||||
before do
|
||||
allow(champ).to receive(:visible?).and_return(true)
|
||||
allow(champ).to receive(:in_dossier_revision?).and_return(true)
|
||||
end
|
||||
context 'when nil' do
|
||||
let(:code_departement) { nil }
|
||||
|
||||
|
|
|
@ -3,7 +3,10 @@
|
|||
describe Champs::IbanChamp do
|
||||
describe '#valid?' do
|
||||
let(:champ) { Champs::IbanChamp.new(dossier: build(:dossier)) }
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_iban)) }
|
||||
before do
|
||||
allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_iban))
|
||||
allow(champ).to receive(:in_dossier_revision?).and_return(true)
|
||||
end
|
||||
def with_value(value)
|
||||
champ.tap { _1.value = value }
|
||||
end
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
|
||||
describe Champs::IntegerNumberChamp do
|
||||
let(:champ) { Champs::IntegerNumberChamp.new(value:, dossier: build(:dossier)) }
|
||||
before { allow(champ).to receive(:visible?).and_return(true) }
|
||||
before do
|
||||
allow(champ).to receive(:visible?).and_return(true)
|
||||
allow(champ).to receive(:in_dossier_revision?).and_return(true)
|
||||
end
|
||||
subject { champ.validate(:champs_public_value) }
|
||||
|
||||
describe '#valid?' do
|
||||
|
|
|
@ -4,7 +4,10 @@ describe Champs::MultipleDropDownListChamp do
|
|||
let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list, drop_down_list_value: "val1\r\nval2\r\nval3\r\n[brackets] val4") }
|
||||
let(:value) { nil }
|
||||
let(:champ) { Champs::MultipleDropDownListChamp.new(value:, dossier: build(:dossier)) }
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(type_de_champ) }
|
||||
before do
|
||||
allow(champ).to receive(:type_de_champ).and_return(type_de_champ)
|
||||
allow(champ).to receive(:in_dossier_revision?).and_return(true)
|
||||
end
|
||||
|
||||
describe 'validations' do
|
||||
subject { champ.validate(:champs_public_value) }
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
|
||||
describe Champs::PhoneChamp do
|
||||
let(:champ) { Champs::PhoneChamp.new(dossier: build(:dossier)) }
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_phone)) }
|
||||
before do
|
||||
allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_phone))
|
||||
allow(champ).to receive(:in_dossier_revision?).and_return(true)
|
||||
end
|
||||
describe '#validate' do
|
||||
it do
|
||||
expect(champ_with_value(nil).validate(:champs_public_value)).to be_truthy
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
|
||||
describe Champs::RNAChamp do
|
||||
let(:champ) { Champs::RNAChamp.new(value: "W182736273", dossier: build(:dossier)) }
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_rna)) }
|
||||
before do
|
||||
allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_rna))
|
||||
allow(champ).to receive(:in_dossier_revision?).and_return(true)
|
||||
end
|
||||
def with_value(value)
|
||||
champ.tap { _1.value = value }
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue