Merge pull request #10651 from tchak/fix-rebase-with-new-pj
fix(rebase): avoid errors when adding pj champs to a new revision
This commit is contained in:
commit
b9000eeb65
2 changed files with 13 additions and 9 deletions
|
@ -62,13 +62,6 @@ module DossierRebaseConcern
|
|||
.transform_values { Champ.where(id: _1) }
|
||||
.tap { _1.default = Champ.none }
|
||||
|
||||
# add champ
|
||||
changes_by_op[:add]
|
||||
.map { target_coordinates_by_stable_id[_1.stable_id] }
|
||||
# add parent champs first so we can then add children
|
||||
.sort_by { _1.child? ? 1 : 0 }
|
||||
.each { add_new_champs_for_revision(_1) }
|
||||
|
||||
# remove champ
|
||||
children_champ, root_champ = changes_by_op[:remove].partition(&:child?)
|
||||
children_champ.each { champs_by_stable_id[_1.stable_id].destroy_all }
|
||||
|
@ -79,6 +72,13 @@ module DossierRebaseConcern
|
|||
|
||||
# update dossier revision
|
||||
update_column(:revision_id, target_revision.id)
|
||||
|
||||
# add champ (after changing dossier revision to avoid errors)
|
||||
changes_by_op[:add]
|
||||
.map { target_coordinates_by_stable_id[_1.stable_id] }
|
||||
# add parent champs first so we can then add children
|
||||
.sort_by { _1.child? ? 1 : 0 }
|
||||
.each { add_new_champs_for_revision(_1) }
|
||||
end
|
||||
|
||||
def apply(change, champs)
|
||||
|
|
|
@ -312,6 +312,10 @@ describe DossierRebaseConcern do
|
|||
type_champ: TypeDeChamp.type_champs.fetch(:text),
|
||||
libelle: "Un champ text"
|
||||
})
|
||||
procedure.draft_revision.add_type_de_champ({
|
||||
type_champ: TypeDeChamp.type_champs.fetch(:piece_justificative),
|
||||
libelle: "Un champ pj"
|
||||
})
|
||||
procedure.draft_revision.find_and_ensure_exclusive_use(text_type_de_champ.stable_id).update(mandatory: false, libelle: "nouveau libelle")
|
||||
procedure.draft_revision.find_and_ensure_exclusive_use(datetime_type_de_champ.stable_id).update(type_champ: TypeDeChamp.type_champs.fetch(:date))
|
||||
procedure.draft_revision.find_and_ensure_exclusive_use(repetition_text_type_de_champ.stable_id).update(libelle: "nouveau libelle dans une repetition")
|
||||
|
@ -361,8 +365,8 @@ describe DossierRebaseConcern do
|
|||
|
||||
expect(procedure.revisions.size).to eq(3)
|
||||
expect(dossier.revision).to eq(procedure.published_revision)
|
||||
expect(dossier.champs_public.size).to eq(6)
|
||||
expect(dossier.champs.count(&:public?)).to eq(12)
|
||||
expect(dossier.champs_public.size).to eq(7)
|
||||
expect(dossier.champs.count(&:public?)).to eq(13)
|
||||
expect(rebased_text_champ.value).to eq(text_champ.value)
|
||||
expect(rebased_text_champ.type_de_champ).not_to eq(text_champ.type_de_champ)
|
||||
expect(rebased_datetime_champ.type_champ).to eq(TypeDeChamp.type_champs.fetch(:date))
|
||||
|
|
Loading…
Reference in a new issue