reset opendata to true when procedure is cloned by another admin

This commit is contained in:
Christophe Robillard 2022-05-27 18:51:06 +02:00
parent 45d48bd269
commit 6dd27ec7ed
2 changed files with 15 additions and 0 deletions

View file

@ -487,6 +487,7 @@ class Procedure < ApplicationRecord
procedure.administrateurs = [admin]
procedure.api_entreprise_token = nil
procedure.encrypted_api_particulier_token = nil
procedure.opendata = true
procedure.api_particulier_scopes = []
else
procedure.administrateurs = administrateurs

View file

@ -439,6 +439,7 @@ describe Procedure do
create(:procedure,
received_mail: received_mail,
service: service,
opendata: opendata,
attestation_template: build(:attestation_template, logo: logo, signature: signature),
types_de_champ: [type_de_champ_0, type_de_champ_1, type_de_champ_2, type_de_champ_pj],
types_de_champ_private: [type_de_champ_private_0, type_de_champ_private_1, type_de_champ_private_2],
@ -456,6 +457,7 @@ describe Procedure do
let(:type_de_champ_private_repetition) { build(:type_de_champ_repetition, :private, position: 3, procedure: procedure, types_de_champ: [build(:type_de_champ, :private)]) }
let(:received_mail) { build(:received_mail) }
let(:from_library) { false }
let(:opendata) { true }
let(:administrateur) { procedure.administrateurs.first }
let(:logo) { Rack::Test::UploadedFile.new('spec/fixtures/files/white.png', 'image/png') }
let(:signature) { Rack::Test::UploadedFile.new('spec/fixtures/files/black.png', 'image/png') }
@ -529,6 +531,13 @@ describe Procedure do
expect(cloned_procedure).to have_same_attributes_as(procedure, except: ["path", "draft_revision_id"])
end
context 'which is opendata' do
let(:opendata) { false }
it 'should keep opendata for same admin' do
expect(subject.opendata).to be_falsy
end
end
context 'when the procedure is cloned from the library' do
let(:from_library) { true }
@ -569,6 +578,7 @@ describe Procedure do
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)
@ -586,6 +596,10 @@ describe Procedure do
expect(subject.read_attribute(:api_entreprise_token)).to be_nil
end
it 'should reset opendata to true' do
expect(subject.opendata).to be_truthy
end
it 'should have one administrateur' do
expect(subject.administrateurs).to eq([administrateur])
end