From 0e54ca314df88a756f901788814aa53e73bee2e8 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 8 Mar 2024 15:46:11 +0100 Subject: [PATCH] bug(rebase): rebase a dossier when its repetition had been removed on newer version of published_revision crashes --- .../users/dossiers_controller_spec.rb | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 88d0865ba..ca9dd6328 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -515,8 +515,9 @@ describe Users::DossiersController, type: :controller do describe '#submit_en_construction' do before { sign_in(user) } - - let!(:dossier) { create(:dossier, :en_construction, user: user) } + let(:procedure) { create(:procedure, :published, types_de_champ_public:) } + let(:types_de_champ_public) { [{ type: :text }] } + let(:dossier) { create(:dossier, :en_construction, procedure:, user:) } let(:first_champ) { dossier.owner_editing_fork.champs_public.first } let(:anchor_to_first_champ) { controller.helpers.link_to I18n.t('views.users.dossiers.fix_champ'), modifier_dossier_path(anchor: first_champ.labelledby_id), class: 'error-anchor' } let(:value) { 'beautiful value' } @@ -560,10 +561,8 @@ describe Users::DossiersController, type: :controller do context 'when a mandatory champ is missing' do let(:value) { nil } render_views - before do - first_champ.type_de_champ.update(mandatory: true, libelle: 'l') - subject - end + let(:types_de_champ_public) { [{ type: :text, mandatory: true, libelle: 'l' }] } + before { subject } it { expect(response).to render_template(:modifier) } it { expect(response.body).to have_content("doit ĂȘtre rempli") } @@ -580,6 +579,25 @@ describe Users::DossiersController, type: :controller do end end + context 'when dossier repetition had been removed in newer version' do + let(:dossier) { create(:dossier, :en_construction, :with_populated_champs, procedure:, user:) } + let(:types_de_champ_public) { [{ type: :repetition, libelle: 'repetition', children: [{ type: :text, libelle: 'child' }] }] } + let(:editing_fork) { dossier.owner_editing_fork } + let(:champ_repetition) { editing_fork.champs.find(&:repetition?) } + before do + editing_fork + + procedure.draft_revision.remove_type_de_champ(editing_fork.champs.find(&:repetition?).stable_id) + procedure.publish_revision! + + editing_fork.reload + editing_fork.rebase! + end + let(:submit_payload) { { id: dossier.id } } + + it { expect { subject }.not_to raise_error } + end + context 'when dossier was already submitted' do before { post :submit_en_construction, params: payload }