fix(fork): don't let active storage override our champ#updated_at after a transaction

This commit is contained in:
Colin Darie 2023-05-11 15:57:28 +02:00
parent 9b52f0902d
commit 0d21450f8a
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
2 changed files with 27 additions and 3 deletions

View file

@ -109,13 +109,16 @@ module DossierCloneConcern
cloned_dossier.save!
if fork
cloned_champs.values.each do |(original, champ)|
champ.update_columns(created_at: original.created_at, updated_at: original.updated_at)
end
cloned_dossier.rebase!
end
end
if fork
cloned_champs.values.each do |(original, champ)|
champ.update_columns(created_at: original.created_at, updated_at: original.updated_at)
end
end
cloned_dossier.reload
end

View file

@ -162,6 +162,27 @@ RSpec.describe DossierCloneConcern do
end
end
end
context "as a fork" do
let(:new_dossier) { dossier.clone(fork: true) }
it { expect(new_dossier.editing_fork_origin).to eq(dossier) }
it { expect(new_dossier.champs_public[0].id).not_to eq(dossier.champs_public[0].id) }
it { expect(new_dossier.champs_public[0].created_at).to eq(dossier.champs_public[0].created_at) }
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 }
it {
champ_pj_fork = Champs::PieceJustificativeChamp.where(dossier: new_dossier).first
expect(champ_pj_fork.piece_justificative_file.first.blob).to eq(champ_pj.piece_justificative_file.first.blob)
expect(champ_pj_fork.created_at).to eq(champ_pj.created_at)
expect(champ_pj_fork.updated_at).to eq(champ_pj.updated_at)
}
end
end
end
describe '#make_diff' do