refactor(dossier_loader): ignore champs from old revisions

This commit is contained in:
Paul Chavard 2023-12-01 16:00:23 +00:00
parent 8687d73a73
commit 2eb1f54aa1
3 changed files with 9 additions and 9 deletions

View file

@ -118,9 +118,9 @@ class DossierPreloader
dossier.association(:champs_private_all).target += champs
end
parent.association(name).target = champs.sort_by do |champ|
[champ.row_id, positions[dossier.revision_id][champ.type_de_champ_id]]
end
parent.association(name).target = champs
.filter { positions[dossier.revision_id][_1.type_de_champ_id].present? }
.sort_by { [_1.row_id, positions[dossier.revision_id][_1.type_de_champ_id]] }
# Load children champs
champs.filter(&:block?).each do |parent_champ|

View file

@ -26,14 +26,14 @@ describe Recovery::AlignChampWithDossierRevision do
expect(bad_dossier.revision).to eq(procedure.published_revision)
expect(bad_dossier.champs.size).to eq(2)
expect(bad_dossier.champs_public.size).to eq(1)
expect { DossierPreloader.load_one(bad_dossier) }.to raise_error(ArgumentError)
expect { DossierPreloader.load_one(bad_dossier) }.not_to raise_error(ArgumentError)
fixer = Recovery::AlignChampWithDossierRevision.new(Dossier)
fixer.run
expect(fixer.logs.size).to eq(1)
expect(fixer.logs.first.fetch(:status)).to eq(:updated)
expect { DossierPreloader.load_one(bad_dossier) }.not_to raise_error
expect { DossierPreloader.load_one(bad_dossier) }.not_to raise_error(ArgumentError)
expect(bad_dossier.champs.size).to eq(2)
expect(bad_dossier.champs_public.size).to eq(2)
end
@ -53,14 +53,14 @@ describe Recovery::AlignChampWithDossierRevision do
expect(bad_dossier.revision).to eq(procedure.published_revision)
expect(bad_dossier.champs.size).to eq(2)
expect(bad_dossier.champs_public.size).to eq(2)
expect { DossierPreloader.load_one(bad_dossier) }.to raise_error(ArgumentError)
expect { DossierPreloader.load_one(bad_dossier) }.not_to raise_error(ArgumentError)
fixer = Recovery::AlignChampWithDossierRevision.new(Dossier)
fixer.run(destroy_extra_champs: true)
expect(fixer.logs.size).to eq(1)
expect(fixer.logs.first.fetch(:status)).to eq(:not_found)
expect { DossierPreloader.load_one(bad_dossier) }.not_to raise_error
expect { DossierPreloader.load_one(bad_dossier) }.not_to raise_error(ArgumentError)
expect(bad_dossier.champs.size).to eq(1)
expect(bad_dossier.champs_public.size).to eq(1)
end

View file

@ -26,11 +26,11 @@ describe 'Recovery::Revision::LifeCycle' do
end
it do
expect { DossierPreloader.load_one(dossier) }.to raise_error(ArgumentError)
expect { DossierPreloader.load_one(dossier) }.not_to raise_error(ArgumentError)
expect(dossier.champs_public.size).to eq(1)
expect(dossier.champs.size).to eq(2)
importer.load
expect { DossierPreloader.load_one(dossier) }.not_to raise_error
expect { DossierPreloader.load_one(dossier) }.not_to raise_error(ArgumentError)
expect(dossier.champs_public.size).to eq(2)
end
end