Merge pull request #3681 from betagouv/fix-3650
When cloning a procedure, do not forget pj_templates
This commit is contained in:
commit
4681943811
3 changed files with 19 additions and 1 deletions
|
@ -189,6 +189,16 @@ class Procedure < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def clone_attachments(original, kopy)
|
||||
if original.is_a?(TypeDeChamp) && original.piece_justificative_template.attached?
|
||||
kopy.piece_justificative_template.attach({
|
||||
io: StringIO.new(original.piece_justificative_template.download),
|
||||
filename: original.piece_justificative_template.blob.filename,
|
||||
content_type: original.piece_justificative_template.blob.content_type
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
def clone(admin, from_library)
|
||||
is_different_admin = !admin.owns?(self)
|
||||
|
||||
|
@ -198,7 +208,7 @@ class Procedure < ApplicationRecord
|
|||
attestation_template: nil,
|
||||
types_de_champ: [:drop_down_list, types_de_champ: :drop_down_list],
|
||||
types_de_champ_private: [:drop_down_list, types_de_champ: :drop_down_list]
|
||||
})
|
||||
}, &method(:clone_attachments))
|
||||
procedure.path = nil
|
||||
procedure.aasm_state = :brouillon
|
||||
procedure.test_started_at = nil
|
||||
|
|
|
@ -86,6 +86,10 @@ FactoryBot.define do
|
|||
end
|
||||
factory :type_de_champ_piece_justificative do
|
||||
type_champ { TypeDeChamp.type_champs.fetch(:piece_justificative) }
|
||||
|
||||
after(:create) do |tc, _evaluator|
|
||||
tc.piece_justificative_template.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain")
|
||||
end
|
||||
end
|
||||
factory :type_de_champ_siret do
|
||||
type_champ { TypeDeChamp.type_champs.fetch(:siret) }
|
||||
|
|
|
@ -485,6 +485,10 @@ describe Procedure do
|
|||
expect(subject.types_de_champ.first.id).not_to eq(procedure.types_de_champ.first.id)
|
||||
expect(subject.types_de_champ.first.stable_id).to eq(procedure.types_de_champ.first.id)
|
||||
end
|
||||
|
||||
it 'should duplicate piece_justificative_template on a type_de_champ' do
|
||||
expect(subject.types_de_champ.where(type_champ: "piece_justificative").first.piece_justificative_template.attached?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#publish!' do
|
||||
|
|
Loading…
Reference in a new issue