diff --git a/app/models/concerns/champs_validate_concern.rb b/app/models/concerns/champs_validate_concern.rb index ac8d0e1aa..97c0c791e 100644 --- a/app/models/concerns/champs_validate_concern.rb +++ b/app/models/concerns/champs_validate_concern.rb @@ -29,7 +29,7 @@ module ChampsValidateConcern end def in_dossier_revision? - dossier.revision.types_de_champ.any? { _1.stable_id == stable_id } && is_type?(type_de_champ.type_champ) + dossier.revision.in_revision?(stable_id) && is_type?(type_de_champ.type_champ) end end end diff --git a/app/models/concerns/dossier_champs_concern.rb b/app/models/concerns/dossier_champs_concern.rb index f6e9baf0a..0f373bd74 100644 --- a/app/models/concerns/dossier_champs_concern.rb +++ b/app/models/concerns/dossier_champs_concern.rb @@ -109,6 +109,7 @@ module DossierChampsConcern def repetition_row_ids(type_de_champ) return [] if !type_de_champ.repetition? + return [] if !revision.in_revision?(type_de_champ.stable_id) stable_ids = revision.children_of(type_de_champ).map(&:stable_id) champs.filter { _1.stable_id.in?(stable_ids) && _1.row_id.present? } diff --git a/app/models/procedure_revision.rb b/app/models/procedure_revision.rb index 94f896d62..cffc1c96b 100644 --- a/app/models/procedure_revision.rb +++ b/app/models/procedure_revision.rb @@ -203,6 +203,10 @@ class ProcedureRevision < ApplicationRecord coordinate_for(tdc).parent_type_de_champ end + def in_revision?(stable_id) + types_de_champ.any? { _1.stable_id == stable_id } + end + def dependent_conditions(tdc) stable_id = tdc.stable_id diff --git a/spec/models/concerns/dossier_champs_concern_spec.rb b/spec/models/concerns/dossier_champs_concern_spec.rb index 1b8a920e8..351a7a1b7 100644 --- a/spec/models/concerns/dossier_champs_concern_spec.rb +++ b/spec/models/concerns/dossier_champs_concern_spec.rb @@ -154,6 +154,21 @@ RSpec.describe DossierChampsConcern do subject { dossier.repetition_row_ids(type_de_champ_repetition) } it { expect(subject.size).to eq(1) } + + context 'given a type de champ repetition in another revision' do + let(:procedure) { create(:procedure, :published, types_de_champ_public:, types_de_champ_private:) } + let(:draft) { procedure.draft_revision } + let(:errored_stable_id) { 666 } + let(:type_de_champ_repetition) { procedure.active_revision.types_de_champ.find { _1.stable_id == errored_stable_id } } + before do + dossier + tdc_repetition = draft.add_type_de_champ(type_champ: :repetition, libelle: "repetition", stable_id: errored_stable_id) + draft.add_type_de_champ(type_champ: :text, libelle: "t1", parent_stable_id: tdc_repetition.stable_id) + procedure.publish_revision! + end + + it { expect { subject }.not_to raise_error } + end end describe '#project_rows_for' do