feat(Procedure.clone): stop cloning procedure service which is confusing for some administrateurs

This commit is contained in:
Martin 2022-08-17 08:47:19 +02:00
parent d1ae98b9a7
commit 6e31decc2d
2 changed files with 6 additions and 13 deletions

View file

@ -510,12 +510,7 @@ class Procedure < ApplicationRecord
procedure.parent_procedure = self
procedure.canonical_procedure = nil
procedure.replaced_by_procedure = nil
if from_library
procedure.service = nil
elsif self.service.present? && is_different_admin
procedure.service = self.service.clone_and_assign_to_administrateur(admin)
end
procedure.service = nil
transaction do
procedure.save

View file

@ -525,7 +525,7 @@ describe Procedure do
cloned_procedure = subject
cloned_procedure.parent_procedure_id = nil
expect(cloned_procedure).to have_same_attributes_as(procedure, except: ["path", "draft_revision_id"])
expect(cloned_procedure).to have_same_attributes_as(procedure, except: ["path", "draft_revision_id", "service_id"])
end
context 'which is opendata' do
@ -569,18 +569,16 @@ describe Procedure do
end
end
it 'should keep service_id' do
expect(subject.service).to eq(service)
it 'should skips service_id' do
expect(subject.service).to eq(nil)
end
context 'when the procedure is cloned to another administrateur' do
let(:administrateur) { create(:administrateur) }
let(:opendata) { false }
it 'should clone service' do
expect(subject.service.id).not_to eq(service.id)
expect(subject.service.administrateur_id).not_to eq(service.administrateur_id)
expect(subject.service.attributes.except("id", "administrateur_id", "created_at", "updated_at")).to eq(service.attributes.except("id", "administrateur_id", "created_at", "updated_at"))
it 'should not clone service' do
expect(subject.service).to eq(nil)
end
it 'should discard old pj information' do