Merge pull request #2399 from tchak/remove-references-to-test-procedures

Remove references to `test_procedure`
This commit is contained in:
Pierre de La Morinerie 2018-08-14 16:37:53 +02:00 committed by GitHub
commit 559984c351
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 25 deletions

View file

@ -9,6 +9,7 @@ class Procedure < ApplicationRecord
has_one :module_api_carto, dependent: :destroy has_one :module_api_carto, dependent: :destroy
has_one :attestation_template, dependent: :destroy has_one :attestation_template, dependent: :destroy
has_one :procedure_path
belongs_to :administrateur belongs_to :administrateur
belongs_to :parent_procedure, class_name: 'Procedure' belongs_to :parent_procedure, class_name: 'Procedure'
@ -105,7 +106,7 @@ class Procedure < ApplicationRecord
def after_hide def after_hide
now = Time.now now = Time.now
update(hidden_at: now) update(hidden_at: now)
procedure_path&.hide!(self) procedure_path&.hide!
dossiers.update_all(hidden_at: now) dossiers.update_all(hidden_at: now)
end end
@ -153,10 +154,6 @@ class Procedure < ApplicationRecord
Dossier.new(procedure: self, champs: champs, champs_private: champs_private) Dossier.new(procedure: self, champs: champs, champs_private: champs_private)
end end
def procedure_path
ProcedurePath.find_with_procedure(self)
end
def path def path
procedure_path.path if procedure_path.present? procedure_path.path if procedure_path.present?
end end

View file

@ -3,32 +3,17 @@ class ProcedurePath < ApplicationRecord
validates :administrateur_id, presence: true, allow_blank: false, allow_nil: false validates :administrateur_id, presence: true, allow_blank: false, allow_nil: false
validates :procedure_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 :procedure
belongs_to :administrateur belongs_to :administrateur
def self.find_with_procedure(procedure) def hide!
where(procedure: procedure).or(where(test_procedure: procedure)).last destroy!
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
end end
def publish!(new_procedure) def publish!(new_procedure)
if procedure != new_procedure if procedure&.publiee?
if procedure&.publiee? procedure.archive!
procedure.archive!
end
update(procedure: new_procedure)
end end
update!(procedure: new_procedure)
end end
end end