fix(spec/lint/review): lint and fix spec of previous commits, also fix based on tchak feedback

This commit is contained in:
Martin 2021-12-02 14:21:39 +01:00
parent d87f8b57cc
commit 1bb868714c
9 changed files with 36 additions and 33 deletions

View file

@ -15,13 +15,9 @@ module Instructeurs
dossiers = current_instructeur.dossiers.joins(:groupe_instructeur)
@dossiers_count_per_procedure = dossiers.all_state.group('groupe_instructeurs.procedure_id').reorder(nil).count
@dossiers_a_suivre_count_per_procedure = dossiers.without_followers.en_cours.group('groupe_instructeurs.procedure_id').reorder(nil).count
@dossiers_archived_count_per_procedure = dossiers.archived.group('groupe_instructeurs.procedure_id').count #why not reorder(nil)
@dossiers_archived_count_per_procedure = dossiers.archived.group('groupe_instructeurs.procedure_id').count # why not reorder(nil)
@dossiers_termines_count_per_procedure = dossiers.termine.group('groupe_instructeurs.procedure_id').reorder(nil).count
<<<<<<< HEAD
@dossiers_expirant_count_per_procedure = dossiers.termine_close_to_expiration.group('groupe_instructeurs.procedure_id').count #why not reorder(nil)
=======
@dossiers_expirant_count_per_procedure = dossiers.termine_or_en_construction_close_to_expiration.group('groupe_instructeurs.procedure_id').count # why not reorder(nil)
>>>>>>> 2722cf295 (fixup! feat(instructeurs/procedures#show): add dossier experiant in procedure#show)
groupe_ids = current_instructeur.groupe_instructeurs.pluck(:id)
@followed_dossiers_count_per_procedure = current_instructeur

View file

@ -24,7 +24,6 @@
# last_commentaire_updated_at :datetime
# motivation :text
# private_search_terms :text
# process_expired :boolean default(FALSE)
# processed_at :datetime
# search_terms :text
# state :string
@ -297,7 +296,7 @@ class Dossier < ApplicationRecord
end
scope :interval_termine_close_to_expiration, -> do
state_termine
.where(procedures: { procedure_expires_when_termine_enabled: true})
.where(procedures: { procedure_expires_when_termine_enabled: true })
.where("dossiers.processed_at + dossiers.conservation_extension + (duree_conservation_dossiers_dans_ds * INTERVAL '1 month') - INTERVAL :expires_in < :now", { now: Time.zone.now, expires_in: INTERVAL_BEFORE_EXPIRATION })
end

View file

@ -95,7 +95,6 @@ class ExpiredDossiersDeletionService
deleted_dossier_ids << dossier.id
end
end
user_notifications.each do |(email, dossier_ids)|
dossier_ids = dossier_ids.intersection(deleted_dossier_ids)
if dossier_ids.present?

View file

@ -1,10 +1,10 @@
class AddExpirantsToProcedurePresentations < ActiveRecord::Migration[6.1]
def up
ProcedurePresentation.update_all(%Q(filters = filters || '{"expirant": []}'))
change_column_default :procedure_presentations, :filters, {"tous"=>[], "suivis"=>[], "traites"=>[], "a-suivre"=>[], "archives"=>[], "expirant": []}
change_column_default :procedure_presentations, :filters, { "tous" => [], "suivis" => [], "traites" => [], "a-suivre" => [], "archives" => [], "expirant": [] }
end
def down
change_column_default :procedure_presentations, :filters, {"tous"=>[], "suivis"=>[], "traites"=>[], "a-suivre"=>[], "archives"=>[]}
change_column_default :procedure_presentations, :filters, { "tous" => [], "suivis" => [], "traites" => [], "a-suivre" => [], "archives" => [] }
end
end

View file

@ -2,14 +2,14 @@ namespace :after_party do
desc 'Deployment task: move_traitement_process_expired_to_procedure'
task move_traitement_process_expired_to_procedure: :environment do
procedures = Procedure.joins(dossiers: :traitements).where(dossiers: {traitements: {process_expired: true, process_expired_migrated: false}})
procedures = Procedure.joins(dossiers: :traitements).where(dossiers: { traitements: { process_expired: true, process_expired_migrated: false } })
progress = ProgressReport.new(procedures.count)
procedures.group(:id).find_each do |procedure|
ActiveRecord::Base.transaction do
puts "update traitements from dossier_ids: #{procedure.dossiers.ids}"
Traitement.where(id: procedure.dossiers.ids).update_all(process_expired_migrated: true)
Procedure.update(procedure_expires_when_termine_enabled: true)
procedure.update(procedure_expires_when_termine_enabled: true)
progress.inc
end
end

View file

@ -135,10 +135,12 @@ FactoryBot.define do
if processed_at.present?
dossier.en_construction_at ||= processed_at - 2.minutes
dossier.en_instruction_at ||= processed_at - 1.minute
dossier.processed_at = processed_at
dossier.traitements.accepter(motivation: evaluator.motivation, processed_at: processed_at)
else
dossier.en_construction_at ||= dossier.created_at + 1.minute
dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute
dossier.processed_at = dossier.en_instruction_at + 1.minute
dossier.traitements.accepter(motivation: evaluator.motivation, processed_at: dossier.en_instruction_at + 1.minute)
end
dossier.save!

View file

@ -747,7 +747,6 @@ describe Instructeur, type: :model do
context 'with an expirants dossier' do
let!(:expiring_dossier_termine) { create(:dossier, :accepte, procedure: procedure, processed_at: 175.days.ago) }
let!(:expiring_dossier_en_construction) { create(:dossier, :en_construction, en_construction_at: 175.days.ago, procedure: procedure) }
before { subject }
it { expect(subject['a_suivre']).to eq(1) }

View file

@ -2,8 +2,9 @@ describe ExpiredDossiersDeletionService do
let(:warning_period) { 1.month + 5.days }
let(:conservation_par_defaut) { 3.months }
let(:user) { create(:user) }
let(:procedure) { create(:procedure, :published) }
let(:procedure_2) { create(:procedure, :published) }
let(:procedure_opts) { {} }
let(:procedure) { create(:procedure, :published, procedure_opts) }
let(:procedure_2) { create(:procedure, :published, procedure_opts) }
let(:reference_date) { Date.parse("March 8") }
describe '#process_expired_dossiers_brouillon' do
@ -273,19 +274,18 @@ describe ExpiredDossiersDeletionService do
describe '#send_termine_expiration_notices' do
before { Timecop.freeze(reference_date) }
after { Timecop.return }
before do
Flipper.enable(:procedure_process_expired_dossiers_termine, procedure)
Flipper.enable(:procedure_process_expired_dossiers_termine, procedure_2)
let(:procedure_opts) do
{
procedure_expires_when_termine_enabled: true
}
end
before do
allow(DossierMailer).to receive(:notify_near_deletion_to_user).and_call_original
allow(DossierMailer).to receive(:notify_near_deletion_to_administration).and_call_original
end
context 'with a single dossier' do
let!(:dossier) { create(:dossier, :accepte, :followed, procedure: procedure, processed_at: processed_at) }
let!(:dossier) { create(:dossier, :followed, state: :accepte, procedure: procedure, processed_at: processed_at) }
before { ExpiredDossiersDeletionService.send_termine_expiration_notices }
@ -311,8 +311,8 @@ describe ExpiredDossiersDeletionService do
end
context 'with 2 dossiers to notice' do
let!(:dossier_1) { create(:dossier, :accepte, procedure: procedure, user: user, processed_at: (conservation_par_defaut - 2.weeks + 1.day).ago) }
let!(:dossier_2) { create(:dossier, :accepte, procedure: procedure_2, user: user, processed_at: (conservation_par_defaut - 2.weeks + 1.day).ago) }
let!(:dossier_1) { create(:dossier, state: :accepte, procedure: procedure, user: user, processed_at: (conservation_par_defaut - 2.weeks + 1.day).ago) }
let!(:dossier_2) { create(:dossier, state: :accepte, procedure: procedure_2, user: user, processed_at: (conservation_par_defaut - 2.weeks + 1.day).ago) }
let!(:instructeur) { create(:instructeur) }
@ -331,7 +331,7 @@ describe ExpiredDossiersDeletionService do
context 'when an instructeur is also administrateur' do
let!(:administrateur) { procedure.administrateurs.first }
let!(:dossier) { create(:dossier, :accepte, procedure: procedure, processed_at: (conservation_par_defaut - 2.weeks + 1.day).ago) }
let!(:dossier) { create(:dossier, state: :accepte, procedure: procedure, processed_at: (conservation_par_defaut - 2.weeks + 1.day).ago) }
before do
administrateur.instructeur.followed_dossiers << dossier
@ -348,9 +348,10 @@ describe ExpiredDossiersDeletionService do
before { Timecop.freeze(reference_date) }
after { Timecop.return }
before do
Flipper.enable(:procedure_process_expired_dossiers_termine, procedure)
Flipper.enable(:procedure_process_expired_dossiers_termine, procedure_2)
let(:procedure_opts) do
{
procedure_expires_when_termine_enabled: true
}
end
before do
@ -359,7 +360,7 @@ describe ExpiredDossiersDeletionService do
end
context 'with a single dossier' do
let!(:dossier) { create(:dossier, :accepte, :followed, procedure: procedure, termine_close_to_expiration_notice_sent_at: notice_sent_at) }
let!(:dossier) { create(:dossier, :followed, :accepte, procedure: procedure, termine_close_to_expiration_notice_sent_at: notice_sent_at) }
let(:deleted_dossier) { DeletedDossier.find_by(dossier_id: dossier.id) }
before { ExpiredDossiersDeletionService.delete_expired_termine_and_notify }

View file

@ -1,6 +1,13 @@
describe 'shared/dossiers/expiration_banner.html.haml', type: :view do
include DossierHelper
let(:dossier) { build(:dossier, state, attributes.merge(id: 1, state: state)) }
let(:dossier) do
create(:dossier, state, attributes.merge(
id: 1,
state: state,
procedure: create(:procedure, procedure_expires_when_termine_enabled: expiration_enabled)
))
end
let(:i18n_key_state) { state }
subject do
render('shared/dossiers/expiration_banner.html.haml',
@ -8,8 +15,8 @@ describe 'shared/dossiers/expiration_banner.html.haml', type: :view do
current_user: build(:user))
end
context 'with procedure having procedure_process_expired_dossiers_termine not enabled' do
before { allow(dossier.procedure).to receive(:feature_enabled?).with(:procedure_process_expired_dossiers_termine).and_return(false) }
context 'with procedure having procedure_expires_when_termine_enabled not enabled' do
let(:expiration_enabled) { false }
let(:attributes) { { processed_at: 6.months.ago } }
let(:state) { :accepte }
@ -18,8 +25,8 @@ describe 'shared/dossiers/expiration_banner.html.haml', type: :view do
end
end
context 'with procedure having procedure_process_expired_dossiers_termine enabled' do
before { allow(dossier.procedure).to receive(:feature_enabled?).with(:procedure_process_expired_dossiers_termine).and_return(true) }
context 'with procedure having procedure_expires_when_termine_enabled enabled' do
let(:expiration_enabled) { true }
context 'with dossier.brouillon?' do
let(:attributes) { { created_at: 6.months.ago } }