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
|
||||||
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)
|
def clone(admin, from_library)
|
||||||
is_different_admin = !admin.owns?(self)
|
is_different_admin = !admin.owns?(self)
|
||||||
|
|
||||||
|
@ -198,7 +208,7 @@ class Procedure < ApplicationRecord
|
||||||
attestation_template: nil,
|
attestation_template: nil,
|
||||||
types_de_champ: [:drop_down_list, types_de_champ: :drop_down_list],
|
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]
|
types_de_champ_private: [:drop_down_list, types_de_champ: :drop_down_list]
|
||||||
})
|
}, &method(:clone_attachments))
|
||||||
procedure.path = nil
|
procedure.path = nil
|
||||||
procedure.aasm_state = :brouillon
|
procedure.aasm_state = :brouillon
|
||||||
procedure.test_started_at = nil
|
procedure.test_started_at = nil
|
||||||
|
|
|
@ -86,6 +86,10 @@ FactoryBot.define do
|
||||||
end
|
end
|
||||||
factory :type_de_champ_piece_justificative do
|
factory :type_de_champ_piece_justificative do
|
||||||
type_champ { TypeDeChamp.type_champs.fetch(:piece_justificative) }
|
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
|
end
|
||||||
factory :type_de_champ_siret do
|
factory :type_de_champ_siret do
|
||||||
type_champ { TypeDeChamp.type_champs.fetch(:siret) }
|
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.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)
|
expect(subject.types_de_champ.first.stable_id).to eq(procedure.types_de_champ.first.id)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe '#publish!' do
|
describe '#publish!' do
|
||||||
|
|
Loading…
Add table
Reference in a new issue