From 1c2e93ed419d29ed6a40bd9078b11346a85492cb Mon Sep 17 00:00:00 2001 From: Nicolas Bouilleaud Date: Mon, 29 Apr 2019 15:29:13 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Fix=20=E2=80=9Cnearing=5Fend=5Fof=5Fretenti?= =?UTF-8?q?on=E2=80=9D=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `nearing_end_of_retention` test creates a `just_expired_dossier` “six months ago”, which is 29 Oct 2018. The autumn DST change was on October 28; this is the first time this test runs under these conditions. We workaround the time offset by creating the dossier one hour earlier. This is technically a workaround, not a fix: the date arithmetics in `nearing_end_of_retention` are probably wrong. It looks like it’s comparing intervals, which seems error-prone, while it should be comparing dates. For now, I’m just making the tests pass. --- spec/models/dossier_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 0ab8763f5..ea85160af 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -31,7 +31,7 @@ describe Dossier do let(:procedure) { create(:procedure, duree_conservation_dossiers_dans_ds: 6) } let!(:young_dossier) { create(:dossier, procedure: procedure) } let!(:expiring_dossier) { create(:dossier, :en_instruction, en_instruction_at: 170.days.ago, procedure: procedure) } - let!(:just_expired_dossier) { create(:dossier, :en_instruction, en_instruction_at: (6.months + 1.second).ago, procedure: procedure) } + let!(:just_expired_dossier) { create(:dossier, :en_instruction, en_instruction_at: (6.months + 1.hour + 1.second).ago, procedure: procedure) } let!(:long_expired_dossier) { create(:dossier, :en_instruction, en_instruction_at: 1.year.ago, procedure: procedure) } context 'with default delay to end of retention' do From 8bd1064532bc76b319578470f45caca2a887f3f7 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 29 Apr 2019 11:52:30 +0200 Subject: [PATCH 2/2] tasks: populate Procedure.administrateurs even for hidden procedures The previous procedure migration (created in f7af01e0dc7c38b598a849f062b181b3f8c55a62) worked fine, but didn't run on hidden procedures (due to the default scope). --- app/models/procedure.rb | 2 -- ...administrateurs_for_hidden_procedures.rake | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 lib/tasks/deployment/20190429103024_add_procedure_administrateur_to_administrateurs_for_hidden_procedures.rake diff --git a/app/models/procedure.rb b/app/models/procedure.rb index b2e6cb781..7c097252f 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -1,8 +1,6 @@ require Rails.root.join('lib', 'percentile') class Procedure < ApplicationRecord - self.ignored_columns = [:administrateur_id] - MAX_DUREE_CONSERVATION = 36 has_many :types_de_piece_justificative, -> { ordered }, dependent: :destroy diff --git a/lib/tasks/deployment/20190429103024_add_procedure_administrateur_to_administrateurs_for_hidden_procedures.rake b/lib/tasks/deployment/20190429103024_add_procedure_administrateur_to_administrateurs_for_hidden_procedures.rake new file mode 100644 index 000000000..182387bf4 --- /dev/null +++ b/lib/tasks/deployment/20190429103024_add_procedure_administrateur_to_administrateurs_for_hidden_procedures.rake @@ -0,0 +1,19 @@ +namespace :after_party do + desc 'Deployment task: add_procedure_administrateur_to_administrateurs_for_hidden_procedures' + task add_procedure_administrateur_to_administrateurs_for_hidden_procedures: :environment do + rake_puts "Running deploy task: 'add_procedure_administrateur_to_administrateurs_for_hidden_procedures'" + hidden_procedures = Procedure.unscoped.hidden.includes(:administrateurs) + progress = ProgressReport.new(hidden_procedures.count) + + hidden_procedures.find_each do |procedure| + deprecated_administrateur = Administrateur.find_by(id: procedure.administrateur_id) + if deprecated_administrateur && !procedure.administrateurs.include?(deprecated_administrateur) + procedure.administrateurs << deprecated_administrateur + end + progress.inc + end + + progress.finish + AfterParty::TaskRecord.create version: '20190429103024' + end +end