Revert "Champ related cleanups and refactoring"
This commit is contained in:
parent
7693d216d8
commit
e7443c2308
30 changed files with 173 additions and 158 deletions
|
@ -8,50 +8,31 @@ describe Champ do
|
|||
let(:champ) { Champ.new(value: value) }
|
||||
let(:value) { '' }
|
||||
let(:mandatory) { true }
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(type_de_champ) }
|
||||
|
||||
context 'with champ' do
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(type_de_champ) }
|
||||
context 'when mandatory and blank' do
|
||||
it { expect(champ.mandatory_blank?).to be(true) }
|
||||
end
|
||||
|
||||
context 'when mandatory and blank' do
|
||||
it { expect(champ.mandatory_blank?).to be(true) }
|
||||
end
|
||||
context 'when carte mandatory and blank' do
|
||||
let(:type_de_champ) { build(:type_de_champ_carte, mandatory: mandatory) }
|
||||
let(:champ) { Champs::CarteChamp.new(value: value) }
|
||||
let(:value) { nil }
|
||||
it { expect(champ.mandatory_blank?).to be(true) }
|
||||
end
|
||||
|
||||
context 'when carte mandatory and blank' do
|
||||
let(:type_de_champ) { build(:type_de_champ_carte, mandatory: mandatory) }
|
||||
let(:champ) { Champs::CarteChamp.new(value: value) }
|
||||
let(:value) { nil }
|
||||
it { expect(champ.mandatory_blank?).to be(true) }
|
||||
end
|
||||
context 'when multiple_drop_down_list mandatory and blank' do
|
||||
let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list, mandatory: mandatory) }
|
||||
let(:champ) { Champs::MultipleDropDownListChamp.new(value: value) }
|
||||
let(:value) { '[]' }
|
||||
it { expect(champ.mandatory_blank?).to be(true) }
|
||||
end
|
||||
|
||||
context 'when multiple_drop_down_list mandatory and blank' do
|
||||
let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list, mandatory: mandatory) }
|
||||
let(:champ) { Champs::MultipleDropDownListChamp.new(value: value) }
|
||||
let(:value) { '[]' }
|
||||
it { expect(champ.mandatory_blank?).to be(true) }
|
||||
end
|
||||
context 'when repetition blank' do
|
||||
let(:type_de_champ) { build(:type_de_champ_repetition) }
|
||||
let(:champ) { Champs::RepetitionChamp.new }
|
||||
|
||||
context 'when repetition blank' do
|
||||
let(:type_de_champ) { build(:type_de_champ_repetition) }
|
||||
let(:champ) { Champs::RepetitionChamp.new(dossier: Dossier.new(revision: ProcedureRevision.new)) }
|
||||
|
||||
it { expect(champ.blank?).to be(true) }
|
||||
end
|
||||
|
||||
context 'when not blank' do
|
||||
let(:value) { 'yop' }
|
||||
it { expect(champ.mandatory_blank?).to be(false) }
|
||||
end
|
||||
|
||||
context 'when not mandatory' do
|
||||
let(:mandatory) { false }
|
||||
it { expect(champ.mandatory_blank?).to be(false) }
|
||||
end
|
||||
|
||||
context 'when not mandatory or blank' do
|
||||
let(:value) { 'u' }
|
||||
let(:mandatory) { false }
|
||||
it { expect(champ.mandatory_blank?).to be(false) }
|
||||
end
|
||||
it { expect(champ.blank?).to be(true) }
|
||||
end
|
||||
|
||||
context 'when repetition not blank' do
|
||||
|
@ -61,6 +42,22 @@ describe Champ do
|
|||
|
||||
it { expect(champ.blank?).to be(false) }
|
||||
end
|
||||
|
||||
context 'when not blank' do
|
||||
let(:value) { 'yop' }
|
||||
it { expect(champ.mandatory_blank?).to be(false) }
|
||||
end
|
||||
|
||||
context 'when not mandatory' do
|
||||
let(:mandatory) { false }
|
||||
it { expect(champ.mandatory_blank?).to be(false) }
|
||||
end
|
||||
|
||||
context 'when not mandatory or blank' do
|
||||
let(:value) { 'u' }
|
||||
let(:mandatory) { false }
|
||||
it { expect(champ.mandatory_blank?).to be(false) }
|
||||
end
|
||||
end
|
||||
|
||||
describe "associations" do
|
||||
|
@ -135,7 +132,7 @@ describe Champ do
|
|||
let(:standalone_champ) { build(:champ, type_de_champ: build(:type_de_champ), dossier: build(:dossier)) }
|
||||
let(:public_sections) { dossier.champs_public.filter(&:header_section?) }
|
||||
let(:private_sections) { dossier.champs_private.filter(&:header_section?) }
|
||||
let(:sections_in_repetition) { dossier.champs.filter(&:child?).filter(&:header_section?) }
|
||||
let(:sections_in_repetition) { champ_in_repetition.parent.champs.filter(&:header_section?) }
|
||||
|
||||
it 'returns the sibling sections of a champ' do
|
||||
expect(public_sections).not_to be_empty
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
|
||||
describe Champs::CnafChamp, type: :model do
|
||||
let(:champ) { described_class.new(dossier: build(:dossier)) }
|
||||
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
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_cnaf)) }
|
||||
describe 'numero_allocataire and code_postal' do
|
||||
before do
|
||||
champ.numero_allocataire = '1234567'
|
||||
|
|
|
@ -6,7 +6,6 @@ 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,10 +4,7 @@ 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 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
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_departements)) }
|
||||
subject { champ.validate(:champs_public_value) }
|
||||
|
||||
context 'when nil' do
|
||||
|
|
|
@ -40,10 +40,7 @@ describe Champs::DgfipChamp, type: :model do
|
|||
let(:numero_fiscal) { '1122299999092' }
|
||||
let(:reference_avis) { 'FC22299999092' }
|
||||
let(:champ) { described_class.new(dossier: build(:dossier)) }
|
||||
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
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_dgfip)) }
|
||||
let(:validation_context) { :champs_public_value }
|
||||
|
||||
subject { champ.valid?(validation_context) }
|
||||
|
|
|
@ -4,10 +4,7 @@ describe Champs::DropDownListChamp do
|
|||
describe 'validations' do
|
||||
describe 'inclusion' do
|
||||
let(:champ) { described_class.new(other:, value:, dossier: build(:dossier)) }
|
||||
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
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_drop_down_list, drop_down_other: other)) }
|
||||
subject { champ.validate(:champs_public_value) }
|
||||
|
||||
context 'when the other value is accepted' do
|
||||
|
|
|
@ -3,10 +3,7 @@
|
|||
describe Champs::EmailChamp do
|
||||
describe 'validation' do
|
||||
let(:champ) { described_class.new(value:, dossier: build(:dossier)) }
|
||||
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
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_email)) }
|
||||
subject { champ.validate(:champs_public_value) }
|
||||
|
||||
context 'when nil' do
|
||||
|
|
|
@ -6,10 +6,7 @@ describe Champs::EpciChamp, type: :model do
|
|||
|
||||
describe 'code_departement' do
|
||||
let(:champ) { Champs::EpciChamp.new(code_departement: code_departement, dossier: build(:dossier)) }
|
||||
before do
|
||||
allow(champ).to receive(:visible?).and_return(true)
|
||||
allow(champ).to receive(:in_dossier_revision?).and_return(true)
|
||||
end
|
||||
before { allow(champ).to receive(:visible?).and_return(true) }
|
||||
context 'when nil' do
|
||||
let(:code_departement) { nil }
|
||||
|
||||
|
|
|
@ -3,10 +3,7 @@
|
|||
describe Champs::IbanChamp do
|
||||
describe '#valid?' do
|
||||
let(:champ) { Champs::IbanChamp.new(dossier: build(:dossier)) }
|
||||
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
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_iban)) }
|
||||
def with_value(value)
|
||||
champ.tap { _1.value = value }
|
||||
end
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
|
||||
describe Champs::IntegerNumberChamp do
|
||||
let(:champ) { Champs::IntegerNumberChamp.new(value:, dossier: build(:dossier)) }
|
||||
before do
|
||||
allow(champ).to receive(:visible?).and_return(true)
|
||||
allow(champ).to receive(:in_dossier_revision?).and_return(true)
|
||||
end
|
||||
before { allow(champ).to receive(:visible?).and_return(true) }
|
||||
subject { champ.validate(:champs_public_value) }
|
||||
|
||||
describe '#valid?' do
|
||||
|
|
|
@ -4,10 +4,7 @@ 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 do
|
||||
allow(champ).to receive(:type_de_champ).and_return(type_de_champ)
|
||||
allow(champ).to receive(:in_dossier_revision?).and_return(true)
|
||||
end
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(type_de_champ) }
|
||||
|
||||
describe 'validations' do
|
||||
subject { champ.validate(:champs_public_value) }
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
|
||||
describe Champs::PhoneChamp do
|
||||
let(:champ) { Champs::PhoneChamp.new(dossier: build(:dossier)) }
|
||||
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
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_phone)) }
|
||||
describe '#validate' do
|
||||
it do
|
||||
expect(champ_with_value(nil).validate(:champs_public_value)).to be_truthy
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
|
||||
describe Champs::RNAChamp do
|
||||
let(:champ) { Champs::RNAChamp.new(value: "W182736273", dossier: build(:dossier)) }
|
||||
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
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_rna)) }
|
||||
def with_value(value)
|
||||
champ.tap { _1.value = value }
|
||||
end
|
||||
|
|
|
@ -38,8 +38,10 @@ describe DossierSearchableConcern do
|
|||
end
|
||||
|
||||
it "update columns en construction" do
|
||||
dossier.update_champs_attributes({ champ_public.public_id => { value: 'nouvelle valeur publique' } }, :public, updated_by: 'test')
|
||||
dossier.update_champs_attributes({ champ_private.public_id => { value: 'nouvelle valeur privee' } }, :private, updated_by: 'test')
|
||||
dossier.update(
|
||||
champs_public_attributes: [{ id: champ_public.id, value: 'nouvelle valeur publique' }],
|
||||
champs_private_attributes: [{ id: champ_private.id, value: 'nouvelle valeur privee' }]
|
||||
)
|
||||
|
||||
assert_enqueued_jobs(1, only: DossierIndexSearchTermsJob) do
|
||||
dossier.passer_en_construction
|
||||
|
|
|
@ -50,12 +50,12 @@ describe DossierSectionsConcern do
|
|||
describe '#index_for_section_header' do
|
||||
include Logic
|
||||
let(:number_stable_id) { 99 }
|
||||
let(:types_de_champ) do
|
||||
[
|
||||
{ type: :header_section, libelle: "Infos" }, { type: :integer_number, stable_id: number_stable_id },
|
||||
{ type: :header_section, libelle: "Details", condition: ds_eq(champ_value(99), constant(5)) }, { type: :header_section, libelle: "Conclusion" }
|
||||
]
|
||||
end
|
||||
let(:types_de_champ) {
|
||||
[
|
||||
{ type: :header_section, libelle: "Infos" }, { type: :integer_number, stable_id: number_stable_id },
|
||||
{ type: :header_section, libelle: "Details", condition: ds_eq(champ_value(99), constant(5)) }, { type: :header_section, libelle: "Conclusion" }
|
||||
]
|
||||
}
|
||||
|
||||
let(:procedure) { create(:procedure, :for_individual, types_de_champ_public: types_de_champ) }
|
||||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
|
|
|
@ -7,10 +7,7 @@ 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))
|
||||
allow(champ).to receive(:in_dossier_revision?).and_return(true)
|
||||
}
|
||||
before { allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_engagement_juridique)) }
|
||||
subject { champ.validate(:champs_public_value) }
|
||||
|
||||
context 'with [A-Z]' do
|
Loading…
Add table
Add a link
Reference in a new issue