Procedure: clone the deliberation
This commit is contained in:
parent
fa14db1cbf
commit
0e690c90cc
3 changed files with 25 additions and 10 deletions
|
@ -200,15 +200,7 @@ class Procedure < ApplicationRecord
|
||||||
procedure.logo_secure_token = nil
|
procedure.logo_secure_token = nil
|
||||||
procedure.remote_logo_url = self.logo_url
|
procedure.remote_logo_url = self.logo_url
|
||||||
|
|
||||||
if notice.attached?
|
%i(notice deliberation).each { |attachment| clone_attachment(procedure, attachment) }
|
||||||
response = Typhoeus.get(notice.service_url, timeout: 5)
|
|
||||||
if response.success?
|
|
||||||
procedure.notice.attach(
|
|
||||||
io: StringIO.new(response.body),
|
|
||||||
filename: notice.filename
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
procedure.administrateur = admin
|
procedure.administrateur = admin
|
||||||
procedure.initiated_mail = initiated_mail&.dup
|
procedure.initiated_mail = initiated_mail&.dup
|
||||||
|
@ -351,6 +343,19 @@ class Procedure < ApplicationRecord
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def clone_attachment(cloned_procedure, attachment_symbol)
|
||||||
|
attachment = send(attachment_symbol)
|
||||||
|
if attachment.attached?
|
||||||
|
response = Typhoeus.get(attachment.service_url, timeout: 5)
|
||||||
|
if response.success?
|
||||||
|
cloned_procedure.send(attachment_symbol).attach(
|
||||||
|
io: StringIO.new(response.body),
|
||||||
|
filename: attachment.filename
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def check_juridique
|
def check_juridique
|
||||||
if cadre_juridique.blank? && !deliberation.attached?
|
if cadre_juridique.blank? && !deliberation.attached?
|
||||||
errors.add(:cadre_juridique, " : veuillez remplir le texte de loi ou la délibération")
|
errors.add(:cadre_juridique, " : veuillez remplir le texte de loi ou la délibération")
|
||||||
|
|
|
@ -473,7 +473,7 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'PUT #clone' do
|
describe 'PUT #clone' do
|
||||||
let!(:procedure) { create(:procedure, :with_notice, administrateur: admin) }
|
let!(:procedure) { create(:procedure, :with_notice, :with_deliberation, administrateur: admin) }
|
||||||
let(:params) { { procedure_id: procedure.id } }
|
let(:params) { { procedure_id: procedure.id } }
|
||||||
subject { put :clone, params: params }
|
subject { put :clone, params: params }
|
||||||
|
|
||||||
|
@ -491,6 +491,7 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
expect(response).to redirect_to edit_admin_procedure_path(id: Procedure.last.id)
|
expect(response).to redirect_to edit_admin_procedure_path(id: Procedure.last.id)
|
||||||
expect(Procedure.last.cloned_from_library).to be_falsey
|
expect(Procedure.last.cloned_from_library).to be_falsey
|
||||||
expect(Procedure.last.notice.attached?).to be_truthy
|
expect(Procedure.last.notice.attached?).to be_truthy
|
||||||
|
expect(Procedure.last.deliberation.attached?).to be_truthy
|
||||||
expect(flash[:notice]).to have_content 'Procédure clonée'
|
expect(flash[:notice]).to have_content 'Procédure clonée'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -135,6 +135,15 @@ FactoryBot.define do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
trait :with_deliberation do
|
||||||
|
after(:create) do |procedure, _evaluator|
|
||||||
|
procedure.deliberation.attach(
|
||||||
|
io: StringIO.new('Hello World'),
|
||||||
|
filename: 'hello.txt'
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
trait :with_all_champs_mandatory do
|
trait :with_all_champs_mandatory do
|
||||||
after(:build) do |procedure, _evaluator|
|
after(:build) do |procedure, _evaluator|
|
||||||
tdcs = []
|
tdcs = []
|
||||||
|
|
Loading…
Add table
Reference in a new issue