amelioration(importer): evite de re-importer un dossier pointant vers un parent qui est maintenant detruit
This commit is contained in:
parent
14f7e2423d
commit
32088512ff
2 changed files with 20 additions and 1 deletions
|
@ -11,8 +11,14 @@ module Recovery
|
|||
def load
|
||||
@dossiers.map do |dossier|
|
||||
dossier.instance_variable_set :@new_record, true
|
||||
dossier_attributes = dossier.attributes.dup
|
||||
|
||||
Dossier.insert(dossier.attributes)
|
||||
parent_dossier_id = dossier_attributes['parent_dossier_id']
|
||||
if parent_dossier_id && !Dossier.exists?(id: parent_dossier_id)
|
||||
dossier_attributes.delete('parent_dossier_id')
|
||||
end
|
||||
|
||||
Dossier.insert(dossier_attributes)
|
||||
|
||||
if dossier.etablissement.present?
|
||||
Etablissement.insert(dossier.etablissement.attributes)
|
||||
|
|
|
@ -115,5 +115,18 @@ describe 'Recovery::LifeCycle' do
|
|||
|
||||
expect(reloaded_dossier.transfer_logs).to be_present
|
||||
end
|
||||
|
||||
it 'skip parent_dossier_id when dossier does not exists any more' do
|
||||
parent = create(:dossier)
|
||||
dossier.update!(parent_dossier_id: parent.id)
|
||||
@dossier_ids = [dossier.id]
|
||||
|
||||
Recovery::Exporter.new(dossier_ids: @dossier_ids, file_path: fp).dump
|
||||
Dossier.where(id: @dossier_ids).destroy_all
|
||||
parent.destroy
|
||||
Recovery::Importer.new(file_path: fp).load
|
||||
|
||||
expect(Dossier.count).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue