diff --git a/app/models/champ.rb b/app/models/champ.rb index cbff3b54a..92fbca7d0 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -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 diff --git a/spec/models/champ_spec.rb b/spec/models/champ_spec.rb index 229b440a4..edde59295 100644 --- a/spec/models/champ_spec.rb +++ b/spec/models/champ_spec.rb @@ -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