Merge pull request #10163 from demarches-simplifiees/fix-bulk-message-maintenance-task

fix(maintenance task): fix query and add a test
This commit is contained in:
Eric Leroy-Terquem 2024-03-21 08:26:09 +00:00 committed by GitHub
commit a89b471b5c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 1 deletions

View file

@ -3,7 +3,11 @@
module Maintenance
class BackfillBulkMessagesWithProcedureIdTask < MaintenanceTasks::Task
def collection
BulkMessage.where(procedure: nil).where.missing(:groupe_instructeurs)
BulkMessage
.where(procedure: nil)
.includes(:groupe_instructeurs)
.where
.not(groupe_instructeurs: { id: nil })
end
def process(element)

View file

@ -0,0 +1,23 @@
# frozen_string_literal: true
require "rails_helper"
module Maintenance
RSpec.describe BackfillBulkMessagesWithProcedureIdTask do
describe "#process" do
subject(:process) { described_class.process(bulk_message) }
context 'with groupe instructeurs but no procedure_id' do
let(:bulk_message) { create(:bulk_message) }
let(:procedure) { bulk_message.groupe_instructeurs.first.procedure }
before { bulk_message.update_column(:procedure_id, nil) }
it 'fills procedure id' do
subject
expect(bulk_message.procedure_id).to eq procedure.id
end
end
end
end
end