Procedure: procedure cloned from library are tagged
This commit is contained in:
parent
06a5063807
commit
f46bf5a67e
4 changed files with 30 additions and 9 deletions
|
@ -160,7 +160,7 @@ class Admin::ProceduresController < AdminController
|
||||||
render '/admin/procedures/transfer', formats: 'js', status: 404
|
render '/admin/procedures/transfer', formats: 'js', status: 404
|
||||||
else
|
else
|
||||||
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
||||||
clone_procedure = procedure.clone(admin)
|
clone_procedure = procedure.clone(admin, false)
|
||||||
|
|
||||||
clone_procedure.save
|
clone_procedure.save
|
||||||
|
|
||||||
|
@ -184,13 +184,13 @@ class Admin::ProceduresController < AdminController
|
||||||
|
|
||||||
def clone
|
def clone
|
||||||
procedure = Procedure.find(params[:procedure_id])
|
procedure = Procedure.find(params[:procedure_id])
|
||||||
new_procedure = procedure.clone(current_administrateur)
|
new_procedure = procedure.clone(current_administrateur, cloned_from_library?)
|
||||||
|
|
||||||
if new_procedure.save
|
if new_procedure.save
|
||||||
flash.notice = 'Procédure clonée'
|
flash.notice = 'Procédure clonée'
|
||||||
redirect_to edit_admin_procedure_path(id: new_procedure.id)
|
redirect_to edit_admin_procedure_path(id: new_procedure.id)
|
||||||
else
|
else
|
||||||
if params[:from_new_from_existing].present?
|
if cloned_from_library?
|
||||||
flash.alert = new_procedure.errors.full_messages
|
flash.alert = new_procedure.errors.full_messages
|
||||||
redirect_to new_from_existing_admin_procedures_path
|
redirect_to new_from_existing_admin_procedures_path
|
||||||
else
|
else
|
||||||
|
@ -249,6 +249,10 @@ class Admin::ProceduresController < AdminController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def cloned_from_library?
|
||||||
|
params[:from_new_from_existing].present?
|
||||||
|
end
|
||||||
|
|
||||||
def procedure_params
|
def procedure_params
|
||||||
editable_params = [:libelle, :description, :organisation, :direction, :lien_site_web, :notice, :web_hook_url, :euro_flag, :logo, :auto_archive_on]
|
editable_params = [:libelle, :description, :organisation, :direction, :lien_site_web, :notice, :web_hook_url, :euro_flag, :logo, :auto_archive_on]
|
||||||
if @procedure.try(:locked?)
|
if @procedure.try(:locked?)
|
||||||
|
|
|
@ -104,7 +104,7 @@ class Procedure < ApplicationRecord
|
||||||
publiee_ou_archivee?
|
publiee_ou_archivee?
|
||||||
end
|
end
|
||||||
|
|
||||||
def clone(admin)
|
def clone(admin, from_library)
|
||||||
procedure = self.deep_clone(include:
|
procedure = self.deep_clone(include:
|
||||||
{
|
{
|
||||||
types_de_piece_justificative: nil,
|
types_de_piece_justificative: nil,
|
||||||
|
@ -125,6 +125,8 @@ class Procedure < ApplicationRecord
|
||||||
procedure.refused_mail = refused_mail.try(:dup)
|
procedure.refused_mail = refused_mail.try(:dup)
|
||||||
procedure.without_continuation_mail = without_continuation_mail.try(:dup)
|
procedure.without_continuation_mail = without_continuation_mail.try(:dup)
|
||||||
|
|
||||||
|
procedure.cloned_from_library = from_library
|
||||||
|
|
||||||
procedure
|
procedure
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -456,19 +456,25 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
|
|
||||||
describe 'PUT #clone' do
|
describe 'PUT #clone' do
|
||||||
let!(:procedure) { create(:procedure, administrateur: admin) }
|
let!(:procedure) { create(:procedure, administrateur: admin) }
|
||||||
subject { put :clone, params: { procedure_id: procedure.id } }
|
let(:params) { { procedure_id: procedure.id } }
|
||||||
|
subject { put :clone, params: params }
|
||||||
|
|
||||||
it { expect { subject }.to change(Procedure, :count).by(1) }
|
it { expect { subject }.to change(Procedure, :count).by(1) }
|
||||||
|
|
||||||
context 'when admin is the owner of the procedure' do
|
context 'when admin is the owner of the procedure' do
|
||||||
before do
|
before { subject }
|
||||||
subject
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'creates a new procedure and redirect to it' do
|
it 'creates a new procedure and redirect to it' 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(false)
|
||||||
expect(flash[:notice]).to have_content 'Procédure clonée'
|
expect(flash[:notice]).to have_content 'Procédure clonée'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when the procedure is cloned from the library' do
|
||||||
|
let(:params) { { procedure_id: procedure.id, from_new_from_existing: true } }
|
||||||
|
|
||||||
|
it { expect(Procedure.last.cloned_from_library).to be(true) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when admin is not the owner of the procedure' do
|
context 'when admin is not the owner of the procedure' do
|
||||||
|
|
|
@ -272,12 +272,13 @@ describe Procedure do
|
||||||
let!(:piece_justificative_0) { create(:type_de_piece_justificative, procedure: procedure, order_place: 0) }
|
let!(:piece_justificative_0) { create(:type_de_piece_justificative, procedure: procedure, order_place: 0) }
|
||||||
let!(:piece_justificative_1) { create(:type_de_piece_justificative, procedure: procedure, order_place: 1) }
|
let!(:piece_justificative_1) { create(:type_de_piece_justificative, procedure: procedure, order_place: 1) }
|
||||||
let(:received_mail){ create(:received_mail) }
|
let(:received_mail){ create(:received_mail) }
|
||||||
|
let(:from_library) { false }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
@logo = File.open('spec/fixtures/white.png')
|
@logo = File.open('spec/fixtures/white.png')
|
||||||
@signature = File.open('spec/fixtures/black.png')
|
@signature = File.open('spec/fixtures/black.png')
|
||||||
@attestation_template = create(:attestation_template, procedure: procedure, logo: @logo, signature: @signature)
|
@attestation_template = create(:attestation_template, procedure: procedure, logo: @logo, signature: @signature)
|
||||||
@procedure = procedure.clone(procedure.administrateur)
|
@procedure = procedure.clone(procedure.administrateur, from_library)
|
||||||
@procedure.save
|
@procedure.save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -312,6 +313,14 @@ describe Procedure do
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(subject.attestation_template.title).to eq(procedure.attestation_template.title)
|
expect(subject.attestation_template.title).to eq(procedure.attestation_template.title)
|
||||||
|
|
||||||
|
expect(subject.cloned_from_library).to be(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the procedure is clone from the library' do
|
||||||
|
let(:from_library) { true }
|
||||||
|
|
||||||
|
it { expect(subject.cloned_from_library).to be(true) }
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should duplicate existing mail_templates' do
|
it 'should duplicate existing mail_templates' do
|
||||||
|
|
Loading…
Reference in a new issue