This commit is contained in:
simon lehericey 2022-05-13 17:06:59 +02:00
parent 419d853d1d
commit fd4d543b20
4 changed files with 47 additions and 25 deletions

View file

@ -74,7 +74,12 @@ describe Champ do
create(:procedure, :with_type_de_champ, :with_type_de_champ_private, :with_repetition, types_de_champ_count: 1, types_de_champ_private_count: 1).tap do |procedure| create(:procedure, :with_type_de_champ, :with_type_de_champ_private, :with_repetition, types_de_champ_count: 1, types_de_champ_private_count: 1).tap do |procedure|
create(:type_de_champ_header_section, procedure: procedure) create(:type_de_champ_header_section, procedure: procedure)
create(:type_de_champ_header_section, procedure: procedure, private: true) create(:type_de_champ_header_section, procedure: procedure, private: true)
create(:type_de_champ_header_section, parent: procedure.types_de_champ.find(&:repetition?))
procedure.active_revision.add_type_de_champ(
libelle: 'header',
type_champ: 'header_section',
parent_id: procedure.types_de_champ.find(&:repetition?).stable_id
)
end end
end end
let(:dossier) { create(:dossier, procedure: procedure) } let(:dossier) { create(:dossier, procedure: procedure) }
@ -508,11 +513,9 @@ describe Champ do
end end
describe 'repetition' do describe 'repetition' do
let(:procedure) { create(:procedure, :published, :with_type_de_champ, :with_type_de_champ_private, types_de_champ: [build(:type_de_champ_repetition, types_de_champ: [tdc_text, tdc_integer])]) } let(:procedure) { create(:procedure, :published, :with_type_de_champ, :with_type_de_champ_private, :with_repetition) }
let(:revision) { procedure.published_revision } let(:tdc_repetition) { procedure.types_de_champ.find(&:repetition?) }
let(:rtdc_repetition) { revision.revision_types_de_champ.find { |rtdc| rtdc.type_de_champ.repetition? } } let(:tdc_text) { procedure.active_revision.children_of(tdc_repetition).first }
let(:tdc_text) { build(:type_de_champ_text) }
let(:tdc_integer) { build(:type_de_champ_integer_number) }
let(:dossier) { create(:dossier, procedure: procedure) } let(:dossier) { create(:dossier, procedure: procedure) }
let(:champ) { dossier.champs.find(&:repetition?) } let(:champ) { dossier.champs.find(&:repetition?) }
@ -521,8 +524,7 @@ describe Champ do
let(:champ_text_attrs) { attributes_for(:champ_text, type_de_champ: tdc_text, row: 1) } let(:champ_text_attrs) { attributes_for(:champ_text, type_de_champ: tdc_text, row: 1) }
before do before do
create(:procedure_revision_type_de_champ, revision: revision, type_de_champ: tdc_text, parent: rtdc_repetition, position: 1) procedure.active_revision.add_type_de_champ(libelle: 'sub integer', type_champ: 'integer_number', parent_id: tdc_repetition.stable_id)
create(:procedure_revision_type_de_champ, revision: revision, type_de_champ: tdc_integer, parent: rtdc_repetition, position: 0)
end end
context 'when creating the model directly' do context 'when creating the model directly' do
@ -557,12 +559,12 @@ describe Champ do
champ.champs << champ_integer champ.champs << champ_integer
first_row = champ.reload.rows.first first_row = champ.reload.rows.first
expect(first_row.size).to eq(2) expect(first_row.size).to eq(2)
expect(first_row.first).to eq(champ_integer) expect(first_row.second).to eq(champ_integer)
champ.champs << champ_text champ.champs << champ_text
first_row = champ.reload.rows.first first_row = champ.reload.rows.first
expect(first_row.size).to eq(2) expect(first_row.size).to eq(2)
expect(first_row.second).to eq(champ_text) expect(first_row.first).to eq(champ_text)
expect(champ.rows.size).to eq(2) expect(champ.rows.size).to eq(2)
end end

View file

