refactor(dossier): clone only current revision champs
This commit is contained in:
parent
deb19177f7
commit
8687d73a73
2 changed files with 19 additions and 17 deletions
|
@ -42,11 +42,10 @@ module DossierCloneConcern
|
|||
end
|
||||
|
||||
def make_diff(editing_fork)
|
||||
# TODO: remove champs_public_all usage
|
||||
origin_champs_index = champs_public_all.index_by(&:stable_id_with_row)
|
||||
forked_champs_index = editing_fork.champs_public_all.index_by(&:stable_id_with_row)
|
||||
origin_champs_index = champs_for_revision(:public).index_by(&:stable_id_with_row)
|
||||
forked_champs_index = editing_fork.champs_for_revision(:public).index_by(&:stable_id_with_row)
|
||||
updated_champs_index = editing_fork
|
||||
.champs_public_all
|
||||
.champs_for_revision(:public)
|
||||
.filter { _1.updated_at > editing_fork.created_at }
|
||||
.index_by(&:stable_id_with_row)
|
||||
|
||||
|
@ -81,7 +80,7 @@ module DossierCloneConcern
|
|||
dossier_attributes += [:groupe_instructeur_id] if fork
|
||||
relationships = [:individual, :etablissement]
|
||||
|
||||
cloned_champs = champs
|
||||
cloned_champs = champs_for_revision
|
||||
.index_by(&:id)
|
||||
.transform_values { [_1, _1.clone(fork)] }
|
||||
|
||||
|
@ -143,7 +142,7 @@ module DossierCloneConcern
|
|||
end
|
||||
|
||||
def apply_diff(diff)
|
||||
champs_index = (champs_public_all + diff[:added]).index_by(&:stable_id_with_row)
|
||||
champs_index = (champs_for_revision(:public) + diff[:added]).index_by(&:stable_id_with_row)
|
||||
|
||||
diff[:added].each do |champ|
|
||||
if champ.child?
|
||||
|
|
|
@ -1,20 +1,23 @@
|
|||
RSpec.describe DossierCloneConcern do
|
||||
let(:procedure) do
|
||||
create(:procedure, types_de_champ_public: [
|
||||
create(:procedure, types_de_champ_public:, types_de_champ_private:).tap(&:publish!)
|
||||
end
|
||||
let(:types_de_champ_public) do
|
||||
[
|
||||
{ type: :text, libelle: "Un champ text", stable_id: 99 },
|
||||
{ type: :text, libelle: "Un autre champ text", stable_id: 991 },
|
||||
{ type: :yes_no, libelle: "Un champ yes no", stable_id: 992 },
|
||||
{ type: :repetition, libelle: "Un champ répétable", stable_id: 993, mandatory: true, children: [{ type: :text, libelle: 'Nom', stable_id: 994 }] }
|
||||
])
|
||||
]
|
||||
end
|
||||
let(:types_de_champ_private) { [] }
|
||||
let(:dossier) { create(:dossier, :en_construction, procedure:) }
|
||||
let(:forked_dossier) { dossier.find_or_create_editing_fork(dossier.user) }
|
||||
|
||||
before { procedure.publish! }
|
||||
|
||||
describe '#clone' do
|
||||
let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private) }
|
||||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_populated_champs, procedure:) }
|
||||
let(:types_de_champ_public) { [{}] }
|
||||
let(:types_de_champ_private) { [{}] }
|
||||
let(:fork) { false }
|
||||
let(:new_dossier) { dossier.clone(fork:) }
|
||||
|
||||
|
@ -137,9 +140,9 @@ RSpec.describe DossierCloneConcern do
|
|||
end
|
||||
|
||||
context 'for Champs::PieceJustificative, original_champ.piece_justificative_file is duped' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:champ_piece_justificative) { create(:champ_piece_justificative, dossier_id: dossier.id) }
|
||||
before { dossier.champs_public << champ_piece_justificative }
|
||||
let(:types_de_champ_public) { [{ type: :piece_justificative }] }
|
||||
let(:champ_piece_justificative) { dossier.champs_public.first }
|
||||
|
||||
it { expect(Champs::PieceJustificativeChamp.where(dossier: new_dossier).first.piece_justificative_file.first.blob).to eq(champ_piece_justificative.piece_justificative_file.first.blob) }
|
||||
end
|
||||
|
||||
|
@ -181,8 +184,8 @@ RSpec.describe DossierCloneConcern do
|
|||
it { expect(new_dossier.champs_public[0].updated_at).to eq(dossier.champs_public[0].updated_at) }
|
||||
|
||||
context "piece justificative champ" do
|
||||
let(:champ_pj) { create(:champ_piece_justificative, dossier_id: dossier.id) }
|
||||
before { dossier.champs_public << champ_pj.reload }
|
||||
let(:types_de_champ_public) { [{ type: :piece_justificative }] }
|
||||
let(:champ_pj) { dossier.champs_public.first }
|
||||
|
||||
it {
|
||||
champ_pj_fork = Champs::PieceJustificativeChamp.where(dossier: new_dossier).first
|
||||
|
|
Loading…
Reference in a new issue