[fix #1922] add one annotation to a procedure
This commit is contained in:
parent
684d57bd49
commit
3cfffc2615
2 changed files with 95 additions and 0 deletions
54
lib/tasks/2018_05_14_add_annotation_privee_to_procedure.rake
Normal file
54
lib/tasks/2018_05_14_add_annotation_privee_to_procedure.rake
Normal file
|
@ -0,0 +1,54 @@
|
|||
namespace :'2018_05_14_add_annotation_privee_to_procedure' do
|
||||
task add: :environment do
|
||||
procedure_id = ENV['PROCEDURE_ID'] || 3723
|
||||
add_an_annotation_privee(procedure_id)
|
||||
update_description(procedure_id)
|
||||
end
|
||||
|
||||
def add_an_annotation_privee(procedure_id)
|
||||
new_tdc_order_place = 7
|
||||
|
||||
TypeDeChamp
|
||||
.where(procedure_id: procedure_id, private: true)
|
||||
.where('order_place >= ?', new_tdc_order_place)
|
||||
.each do |tdc|
|
||||
tdc.update_attribute(:order_place, tdc.order_place + 1)
|
||||
end
|
||||
|
||||
new_tdc = TypesDeChamp::TextTypeDeChamp.create(
|
||||
procedure_id: procedure_id,
|
||||
private: true,
|
||||
libelle: 'URL Espace de consultation',
|
||||
order_place: new_tdc_order_place,
|
||||
type_champ: 'text',
|
||||
description: 'L’instructeur renseigne l’URL du site de dépôt des observations ou la page web de la préfecture où est mentionné l’email pour déposer les commentaires'
|
||||
)
|
||||
|
||||
Dossier.includes(champs: :type_de_champ).where(procedure_id: procedure_id).all.each do |dossier|
|
||||
Champs::TextChamp.create(
|
||||
dossier: dossier,
|
||||
type_de_champ: new_tdc,
|
||||
private: true
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def update_description(procedure_id)
|
||||
TypeDeChamp.find_by(
|
||||
private: true,
|
||||
description: "L'instructeur en préfecture saisie la date de publication de l'avis à consultation du public ",
|
||||
procedure_id: procedure_id
|
||||
)&.update(
|
||||
description: "L'instructeur en préfecture saisie la première date de publication de l'avis à consultation du public"
|
||||
)
|
||||
|
||||
TypeDeChamp.find_by(
|
||||
private: false,
|
||||
libelle: "Fichier(s) Etude d'impact",
|
||||
procedure_id: procedure_id
|
||||
)&.update(
|
||||
libelle: "Fichier Etude d'impact",
|
||||
description: "Vous devez télé-charger votre fichier constituant le document dit \"étude d'impact\" de votre projet.\r\nObligatoire."
|
||||
)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,41 @@
|
|||
describe '2018_05_14_add_annotation_privee_to_procedure' do
|
||||
let!(:user) { create(:user) }
|
||||
let!(:procedure) do
|
||||
procedure = create(:procedure)
|
||||
10.times do |i|
|
||||
TypesDeChamp::NumberTypeDeChamp.create(
|
||||
procedure: procedure,
|
||||
private: false,
|
||||
libelle: 'libelle',
|
||||
order_place: i,
|
||||
type_champ: 'number'
|
||||
)
|
||||
|
||||
TypesDeChamp::NumberTypeDeChamp.create(
|
||||
procedure: procedure,
|
||||
private: true,
|
||||
libelle: 'libelle',
|
||||
order_place: i,
|
||||
type_champ: 'number'
|
||||
)
|
||||
end
|
||||
procedure
|
||||
end
|
||||
let!(:dossier) { Dossier.create(procedure: procedure, user: user, state: 'brouillon') }
|
||||
let(:rake_task) { Rake::Task['2018_05_14_add_annotation_privee_to_procedure:add'] }
|
||||
|
||||
before(:all) { TPS::Application.load_tasks }
|
||||
|
||||
before do
|
||||
ENV['PROCEDURE_ID'] = procedure.id.to_s
|
||||
rake_task.invoke
|
||||
procedure.reload
|
||||
end
|
||||
|
||||
after { rake_task.reenable }
|
||||
|
||||
it { expect(procedure.types_de_champ.count).to eq(10) }
|
||||
it { expect(procedure.types_de_champ_private.count).to eq(11) }
|
||||
it { expect(dossier.champs_private.includes(:type_de_champ).map(&:order_place).sort).to match((0..10).to_a) }
|
||||
it { expect(procedure.types_de_champ_private.find_by(order_place: 7).type_champ).to eq('text') }
|
||||
end
|
Loading…
Reference in a new issue