fix(champs.pj.clone): stop cloning private piece_justificative_file when user clone his dossier

This commit is contained in:
mfo 2024-05-21 09:50:27 +02:00
parent 4629092ab6
commit 4ea601de79
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC
2 changed files with 41 additions and 1 deletions

View file

@ -238,7 +238,7 @@ class Champ < ApplicationRecord
kopy.write_attribute(:stable_id, original.stable_id)
kopy.write_attribute(:stream, 'main')
end
ClonePiecesJustificativesService.clone_attachments(original, kopy)
ClonePiecesJustificativesService.clone_attachments(original, kopy) if fork || !private?
end
end

View file

@ -569,4 +569,44 @@ describe Champ do
it { expect(ActionView::RecordIdentifier.dom_id(champ.type_de_champ)).to eq("type_de_champ_#{champ.type_de_champ.id}") }
it { expect(ActionView::RecordIdentifier.dom_class(champ)).to eq("champ") }
end
describe 'clone' do
subject { champ.clone(fork) }
context 'when champ public' do
let(:champ) { create(:champ_piece_justificative, private: false) }
context 'when fork' do
let(:fork) { true }
it do
expect(subject.piece_justificative_file).to be_attached
end
end
context 'when not fork' do
let(:fork) { false }
it do
expect(subject.piece_justificative_file).to be_attached
end
end
end
context 'champ private' do
let(:champ) { create(:champ_piece_justificative, private: true) }
context 'when fork' do
let(:fork) { true }
it do
expect(subject.piece_justificative_file).to be_attached
end
end
context 'when not fork' do
let(:fork) { false }
it do
expect(subject.piece_justificative_file).not_to be_attached
end
end
end
end
end