From 1fb051c3cc291aabab80f6feca3c8f73c9b7fc22 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 24 Nov 2022 15:49:15 +0100 Subject: [PATCH] refactor(attestation_template): remove unused code --- .../attestation_templates_controller.rb | 4 --- app/models/attestation_template.rb | 5 --- app/models/dossier.rb | 12 +++---- app/models/procedure.rb | 11 +------ app/models/procedure_revision.rb | 1 - .../attestation_templates_controller_spec.rb | 2 +- ...ttestation_templates_to_procedures_spec.rb | 33 ------------------- 7 files changed, 6 insertions(+), 62 deletions(-) delete mode 100644 spec/lib/tasks/deployment/20221108114545_assign_attestation_templates_to_procedures_spec.rb diff --git a/app/controllers/administrateurs/attestation_templates_controller.rb b/app/controllers/administrateurs/attestation_templates_controller.rb index 9016809fa..3008567b7 100644 --- a/app/controllers/administrateurs/attestation_templates_controller.rb +++ b/app/controllers/administrateurs/attestation_templates_controller.rb @@ -11,8 +11,6 @@ module Administrateurs end def update - @procedure.move_attestation_template_to_procedure! - @attestation_template = @procedure.attestation_template if @attestation_template.update(activated_attestation_params) @@ -27,8 +25,6 @@ module Administrateurs end def create - @procedure.move_attestation_template_to_procedure! - @attestation_template = build_attestation_template(activated_attestation_params) if @attestation_template.save diff --git a/app/models/attestation_template.rb b/app/models/attestation_template.rb index d5e61a70b..63c6b1cb4 100644 --- a/app/models/attestation_template.rb +++ b/app/models/attestation_template.rb @@ -16,7 +16,6 @@ class AttestationTemplate < ApplicationRecord include TagsSubstitutionConcern belongs_to :procedure, inverse_of: :attestation_template - has_many :revisions, class_name: 'ProcedureRevision', inverse_of: :attestation_template, dependent: :nullify has_one_attached :logo has_one_attached :signature @@ -86,10 +85,6 @@ class AttestationTemplate < ApplicationRecord } end - def procedure - super || revisions.last&.procedure - end - def logo_checksum logo.attached? ? logo.checksum : nil end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 595a7149d..d54382fb8 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -742,21 +742,17 @@ class Dossier < ApplicationRecord { lon: lon, lat: lat, zoom: zoom } end - def active_attestation_template - attestation_template || revision.attestation_template - end - def unspecified_attestation_champs - if active_attestation_template&.activated? - active_attestation_template.unspecified_champs_for_dossier(self) + if attestation_template&.activated? + attestation_template.unspecified_champs_for_dossier(self) else [] end end def build_attestation - if active_attestation_template&.activated? - active_attestation_template.attestation_for(self) + if attestation_template&.activated? + attestation_template.attestation_for(self) end end diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 7c51631f1..1d001c70b 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -80,8 +80,6 @@ class Procedure < ApplicationRecord has_many :published_types_de_champ_public, through: :published_revision, source: :types_de_champ_public has_many :published_types_de_champ_private, through: :published_revision, source: :types_de_champ_private - has_one :draft_attestation_template, through: :draft_revision, source: :attestation_template - has_one :published_dossier_submitted_message, dependent: :destroy, through: :published_revision, source: :dossier_submitted_message has_one :draft_dossier_submitted_message, dependent: :destroy, through: :draft_revision, source: :dossier_submitted_message has_many :dossier_submitted_messages, through: :revisions, source: :dossier_submitted_message @@ -597,13 +595,6 @@ class Procedure < ApplicationRecord touch(:whitelisted_at) end - def move_attestation_template_to_procedure! - if draft_attestation_template.present? && draft_attestation_template != attestation_template - draft_attestation_template.update_column(:procedure_id, id) - reload - end - end - def closed_mail_template_attestation_inconsistency_state # As an optimization, don’t check the predefined templates (they are presumed correct) if closed_mail.present? @@ -812,7 +803,7 @@ class Procedure < ApplicationRecord transaction do reset! draft_revision.types_de_champ.filter(&:only_present_on_draft?).each(&:destroy) - draft_revision.update(attestation_template: nil, dossier_submitted_message: nil) + draft_revision.update(dossier_submitted_message: nil) draft_revision.destroy update!(draft_revision: create_new_revision(published_revision)) end diff --git a/app/models/procedure_revision.rb b/app/models/procedure_revision.rb index dee9a65cd..78a9d2cfc 100644 --- a/app/models/procedure_revision.rb +++ b/app/models/procedure_revision.rb @@ -13,7 +13,6 @@ class ProcedureRevision < ApplicationRecord self.implicit_order_column = :created_at belongs_to :procedure, -> { with_discarded }, inverse_of: :revisions, optional: false - belongs_to :attestation_template, inverse_of: :revisions, optional: true, dependent: :destroy belongs_to :dossier_submitted_message, inverse_of: :revisions, optional: true, dependent: :destroy has_many :dossiers, inverse_of: :revision, foreign_key: :revision_id diff --git a/spec/controllers/administrateurs/attestation_templates_controller_spec.rb b/spec/controllers/administrateurs/attestation_templates_controller_spec.rb index e4a338b88..076a0c1f5 100644 --- a/spec/controllers/administrateurs/attestation_templates_controller_spec.rb +++ b/spec/controllers/administrateurs/attestation_templates_controller_spec.rb @@ -133,7 +133,7 @@ describe Administrateurs::AttestationTemplatesController, type: :controller do it do expect(flash.alert).to be_present - expect(procedure.draft_attestation_template).to be nil + expect(procedure.attestation_template).to be nil end end diff --git a/spec/lib/tasks/deployment/20221108114545_assign_attestation_templates_to_procedures_spec.rb b/spec/lib/tasks/deployment/20221108114545_assign_attestation_templates_to_procedures_spec.rb deleted file mode 100644 index 07968e509..000000000 --- a/spec/lib/tasks/deployment/20221108114545_assign_attestation_templates_to_procedures_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -describe '20221108114545_assign_attestation_templates_to_procedures' do - let(:rake_task) { Rake::Task['after_party:assign_attestation_templates_to_procedures'] } - let(:procedure) { create(:procedure, :published) } - let(:attestation_template) { create(:attestation_template) } - let(:attestation_template_old) { create(:attestation_template, procedure: procedure) } - let(:procedure2) { create(:procedure, :published) } - let(:attestation_template2) { create(:attestation_template) } - - subject(:run_task) do - rake_task.invoke - end - - before do - procedure.draft_revision.add_type_de_champ(type_champ: :integer_number, libelle: 'l1') - procedure.publish_revision! - procedure.draft_revision.update!(attestation_template: attestation_template) - procedure.published_revision.update!(attestation_template: attestation_template) - procedure.revisions.first.update!(attestation_template: attestation_template_old) - - procedure2.draft_revision.update!(attestation_template: attestation_template2) - procedure2.published_revision.update!(attestation_template: attestation_template2) - end - after { rake_task.reenable } - - it "assigns attestation template to procedure" do - expect(procedure.attestation_template).to eq(attestation_template_old) - expect(procedure2.attestation_template).to be_nil - run_task - expect(procedure.reload.attestation_template).to eq(attestation_template) - expect(attestation_template_old.reload.procedure_id).to be_nil - expect(procedure2.reload.attestation_template).to eq(attestation_template2) - end -end