From aec02a9b8a0a5ce1010117784cdd2c44f7e63d2d Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 14 Aug 2018 13:54:39 +0200 Subject: [PATCH] Remove references to `test_procedure` --- app/models/procedure.rb | 7 ++----- app/models/procedure_path.rb | 25 +++++-------------------- 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 54a249bb9..e1b9052a3 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -9,6 +9,7 @@ class Procedure < ApplicationRecord has_one :module_api_carto, dependent: :destroy has_one :attestation_template, dependent: :destroy + has_one :procedure_path belongs_to :administrateur belongs_to :parent_procedure, class_name: 'Procedure' @@ -105,7 +106,7 @@ class Procedure < ApplicationRecord def after_hide now = Time.now update(hidden_at: now) - procedure_path&.hide!(self) + procedure_path&.hide! dossiers.update_all(hidden_at: now) end @@ -153,10 +154,6 @@ class Procedure < ApplicationRecord Dossier.new(procedure: self, champs: champs, champs_private: champs_private) end - def procedure_path - ProcedurePath.find_with_procedure(self) - end - def path procedure_path.path if procedure_path.present? end diff --git a/app/models/procedure_path.rb b/app/models/procedure_path.rb index f34ddf396..197162224 100644 --- a/app/models/procedure_path.rb +++ b/app/models/procedure_path.rb @@ -3,32 +3,17 @@ class ProcedurePath < ApplicationRecord validates :administrateur_id, presence: true, allow_blank: false, allow_nil: false validates :procedure_id, presence: true, allow_blank: false, allow_nil: false - belongs_to :test_procedure, class_name: 'Procedure' belongs_to :procedure belongs_to :administrateur - def self.find_with_procedure(procedure) - where(procedure: procedure).or(where(test_procedure: procedure)).last - end - - def hide!(new_procedure) - if procedure == new_procedure - update(procedure: nil) - end - if test_procedure == new_procedure - update(test_procedure: nil) - end - if procedure.nil? && test_procedure.nil? - destroy - end + def hide! + destroy! end def publish!(new_procedure) - if procedure != new_procedure - if procedure&.publiee? - procedure.archive! - end - update(procedure: new_procedure) + if procedure&.publiee? + procedure.archive! end + update!(procedure: new_procedure) end end