empty invalid fields to allow clone procedure

This commit is contained in:
Lisa Durand 2023-05-16 10:59:17 +02:00
parent b583fe1fab
commit f2cf3188d7
2 changed files with 38 additions and 1 deletions

View file

@ -576,8 +576,13 @@ class Procedure < ApplicationRecord
procedure.service = nil
transaction do
procedure.save
if !procedure.valid?
procedure.errors.attribute_names.each do |attribute|
procedure.send("#{attribute}=", nil)
end
end
procedure.save
move_new_children_to_new_parent_coordinate(procedure.draft_revision)
end

View file

@ -572,6 +572,38 @@ describe Administrateurs::ProceduresController, type: :controller do
expect(flash[:notice]).to have_content 'Démarche clonée, pensez a vérifier la Présentation et choisir le service a laquelle cette procédure est associé.'
end
end
context 'when procedure has invalid fields' do
let(:admin_2) { create(:administrateur) }
let(:path) { 'spec/fixtures/files/invalid_file_format.json' }
before do
sign_out(admin.user)
sign_in(admin_2.user)
procedure.notice.attach(io: File.open(path),
filename: "invalid_file_format.json",
content_type: "application/json",
metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE })
procedure.deliberation.attach(io: File.open(path),
filename: "invalid_file_format.json",
content_type: "application/json",
metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE })
procedure.created_at = Date.new(2020, 2, 27)
procedure.save!
subject { put :clone, params: { procedure_id: procedure.id } }
end
it 'empty invalid fields and allow procedure to be cloned' do
expect(response).to redirect_to admin_procedure_path(id: Procedure.last.id)
expect(Procedure.last.notice.attached?).to be_falsey
expect(Procedure.last.deliberation.attached?).to be_falsey
expect(flash[:notice]).to have_content 'Démarche clonée, pensez a vérifier la Présentation et choisir le service a laquelle cette procédure est associé.'
end
end
end
describe 'PUT #archive' do