fix(dossier): fix some reset draft changes edge cases

This commit is contained in:
Paul Chavard 2022-07-06 15:55:09 +02:00
parent eb216f0a33
commit fb37f8c5a8
3 changed files with 7 additions and 1 deletions

View file

@ -777,6 +777,7 @@ class Procedure < ApplicationRecord
if published_revision.present? && draft_changed?
transaction do
reset!
draft_revision.update(attestation_template: nil, dossier_submitted_message: nil)
draft_revision.destroy
update!(draft_revision: create_new_revision(published_revision))
end

View file

@ -10,6 +10,7 @@ FactoryBot.define do
revision.procedure = original.procedure
revision.attestation_template_id = original.attestation_template_id
revision.dossier_submitted_message_id = original.dossier_submitted_message_id
original.revision_types_de_champ_public.each do |r_tdc|
revision.revision_types_de_champ_public << build(:procedure_revision_type_de_champ, from_original: r_tdc)
end

View file

@ -906,17 +906,21 @@ describe Procedure do
end
context "published procedure" do
let(:procedure) { create(:procedure, :published) }
let(:procedure) { create(:procedure, :published, attestation_template: create(:attestation_template), dossier_submitted_message: create(:dossier_submitted_message)) }
it "should reset draft revision" do
procedure.draft_revision.add_type_de_champ(tdc_attributes)
previous_draft_revision = procedure.draft_revision
previous_attestation_template = previous_draft_revision.attestation_template
previous_dossier_submitted_message = previous_draft_revision.dossier_submitted_message
expect(procedure.draft_changed?).to be_truthy
procedure.reset_draft_revision!
expect(procedure.draft_changed?).to be_falsey
expect(procedure.draft_revision).not_to eq(previous_draft_revision)
expect { previous_draft_revision.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect(procedure.draft_revision.attestation_template).to eq(previous_attestation_template)
expect(procedure.draft_revision.dossier_submitted_message).to eq(previous_dossier_submitted_message)
end
end
end