fix(data): update closing_reason to other if no replaced_by_procedure_id

This commit is contained in:
Eric Leroy-Terquem 2024-03-19 16:41:02 +01:00
parent e55531c6f4
commit 234f0d7a75
2 changed files with 40 additions and 0 deletions

View file

@ -0,0 +1,17 @@
# frozen_string_literal: true
module Maintenance
class UpdateClosingReasonIfNoReplacedByIdTask < MaintenanceTasks::Task
def collection
Procedure
.with_discarded
.closes
.where(closing_reason: Procedure.closing_reasons.fetch(:internal_procedure))
.where(replaced_by_procedure_id: nil)
end
def process(procedure)
procedure.update!(closing_reason: Procedure.closing_reasons.fetch(:other))
end
end
end

View file

@ -0,0 +1,23 @@
# frozen_string_literal: true
require "rails_helper"
module Maintenance
RSpec.describe UpdateClosingReasonIfNoReplacedByIdTask do
describe "#process" do
subject(:process) { described_class.process(procedure) }
let(:procedure) { create(:procedure, :closed) }
before do
procedure.update_column(:closing_reason, Procedure.closing_reasons.fetch(:internal_procedure))
procedure.update_column(:replaced_by_procedure_id, nil)
end
it 'updates closing_reason to other' do
subject
expect(procedure.closing_reason).to eq(Procedure.closing_reasons.fetch(:other))
end
end
end
end