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:
commit
a89b471b5c
2 changed files with 28 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
Loading…
Reference in a new issue