task(procedure): fix open procedures with closing reason

This commit is contained in:
Eric Leroy-Terquem 2024-03-22 16:00:36 +01:00
parent 89401d0e30
commit e712cf5f23
2 changed files with 39 additions and 0 deletions

View file

@ -0,0 +1,18 @@
# frozen_string_literal: true
module Maintenance
class FixOpenProceduresWithClosingReasonTask < MaintenanceTasks::Task
def collection
Procedure
.with_discarded
.where
.not(aasm_state: [:close, :depubliee])
.where
.not(closing_reason: nil)
end
def process(procedure)
procedure.update!(closing_reason: nil)
end
end
end

View file

@ -0,0 +1,21 @@
# frozen_string_literal: true
require "rails_helper"
module Maintenance
RSpec.describe FixOpenProceduresWithClosingReasonTask do
describe "#process" do
subject(:process) { described_class.process(procedure) }
let(:procedure) { create(:procedure, :published) }
before do
procedure.update_column(:closing_reason, 'internal_procedure')
end
it do
subject
expect(procedure.closing_reason).to be_nil
end
end
end
end