From fd4d543b20b4ebb1a3553ad4e2a5c849ff18f932 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Fri, 13 May 2022 17:06:59 +0200 Subject: [PATCH] fix test --- spec/models/champ_spec.rb | 22 ++++++++++--------- .../champs/header_section_champ_spec.rb | 16 +++++++++++++- .../concern/tags_substitution_concern_spec.rb | 20 ++++++++++------- spec/models/dossier_spec.rb | 14 +++++++----- 4 files changed, 47 insertions(+), 25 deletions(-) diff --git a/spec/models/champ_spec.rb b/spec/models/champ_spec.rb index 17390abc9..8b57b1d13 100644 --- a/spec/models/champ_spec.rb +++ b/spec/models/champ_spec.rb @@ -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(:type_de_champ_header_section, procedure: procedure) 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 let(:dossier) { create(:dossier, procedure: procedure) } @@ -508,11 +513,9 @@ describe Champ do end 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(:revision) { procedure.published_revision } - let(:rtdc_repetition) { revision.revision_types_de_champ.find { |rtdc| rtdc.type_de_champ.repetition? } } - let(:tdc_text) { build(:type_de_champ_text) } - let(:tdc_integer) { build(:type_de_champ_integer_number) } + let(:procedure) { create(:procedure, :published, :with_type_de_champ, :with_type_de_champ_private, :with_repetition) } + let(:tdc_repetition) { procedure.types_de_champ.find(&:repetition?) } + let(:tdc_text) { procedure.active_revision.children_of(tdc_repetition).first } let(:dossier) { create(:dossier, procedure: procedure) } 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) } before do - create(:procedure_revision_type_de_champ, revision: revision, type_de_champ: tdc_text, parent: rtdc_repetition, position: 1) - create(:procedure_revision_type_de_champ, revision: revision, type_de_champ: tdc_integer, parent: rtdc_repetition, position: 0) + procedure.active_revision.add_type_de_champ(libelle: 'sub integer', type_champ: 'integer_number', parent_id: tdc_repetition.stable_id) end context 'when creating the model directly' do @@ -557,12 +559,12 @@ describe Champ do champ.champs << champ_integer first_row = champ.reload.rows.first 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 first_row = champ.reload.rows.first 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) end diff --git a/spec/models/champs/header_section_champ_spec.rb b/spec/models/champs/header_section_champ_spec.rb index e09c5fb87..1a823e4b0 100644 --- a/spec/models/champs/header_section_champ_spec.rb +++ b/spec/models/champs/header_section_champ_spec.rb @@ -23,12 +23,26 @@ describe Champs::HeaderSectionChamp do end 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(:first_header) { dossier.champs.first.champs[0] } 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 expect(first_header.section_index).to eq 1 expect(second_header.section_index).to eq 2 diff --git a/spec/models/concern/tags_substitution_concern_spec.rb b/spec/models/concern/tags_substitution_concern_spec.rb index a15bc1a18..e5ecb7970 100644 --- a/spec/models/concern/tags_substitution_concern_spec.rb +++ b/spec/models/concern/tags_substitution_concern_spec.rb @@ -161,19 +161,23 @@ describe TagsSubstitutionConcern, type: :model do context 'when the procedure has a type de champ repetition' do let(:template) { '--Répétition--' } - let(:types_de_champ) do - [ - build(:type_de_champ_repetition, libelle: 'Répétition', types_de_champ: [ - build(:type_de_champ_text, libelle: 'Nom', order_place: 1), - build(:type_de_champ_text, libelle: 'Prénom', order_place: 2) - ]) - ] + let(:repetition) do + repetition_tdc = procedure.active_revision.add_type_de_champ(type_champ: 'repetition', libelle: 'Répétition') + procedure.active_revision.add_type_de_champ(type_champ: 'text', libelle: 'Nom', parent_id: repetition_tdc.stable_id) + procedure.active_revision.add_type_de_champ(type_champ: 'text', libelle: 'Prénom', parent_id: repetition_tdc.stable_id) + + repetition_tdc + end + + let(:dossier) do + repetition + create(:dossier, procedure: procedure) end before do repetition = dossier.champs .find { |champ| champ.libelle == 'Répétition' } - repetition.add_row + repetition.add_row(dossier.revision) paul_champs, pierre_champs = repetition.rows paul_champs.first.update(value: 'Paul') diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 6ab4ea262..6f2ee8056 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -1190,11 +1190,13 @@ describe Dossier do end context "with champ repetition" do - let(:procedure) { create(:procedure, types_de_champ: [type_de_champ_repetition]) } - let(:type_de_champ_repetition) { build(:type_de_champ_repetition, mandatory: true) } + let(:procedure) { create(:procedure, :with_repetition) } + let(:revision) { procedure.active_revision } + let(:type_de_champ_repetition) { revision.types_de_champ.first } 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 context "when no champs" do @@ -1215,7 +1217,7 @@ describe Dossier do let(:champ_with_error) { dossier.champs.first.champs.first } before do - dossier.champs.first.add_row + dossier.champs.first.add_row(dossier.revision) end it 'should have errors' do @@ -1763,8 +1765,8 @@ describe Dossier do datetime_champ.update(value: Date.today.to_s) text_champ.update(value: 'bonjour') # 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.add_row(repetition_champ.dossier.revision) + repetition_champ.add_row(repetition_champ.dossier.revision) repetition_champ.champs.where(row: repetition_champ.champs.last.row - 1).destroy_all repetition_champ.reload end