diff --git a/spec/controllers/api/v1/dossiers_controller_spec.rb b/spec/controllers/api/v1/dossiers_controller_spec.rb index 08dd00196..bc9b08f0b 100644 --- a/spec/controllers/api/v1/dossiers_controller_spec.rb +++ b/spec/controllers/api/v1/dossiers_controller_spec.rb @@ -263,9 +263,9 @@ describe API::V1::DossiersController do it 'should have rows' do expect(subject.size).to eq(2) expect(subject[0][:id]).to eq(1) - expect(subject[0][:champs].size).to eq(3) - expect(subject[0][:champs].map { |c| c[:value] }).to eq(['text', 'text', '42']) - expect(subject[0][:champs].map { |c| c[:type_de_champ][:type_champ] }).to eq(['text', 'text', 'number']) + expect(subject[0][:champs].size).to eq(1) + expect(subject[0][:champs].map { |c| c[:value] }).to eq(['text']) + expect(subject[0][:champs].map { |c| c[:type_de_champ][:type_champ] }).to eq(['text']) end end end diff --git a/spec/factories/champ.rb b/spec/factories/champ.rb index 7d9e38aed..d531fd980 100644 --- a/spec/factories/champ.rb +++ b/spec/factories/champ.rb @@ -226,28 +226,6 @@ FactoryBot.define do parent = revision.revision_types_de_champ.find { |rtdc| rtdc.type_de_champ == champ_repetition.type_de_champ } types_de_champ = revision.revision_types_de_champ.filter { |rtdc| rtdc.parent == parent }.map(&:type_de_champ) - type_de_champ_text = types_de_champ.find { |tdc| tdc.libelle == 'Nom' } - if !type_de_champ_text - type_de_champ_text = build(:type_de_champ_text, - procedure: champ_repetition.type_de_champ.procedure, - position: 0, - private: champ_repetition.private?, - parent: parent, - libelle: 'Nom') - types_de_champ.push(type_de_champ_text) - end - - type_de_champ_number = types_de_champ.find { |tdc| tdc.libelle == 'Age' } - if !type_de_champ_number - type_de_champ_number = build(:type_de_champ_number, - procedure: champ_repetition.type_de_champ.procedure, - position: 1, - private: champ_repetition.private?, - parent: parent, - libelle: 'Age') - types_de_champ.push(type_de_champ_number) - end - evaluator.rows.times do |row| champ_repetition.champs << types_de_champ.map do |type_de_champ| build(:"champ_#{type_de_champ.type_champ}", dossier: champ_repetition.dossier, row: row, type_de_champ: type_de_champ, parent: champ_repetition, private: champ_repetition.private?) diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index 4cc464f85..380fa69ce 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -19,7 +19,6 @@ FactoryBot.define do transient do administrateur {} instructeurs { [] } - types_de_champ { [] } types_de_champ_public { [] } types_de_champ_private { [] } updated_at { nil } @@ -27,10 +26,6 @@ FactoryBot.define do end after(:build) do |procedure, evaluator| - if evaluator.types_de_champ.present? - raise "use types_de_champ_public instead of types_de_champ" - end - initial_revision = build(:procedure_revision, procedure: procedure, dossier_submitted_message: evaluator.dossier_submitted_message) if evaluator.types_de_champ_public.present? @@ -347,7 +342,11 @@ FactoryBot.define do if libelle == 'drop_down_list' libelle = 'simple_drop_down_list' end - build(:"type_de_champ_#{type_champ}", procedure: procedure, mandatory: true, libelle: libelle, position: index) + if type_champ == 'repetition' + build(:type_de_champ_repetition, :with_types_de_champ, procedure: procedure, mandatory: true, libelle: libelle, position: index) + else + build(:"type_de_champ_#{type_champ}", procedure: procedure, mandatory: true, libelle: libelle, position: index) + end end build(:type_de_champ_drop_down_list, :long, procedure: procedure, mandatory: true, libelle: 'simple_choice_drop_down_list_long', position: TypeDeChamp.type_champs.size) build(:type_de_champ_multiple_drop_down_list, :long, procedure: procedure, mandatory: true, libelle: 'multiple_choice_drop_down_list_long', position: TypeDeChamp.type_champs.size + 1) @@ -360,7 +359,11 @@ FactoryBot.define do if libelle == 'drop_down_list' libelle = 'simple_drop_down_list' end - build(:"type_de_champ_#{type_champ}", procedure: procedure, libelle: libelle, position: index) + if type_champ == 'repetition' + build(:type_de_champ_repetition, :with_types_de_champ, procedure: procedure, libelle: libelle, position: index) + else + build(:"type_de_champ_#{type_champ}", procedure: procedure, libelle: libelle, position: index) + end end end end diff --git a/spec/graphql/annotation_spec.rb b/spec/graphql/annotation_spec.rb index 704e67450..17bffffc5 100644 --- a/spec/graphql/annotation_spec.rb +++ b/spec/graphql/annotation_spec.rb @@ -1,6 +1,6 @@ RSpec.describe Mutations::DossierModifierAnnotation, type: :graphql do let(:admin) { create(:administrateur) } - let(:procedure) { create(:procedure, :published, :for_individual, :with_private_repetition, :with_type_de_champ_private, administrateurs: [admin]) } + let(:procedure) { create(:procedure, :published, :for_individual, types_de_champ_private: [{ type: :repetition, children: [{ libelle: 'Nom' }, { type: :integer_number, libelle: 'Age' }] }, {}], administrateurs: [admin]) } let(:dossiers) { [] } let(:instructeur) { create(:instructeur, followed_dossiers: dossiers) } diff --git a/spec/lib/tasks/deployment/20220705164551_remove_unused_champs_spec.rb b/spec/lib/tasks/deployment/20220705164551_remove_unused_champs_spec.rb index cbd5379c7..3443bfc56 100644 --- a/spec/lib/tasks/deployment/20220705164551_remove_unused_champs_spec.rb +++ b/spec/lib/tasks/deployment/20220705164551_remove_unused_champs_spec.rb @@ -14,9 +14,9 @@ describe '20220705164551_remove_unused_champs' do describe 'remove_unused_champs' do it "with bad champs" do - expect(Champ.where(dossier: dossier).count).to eq(39) + expect(Champ.where(dossier: dossier).count).to eq(37) run_task - expect(Champ.where(dossier: dossier).count).to eq(38) + expect(Champ.where(dossier: dossier).count).to eq(36) end end end diff --git a/spec/models/champ_shared_example.rb b/spec/models/champ_shared_example.rb index 4d9c3d3aa..a50ecc255 100644 --- a/spec/models/champ_shared_example.rb +++ b/spec/models/champ_shared_example.rb @@ -31,7 +31,7 @@ shared_examples 'champ_spec' do end context 'when repetition not blank' do - let(:type_de_champ) { build(:type_de_champ_repetition) } + let(:type_de_champ) { build(:type_de_champ_repetition, :with_types_de_champ, procedure: build(:procedure)) } let(:champ) { build(:champ_repetition, type_de_champ: type_de_champ) } it { expect(champ.blank?).to be(false) } diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 4d0184228..e24976709 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -1749,11 +1749,11 @@ describe Dossier do context 'for Champs::Repetition with rows, original_champ.repetition and rows are duped' do let(:dossier) { create(:dossier) } - let(:type_de_champ_repetition) { create(:type_de_champ_repetition, procedure: dossier.procedure) } + let(:type_de_champ_repetition) { create(:type_de_champ_repetition, :with_types_de_champ, procedure: dossier.procedure) } let(:champ_repetition) { create(:champ_repetition, type_de_champ: type_de_champ_repetition, dossier: dossier) } before { dossier.champs_public << champ_repetition } - it { expect(Champs::RepetitionChamp.where(dossier: new_dossier).first.champs.count).to eq(4) } + it { expect(Champs::RepetitionChamp.where(dossier: new_dossier).first.champs.count).to eq(2) } it { expect(Champs::RepetitionChamp.where(dossier: new_dossier).first.champs.ids).not_to eq(champ_repetition.champs.ids) } end diff --git a/spec/services/procedure_export_service_spec.rb b/spec/services/procedure_export_service_spec.rb index a084e3410..a0e737a7d 100644 --- a/spec/services/procedure_export_service_spec.rb +++ b/spec/services/procedure_export_service_spec.rb @@ -342,6 +342,7 @@ describe ProcedureExportService do end describe 'Repetitions sheet' do + let(:procedure) { create(:procedure, :published, :for_individual, types_de_champ_public: [{ type: :repetition, children: [{ libelle: 'Nom' }, { libelle: 'Age' }] }]) } let!(:dossiers) do [ create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure: procedure), @@ -403,7 +404,7 @@ describe ProcedureExportService do context 'with non unique labels' do let(:dossier) { create(:dossier, :en_instruction, :with_populated_champs, :with_individual, procedure: procedure) } let(:champ_repetition) { dossier.champs_public.find { |champ| champ.type_champ == 'repetition' } } - let(:type_de_champ_repetition) { create(:type_de_champ_repetition, procedure: procedure, libelle: champ_repetition.libelle) } + let(:type_de_champ_repetition) { create(:type_de_champ_repetition, :with_types_de_champ, procedure: procedure, libelle: champ_repetition.libelle) } let!(:another_champ_repetition) { create(:champ_repetition, type_de_champ: type_de_champ_repetition, dossier: dossier) } it 'should have sheets' do