diff --git a/app/jobs/cron/purge_manager_administrateur_sessions_job.rb b/app/jobs/cron/purge_manager_administrateur_sessions_job.rb index 29de55b38..7e20e1b17 100644 --- a/app/jobs/cron/purge_manager_administrateur_sessions_job.rb +++ b/app/jobs/cron/purge_manager_administrateur_sessions_job.rb @@ -2,6 +2,7 @@ class Cron::PurgeManagerAdministrateurSessionsJob < Cron::CronJob self.schedule_expression = "every day at 3 am" def perform - AdministrateursProcedure.where(manager: true).destroy_all + # TODO: add id column to administrateurs_procedures and use destroy_all + AdministrateursProcedure.where(manager: true).delete_all end end diff --git a/spec/jobs/cron/purge_manager_administrateur_sessions_job_spec.rb b/spec/jobs/cron/purge_manager_administrateur_sessions_job_spec.rb new file mode 100644 index 000000000..cff2eaff4 --- /dev/null +++ b/spec/jobs/cron/purge_manager_administrateur_sessions_job_spec.rb @@ -0,0 +1,22 @@ +RSpec.describe Cron::PurgeManagerAdministrateurSessionsJob, type: :job do + describe 'perform' do + let(:administrateur) { create(:administrateur) } + let(:procedure) { create(:procedure) } + + subject { Cron::PurgeManagerAdministrateurSessionsJob.perform_now } + + context "with an inactive administrateur" do + before do + AdministrateursProcedure.create(procedure: procedure, administrateur: administrateur, manager: true) + expect(AdministrateursProcedure.where(manager: true).count).to eq(1) + expect(AdministrateursProcedure.count).to eq(2) + subject + end + + it { + expect(AdministrateursProcedure.where(manager: true).count).to eq(0) + expect(AdministrateursProcedure.count).to eq(1) + } + end + end +end