From 6dd27ec7ed4cb60a2d8a6a05a0ec5e9c77d9faaf Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Fri, 27 May 2022 18:51:06 +0200 Subject: [PATCH] reset opendata to true when procedure is cloned by another admin --- app/models/procedure.rb | 1 + spec/models/procedure_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 407e44efe..c49243760 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -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 diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index ddf7a2ff1..139c0b267 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -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