@ -23,12 +23,26 @@ describe Champs::HeaderSectionChamp do
end end
context 'for repetition champs' do context 'for repetition champs' do
let(:procedure) { create(:procedure, types_de_champ: [build(:type_de_champ_repetition, types_de_champ: types_de_champ)]) } let(:procedure) { create(:procedure, :with_repetition) }
let(:dossier) { create(:dossier, procedure: procedure) } let(:dossier) { create(:dossier, procedure: procedure) }
let(:first_header) { dossier.champs.first.champs[0] } let(:first_header) { dossier.champs.first.champs[0] }
let(:second_header) { dossier.champs.first.champs[3] } let(:second_header) { dossier.champs.first.champs[3] }
before do
revision = procedure.active_revision
tdc_repetition = revision.types_de_champ_public.first
revision.remove_type_de_champ(revision.children_of(tdc_repetition))
types_de_champ.each do |tdc|
revision.add_type_de_champ(
libelle: tdc.libelle,
type_champ: tdc.type_champ,
parent_id: tdc_repetition.stable_id
)
end
end
it 'returns the index of the section in the repetition (starting from 1)' do it 'returns the index of the section in the repetition (starting from 1)' do
expect(first_header.section_index).to eq 1 expect(first_header.section_index).to eq 1
expect(second_header.section_index).to eq 2 expect(second_header.section_index).to eq 2

View file

@ -161,19 +161,23 @@ describe TagsSubstitutionConcern, type: :model do
context 'when the procedure has a type de champ repetition' do context 'when the procedure has a type de champ repetition' do
let(:template) { '--Répétition--' } let(:template) { '--Répétition--' }
let(:types_de_champ) do let(:repetition) do
[ repetition_tdc = procedure.active_revision.add_type_de_champ(type_champ: 'repetition', libelle: 'Répétition')
build(:type_de_champ_repetition, libelle: 'Répétition', types_de_champ: [ procedure.active_revision.add_type_de_champ(type_champ: 'text', libelle: 'Nom', parent_id: repetition_tdc.stable_id)
build(:type_de_champ_text, libelle: 'Nom', order_place: 1), procedure.active_revision.add_type_de_champ(type_champ: 'text', libelle: 'Prénom', parent_id: repetition_tdc.stable_id)
build(:type_de_champ_text, libelle: 'Prénom', order_place: 2)
]) repetition_tdc
] end
let(:dossier) do
repetition
create(:dossier, procedure: procedure)
end end
before do before do
repetition = dossier.champs repetition = dossier.champs
.find { |champ| champ.libelle == 'Répétition' } .find { |champ| champ.libelle == 'Répétition' }
repetition.add_row repetition.add_row(dossier.revision)
paul_champs, pierre_champs = repetition.rows paul_champs, pierre_champs = repetition.rows
paul_champs.first.update(value: 'Paul') paul_champs.first.update(value: 'Paul')

View file

@ -1190,11 +1190,13 @@ describe Dossier do
end end
context "with champ repetition" do context "with champ repetition" do
let(:procedure) { create(:procedure, types_de_champ: [type_de_champ_repetition]) } let(:procedure) { create(:procedure, :with_repetition) }
let(:type_de_champ_repetition) { build(:type_de_champ_repetition, mandatory: true) } let(:revision) { procedure.active_revision }
let(:type_de_champ_repetition) { revision.types_de_champ.first }
before do before do
create(:type_de_champ_text, mandatory: true, parent: type_de_champ_repetition) type_de_champ_repetition.update(mandatory: true)
revision.children_of(type_de_champ_repetition).first.update(mandatory: true)
end end
context "when no champs" do context "when no champs" do
@ -1215,7 +1217,7 @@ describe Dossier do
let(:champ_with_error) { dossier.champs.first.champs.first } let(:champ_with_error) { dossier.champs.first.champs.first }
before do before do
dossier.champs.first.add_row dossier.champs.first.add_row(dossier.revision)
end end
it 'should have errors' do it 'should have errors' do
@ -1763,8 +1765,8 @@ describe Dossier do
datetime_champ.update(value: Date.today.to_s) datetime_champ.update(value: Date.today.to_s)
text_champ.update(value: 'bonjour') text_champ.update(value: 'bonjour')
# Add two rows then remove previous to last row in order to create a "hole" in the sequence # Add two rows then remove previous to last row in order to create a "hole" in the sequence
repetition_champ.add_row repetition_champ.add_row(repetition_champ.dossier.revision)
repetition_champ.add_row repetition_champ.add_row(repetition_champ.dossier.revision)
repetition_champ.champs.where(row: repetition_champ.champs.last.row - 1).destroy_all repetition_champ.champs.where(row: repetition_champ.champs.last.row - 1).destroy_all
repetition_champ.reload repetition_champ.reload
end end