Merge pull request #10634 from demarches-simplifiees/remove_piece_justificative_file_not_visible
ETQ superadmin je peux supprimer les pjs associées aux champs non visibles avec une maintenance task
This commit is contained in:
commit
3dd6a59101
2 changed files with 47 additions and 0 deletions
|
@ -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
|
|
@ -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
|
Loading…
Reference in a new issue