diff --git a/app/models/procedure_revision.rb b/app/models/procedure_revision.rb index 9d577a4cf..7e94d0595 100644 --- a/app/models/procedure_revision.rb +++ b/app/models/procedure_revision.rb @@ -272,7 +272,7 @@ class ProcedureRevision < ApplicationRecord .map { [from_h[_1], to_h[_1]] } .flat_map { |from, to| compare_type_de_champ(from.type_de_champ, to.type_de_champ, from_coordinates, to_coordinates) } - (removed + added + moved + changed).sort_by { _1.op == :remove ? from_sids[_1.stable_id] : to_sids[_1.stable_id] } + (removed + added + moved + changed).sort_by { _1.op == :remove ? from_sids.index(_1.stable_id) : to_sids.index(_1.stable_id) } end end diff --git a/spec/models/concern/dossier_rebase_concern_spec.rb b/spec/models/concern/dossier_rebase_concern_spec.rb index ca6b2a6ac..d0cb866ad 100644 --- a/spec/models/concern/dossier_rebase_concern_spec.rb +++ b/spec/models/concern/dossier_rebase_concern_spec.rb @@ -1,6 +1,6 @@ describe DossierRebaseConcern do describe '#can_rebase?' do - let(:procedure) { create(:procedure, :with_type_de_champ_mandatory, :with_type_de_champ_private, :with_yes_no) } + let(:procedure) { create(:procedure, types_de_champ_public: [{ mandatory: true }, { type: :yes_no }], types_de_champ_private: [{}]) } let(:attestation_template) { procedure.draft_revision.attestation_template.find_or_revise! } let(:type_de_champ) { procedure.active_revision.types_de_champ_public.find { |tdc| !tdc.mandatory? } } let(:private_type_de_champ) { procedure.active_revision.types_de_champ_private.first } @@ -252,7 +252,7 @@ describe DossierRebaseConcern do describe "#rebase" do let(:procedure) do create(:procedure, types_de_champ_public: [ - { type: :text, mandatory: true, stable_id: 100 }, + { type: :text, mandatory: true, stable_id: 1 }, { type: :repetition, stable_id: 101, mandatory: true, children: [ { type: :text, stable_id: 102 } @@ -266,17 +266,17 @@ describe DossierRebaseConcern do let(:dossier) { create(:dossier, procedure: procedure) } let(:types_de_champ) { procedure.active_revision.types_de_champ } - let(:text_type_de_champ) { types_de_champ.find { _1.stable_id == 100 } } + let(:text_type_de_champ) { types_de_champ.find { _1.stable_id == 1 } } let(:repetition_type_de_champ) { types_de_champ.find { _1.stable_id == 101 } } let(:repetition_text_type_de_champ) { types_de_champ.find { _1.stable_id == 102 } } let(:datetime_type_de_champ) { types_de_champ.find { _1.stable_id == 103 } } let(:yes_no_type_de_champ) { types_de_champ.find { _1.stable_id == 104 } } - let(:text_champ) { dossier.champs_public.find { _1.stable_id == 100 } } + let(:text_champ) { dossier.champs_public.find { _1.stable_id == 1 } } let(:repetition_champ) { dossier.champs_public.find { _1.stable_id == 101 } } let(:datetime_champ) { dossier.champs_public.find { _1.stable_id == 103 } } - let(:rebased_text_champ) { dossier.champs_public.find { _1.stable_id == 100 } } + let(:rebased_text_champ) { dossier.champs_public.find { _1.stable_id == 1 } } let(:rebased_repetition_champ) { dossier.champs_public.find { _1.stable_id == 101 } } let(:rebased_datetime_champ) { dossier.champs_public.find { _1.stable_id == 103 } } let(:rebased_number_champ) { dossier.champs_public.find { _1.stable_id == 105 } } diff --git a/spec/models/procedure_revision_spec.rb b/spec/models/procedure_revision_spec.rb index 9f3277267..a30030d3c 100644 --- a/spec/models/procedure_revision_spec.rb +++ b/spec/models/procedure_revision_spec.rb @@ -525,14 +525,6 @@ describe ProcedureRevision do it do is_expected.to eq([ - { - op: :move, - label: new_draft_second_tdc.libelle, - private: false, - from: 1, - to: 2, - stable_id: new_draft_second_tdc.stable_id - }, { op: :move, label: new_draft_third_tdc.libelle, @@ -540,6 +532,14 @@ describe ProcedureRevision do from: 2, to: 1, stable_id: new_draft_third_tdc.stable_id + }, + { + op: :move, + label: new_draft_second_tdc.libelle, + private: false, + from: 1, + to: 2, + stable_id: new_draft_second_tdc.stable_id } ]) end