From 5e25547b7bc16ee8054d7d20b8b43fd2ee2104de Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Tue, 2 Jul 2024 14:10:23 +0200 Subject: [PATCH] fix(attestation): don't delete v1 published when building a v2 --- .../administrateurs/attestation_template_v2s_controller.rb | 2 +- .../administrateurs/attestation_template_v2s_controller_spec.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/administrateurs/attestation_template_v2s_controller.rb b/app/controllers/administrateurs/attestation_template_v2s_controller.rb index 269373773..4585f1c39 100644 --- a/app/controllers/administrateurs/attestation_template_v2s_controller.rb +++ b/app/controllers/administrateurs/attestation_template_v2s_controller.rb @@ -130,7 +130,7 @@ module Administrateurs def build_default_attestation state = should_edit_draft? ? :draft : :published - @procedure.build_attestation_template(version: 2, json_body: AttestationTemplate::TIPTAP_BODY_DEFAULT, activated: true, state:) + @procedure.attestation_templates.build(version: 2, json_body: AttestationTemplate::TIPTAP_BODY_DEFAULT, activated: true, state:) end def should_edit_draft? = !@procedure.brouillon? diff --git a/spec/controllers/administrateurs/attestation_template_v2s_controller_spec.rb b/spec/controllers/administrateurs/attestation_template_v2s_controller_spec.rb index dea76c8f9..e82085bc9 100644 --- a/spec/controllers/administrateurs/attestation_template_v2s_controller_spec.rb +++ b/spec/controllers/administrateurs/attestation_template_v2s_controller_spec.rb @@ -140,6 +140,7 @@ describe Administrateurs::AttestationTemplateV2sController, type: :controller do subject expect(assigns(:attestation_template).version).to eq(2) expect(assigns(:attestation_template)).to be_draft + expect(attestation_template.reload).to be_present end end