Merge pull request #10084 from mfo/US/fix-rebase-when-repetition-was-removed

fix(rebase): rebase a dossier when its repetition had been removed on newer version of published_revision crashes
This commit is contained in:
mfo 2024-03-08 16:15:00 +01:00 committed by GitHub
commit 14266232a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 7 deletions

View file

@ -71,7 +71,9 @@ module DossierRebaseConcern
.each { add_new_champs_for_revision(_1) } .each { add_new_champs_for_revision(_1) }
# remove champ # remove champ
changes_by_op[:remove].each { champs_by_stable_id[_1.stable_id].destroy_all } children_champ, root_champ = changes_by_op[:remove].partition(&:child?)
children_champ.each { champs_by_stable_id[_1.stable_id].delete_all }
root_champ.each { champs_by_stable_id[_1.stable_id].delete_all }
# update champ # update champ
changes_by_op[:update].each { apply(_1, champs_by_stable_id[_1.stable_id]) } changes_by_op[:update].each { apply(_1, champs_by_stable_id[_1.stable_id]) }

View file

@ -7,6 +7,7 @@ class ProcedureRevisionChange
def label = @type_de_champ.libelle def label = @type_de_champ.libelle
def stable_id = @type_de_champ.stable_id def stable_id = @type_de_champ.stable_id
def private? = @type_de_champ.private? def private? = @type_de_champ.private?
def child? = @type_de_champ.child?
def to_h = { op:, stable_id:, label:, private: private? } def to_h = { op:, stable_id:, label:, private: private? }

View file

@ -515,8 +515,9 @@ describe Users::DossiersController, type: :controller do
describe '#submit_en_construction' do describe '#submit_en_construction' do
before { sign_in(user) } before { sign_in(user) }
let(:procedure) { create(:procedure, :published, types_de_champ_public:) }
let!(:dossier) { create(:dossier, :en_construction, user: user) } 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(: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(: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' } let(:value) { 'beautiful value' }
@ -560,10 +561,8 @@ describe Users::DossiersController, type: :controller do
context 'when a mandatory champ is missing' do context 'when a mandatory champ is missing' do
let(:value) { nil } let(:value) { nil }
render_views render_views
before do let(:types_de_champ_public) { [{ type: :text, mandatory: true, libelle: 'l' }] }
first_champ.type_de_champ.update(mandatory: true, libelle: 'l') before { subject }
subject
end
it { expect(response).to render_template(:modifier) } it { expect(response).to render_template(:modifier) }
it { expect(response.body).to have_content("doit être rempli") } it { expect(response.body).to have_content("doit être rempli") }
@ -580,6 +579,25 @@ describe Users::DossiersController, type: :controller do
end end
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 context 'when dossier was already submitted' do
before { post :submit_en_construction, params: payload } before { post :submit_en_construction, params: payload }