db(task): remove pj files for not visible champs

This commit is contained in:
Eric Leroy-Terquem 2024-07-23 16:59:42 +02:00
parent e79a3b6aa2
commit d8d2094909
No known key found for this signature in database
GPG key ID: 53D8FAECEF207605
2 changed files with 47 additions and 0 deletions

View file

@ -0,0 +1,17 @@
# frozen_string_literal: true
module Maintenance
class RemovePieceJustificativeFileNotVisibleTask < MaintenanceTasks::Task
attribute :procedure_id, :string
validates :procedure_id, presence: true
def collection
procedure = Procedure.with_discarded.find(procedure_id.strip.to_i)
procedure.dossiers.state_not_brouillon
end
def process(dossier)
dossier.remove_piece_justificative_file_not_visible!
end
end
end

View file

@ -0,0 +1,30 @@
# frozen_string_literal: true
require "rails_helper"
module Maintenance
RSpec.describe RemovePieceJustificativeFileNotVisibleTask do
describe "#process" do
subject(:process) { described_class.process(dossier) }
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :piece_justificative }]) }
let(:dossier) { create(:dossier, :en_construction, :with_populated_champs, procedure:) }
before { expect(champ).to receive(:visible?).and_return(visible) }
context 'when piece_justificative' do
let(:champ) { dossier.champs_for_revision(scope: :public).find(&:piece_justificative?) }
context 'when not visible' do
let(:visible) { false }
it { expect { subject }.to change { champ.reload.piece_justificative_file.attached? } }
end
context 'when visible' do
let(:visible) { true }
it { expect { subject }.not_to change { champ.reload.piece_justificative_file.attached? } }
end
end
end
end
end