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:
commit
14266232a4
3 changed files with 28 additions and 7 deletions
|
@ -71,7 +71,9 @@ module DossierRebaseConcern
|
|||
.each { add_new_champs_for_revision(_1) }
|
||||
|
||||
# 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
|
||||
changes_by_op[:update].each { apply(_1, champs_by_stable_id[_1.stable_id]) }
|
||||
|
|
|
@ -7,6 +7,7 @@ class ProcedureRevisionChange
|
|||
def label = @type_de_champ.libelle
|
||||
def stable_id = @type_de_champ.stable_id
|
||||
def private? = @type_de_champ.private?
|
||||
def child? = @type_de_champ.child?
|
||||
|
||||
def to_h = { op:, stable_id:, label:, private: private? }
|
||||
|
||||
|
|
|
@ -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 }
|
||||
|
||||
|
|
Loading…
Reference in a new issue