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?
|
def validate_champ_value?
|
||||||
case validation_context
|
case validation_context
|
||||||
when :champs_public_value
|
when :champs_public_value
|
||||||
public? && visible?
|
public? && in_dossier_revision? && visible?
|
||||||
when :champs_private_value
|
when :champs_private_value
|
||||||
private? && visible?
|
private? && in_dossier_revision? && visible?
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
@ -27,5 +27,9 @@ module ChampsValidateConcern
|
||||||
def validate_champ_value_or_prefill?
|
def validate_champ_value_or_prefill?
|
||||||
validate_champ_value? || validation_context == :prefill
|
validate_champ_value? || validation_context == :prefill
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def in_dossier_revision?
|
||||||
|
dossier.revision.types_de_champ.any? { _1.stable_id = stable_id }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,10 @@
|
||||||
|
|
||||||
describe Champs::CnafChamp, type: :model do
|
describe Champs::CnafChamp, type: :model do
|
||||||
let(:champ) { described_class.new(dossier: build(:dossier)) }
|
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
|
describe 'numero_allocataire and code_postal' do
|
||||||
before do
|
before do
|
||||||
champ.numero_allocataire = '1234567'
|
champ.numero_allocataire = '1234567'
|
||||||
|
|
|
@ -6,6 +6,7 @@ describe Champs::DecimalNumberChamp do
|
||||||
before do
|
before do
|
||||||
allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_decimal_number))
|
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(:visible?).and_return(true)
|
||||||
|
allow(champ).to receive(:in_dossier_revision?).and_return(true)
|
||||||
champ.run_callbacks(:validation)
|
champ.run_callbacks(:validation)
|
||||||
end
|
end
|
||||||
subject { champ.validate(:champs_public_value) }
|
subject { champ.validate(:champs_public_value) }
|
||||||
|
|
|
@ -4,7 +4,10 @@ describe Champs::DepartementChamp, type: :model do
|
||||||
describe 'validations' do
|
describe 'validations' do
|
||||||
describe 'external link' do
|
describe 'external link' do
|
||||||
let(:champ) { described_class.new(external_id: external_id, dossier: build(:dossier)) }
|
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) }
|
subject { champ.validate(:champs_public_value) }
|
||||||
|
|
||||||
context 'when nil' do
|
context 'when nil' do
|
||||||
|
|
|
@ -40,7 +40,10 @@ describe Champs::DgfipChamp, type: :model do
|
||||||
let(:numero_fiscal) { '1122299999092' }
|
let(:numero_fiscal) { '1122299999092' }
|
||||||
let(:reference_avis) { 'FC22299999092' }
|
let(:reference_avis) { 'FC22299999092' }
|
||||||
let(:champ) { described_class.new(dossier: build(:dossier)) }
|
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 }
|
let(:validation_context) { :champs_public_value }
|
||||||
|
|
||||||
subject { champ.valid?(validation_context) }
|
subject { champ.valid?(validation_context) }
|
||||||
|
|
|
@ -4,7 +4,10 @@ describe Champs::DropDownListChamp do
|
||||||
describe 'validations' do
|
describe 'validations' do
|
||||||
describe 'inclusion' do
|
describe 'inclusion' do
|
||||||
let(:champ) { described_class.new(other:, value:, dossier: build(:dossier)) }
|
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) }
|
subject { champ.validate(:champs_public_value) }
|
||||||
|
|
||||||
context 'when the other value is accepted' do
|
context 'when the other value is accepted' do
|
||||||
|
|
|
@ -3,7 +3,10 @@
|
||||||
describe Champs::EmailChamp do
|
describe Champs::EmailChamp do
|
||||||
describe 'validation' do
|
describe 'validation' do
|
||||||
let(:champ) { described_class.new(value:, dossier: build(:dossier)) }
|
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) }
|
subject { champ.validate(:champs_public_value) }
|
||||||
|
|
||||||
context 'when nil' do
|
context 'when nil' do
|
||||||
|
|
|
@ -7,7 +7,10 @@ describe Champs::EngagementJuridiqueChamp do
|
||||||
.new(dossier: build(:dossier))
|
.new(dossier: build(:dossier))
|
||||||
.tap { _1.value = value }
|
.tap { _1.value = value }
|
||||||
end
|
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) }
|
subject { champ.validate(:champs_public_value) }
|
||||||
|
|
||||||
context 'with [A-Z]' do
|
context 'with [A-Z]' do
|
|
@ -6,7 +6,10 @@ describe Champs::EpciChamp, type: :model do
|
||||||
|
|
||||||
describe 'code_departement' do
|
describe 'code_departement' do
|
||||||
let(:champ) { Champs::EpciChamp.new(code_departement: code_departement, dossier: build(:dossier)) }
|
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
|
context 'when nil' do
|
||||||
let(:code_departement) { nil }
|
let(:code_departement) { nil }
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,10 @@
|
||||||
describe Champs::IbanChamp do
|
describe Champs::IbanChamp do
|
||||||
describe '#valid?' do
|
describe '#valid?' do
|
||||||
let(:champ) { Champs::IbanChamp.new(dossier: build(:dossier)) }
|
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)
|
def with_value(value)
|
||||||
champ.tap { _1.value = value }
|
champ.tap { _1.value = value }
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,10 @@
|
||||||
|
|
||||||
describe Champs::IntegerNumberChamp do
|
describe Champs::IntegerNumberChamp do
|
||||||
let(:champ) { Champs::IntegerNumberChamp.new(value:, dossier: build(:dossier)) }
|
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) }
|
subject { champ.validate(:champs_public_value) }
|
||||||
|
|
||||||
describe '#valid?' do
|
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(: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(:value) { nil }
|
||||||
let(:champ) { Champs::MultipleDropDownListChamp.new(value:, dossier: build(:dossier)) }
|
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
|
describe 'validations' do
|
||||||
subject { champ.validate(:champs_public_value) }
|
subject { champ.validate(:champs_public_value) }
|
||||||
|
|
|
@ -2,7 +2,10 @@
|
||||||
|
|
||||||
describe Champs::PhoneChamp do
|
describe Champs::PhoneChamp do
|
||||||
let(:champ) { Champs::PhoneChamp.new(dossier: build(:dossier)) }
|
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
|
describe '#validate' do
|
||||||
it do
|
it do
|
||||||
expect(champ_with_value(nil).validate(:champs_public_value)).to be_truthy
|
expect(champ_with_value(nil).validate(:champs_public_value)).to be_truthy
|
||||||
|
|
|
@ -2,7 +2,10 @@
|
||||||
|
|
||||||
describe Champs::RNAChamp do
|
describe Champs::RNAChamp do
|
||||||
let(:champ) { Champs::RNAChamp.new(value: "W182736273", dossier: build(:dossier)) }
|
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)
|
def with_value(value)
|
||||||
champ.tap { _1.value = value }
|
champ.tap { _1.value = value }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue