Remove old tasks depending on single administrateur
This commit is contained in:
parent
fcddb69dab
commit
23d8f0d803
6 changed files with 0 additions and 444 deletions
|
@ -1,106 +0,0 @@
|
|||
require Rails.root.join("lib", "tasks", "task_helper")
|
||||
|
||||
namespace :'2018_07_31_nutriscore' do
|
||||
task migrate_dossiers: :environment do
|
||||
source_procedure_id = ENV['SOURCE_PROCEDURE_ID'] || 4861
|
||||
destination_procedure_id = ENV['DESTINATION_PROCEDURE_ID'] || 7009
|
||||
|
||||
source_procedure = Procedure.find(source_procedure_id)
|
||||
destination_procedure = Procedure.find(destination_procedure_id)
|
||||
|
||||
mapping = Class.new(Tasks::DossierProcedureMigrator::ChampMapping) do
|
||||
def setup_mapping
|
||||
siret_order_place = 2
|
||||
fonction_order_place = 9
|
||||
zone_geographique_header_order_place = 18
|
||||
pays_commercialisation_order_place = 19
|
||||
header_engagement_order_place = 20
|
||||
|
||||
champ_opts = { header_engagement_order_place => { source_overrides: { 'libelle' => 'PARTIE 3 : ENGAGEMENT DE L’EXPLOITANT' }, destination_overrides: { 'libelle' => 'PARTIE 4 : ENGAGEMENT DE L’EXPLOITANT' } } }
|
||||
|
||||
pays_drop_down_values = "FRANCE\r\nACORES, MADERE\r\nAFGHANISTAN\r\nAFRIQUE DU SUD\r\nALASKA\r\nALBANIE\r\nALGERIE\r\nALLEMAGNE\r\nANDORRE\r\nANGOLA\r\nANGUILLA\r\nANTIGUA-ET-BARBUDA\r\nANTILLES NEERLANDAISES\r\nARABIE SAOUDITE\r\nARGENTINE\r\nARMENIE\r\nARUBA\r\nAUSTRALIE\r\nAUTRICHE\r\nAZERBAIDJAN\r\nBAHAMAS\r\nBAHREIN\r\nBANGLADESH\r\nBARBADE\r\nBELGIQUE\r\nBELIZE\r\nBENIN\r\nBERMUDES\r\nBHOUTAN\r\nBIELORUSSIE\r\nBIRMANIE\r\nBOLIVIE\r\nBONAIRE, SAINT EUSTACHE ET SABA\r\nBOSNIE-HERZEGOVINE\r\nBOTSWANA\r\nBOUVET (ILE)\r\nBRESIL\r\nBRUNEI\r\nBULGARIE\r\nBURKINA\r\nBURUNDI\r\nCAIMANES (ILES)\r\nCAMBODGE\r\nCAMEROUN\r\nCAMEROUN ET TOGO\r\nCANADA\r\nCANARIES (ILES)\r\nCAP-VERT\r\nCENTRAFRICAINE (REPUBLIQUE)\r\nCHILI\r\nCHINE\r\nCHRISTMAS (ILE)\r\nCHYPRE\r\nCLIPPERTON (ILE)\r\nCOCOS ou KEELING (ILES)\r\nCOLOMBIE\r\nCOMORES\r\nCONGO\r\nCONGO (REPUBLIQUE DEMOCRATIQUE)\r\nCOOK (ILES)\r\nCOREE\r\nCOREE (REPUBLIQUE DE)\r\nCOREE (REPUBLIQUE POPULAIRE DEMOCRATIQUE DE)\r\nCOSTA RICA\r\nCOTE D'IVOIRE\r\nCROATIE\r\nCUBA\r\nCURAÇAO\r\nDANEMARK\r\nDJIBOUTI\r\nDOMINICAINE (REPUBLIQUE)\r\nDOMINIQUE\r\nEGYPTE\r\nEL SALVADOR\r\nEMIRATS ARABES UNIS\r\nEQUATEUR\r\nERYTHREE\r\nESPAGNE\r\nESTONIE\r\nETATS MALAIS NON FEDERES\r\nETATS-UNIS\r\nETHIOPIE\r\nFEROE (ILES)\r\nFIDJI\r\nFINLANDE\r\nGABON\r\nGAMBIE\r\nGEORGIE\r\nGEORGIE DU SUD ET LES ILES SANDWICH DU SUD\r\nGHANA\r\nGIBRALTAR\r\nGOA\r\nGRECE\r\nGRENADE\r\nGROENLAND\r\nGUADELOUPE\r\nGUAM\r\nGUATEMALA\r\nGUERNESEY\r\nGUINEE\r\nGUINEE EQUATORIALE\r\nGUINEE-BISSAU\r\nGUYANA\r\nGUYANE\r\nHAITI\r\nHAWAII (ILES)\r\nHEARD ET MACDONALD (ILES)\r\nHONDURAS\r\nHONG-KONG\r\nHONGRIE\r\nILES PORTUGAISES DE L'OCEAN INDIEN\r\nINDE\r\nINDONESIE\r\nIRAN\r\nIRAQ\r\nIRLANDE, ou EIRE\r\nISLANDE\r\nISRAEL\r\nITALIE\r\nJAMAIQUE\r\nJAPON\r\nJERSEY\r\nJORDANIE\r\nKAMTCHATKA\r\nKAZAKHSTAN\r\nKENYA\r\nKIRGHIZISTAN\r\nKIRIBATI\r\nKOSOVO\r\nKOWEIT\r\nLA REUNION\r\nLABRADOR\r\nLAOS\r\nLESOTHO\r\nLETTONIE\r\nLIBAN\r\nLIBERIA\r\nLIBYE\r\nLIECHTENSTEIN\r\nLITUANIE\r\nLUXEMBOURG\r\nMACAO\r\nMACEDOINE DU NORD (REPUBLIQUE DE)\r\nMADAGASCAR\r\nMALAISIE\r\nMALAWI\r\nMALDIVES\r\nMALI\r\nMALOUINES, OU FALKLAND (ILES)\r\nMALTE\r\nMAN (ILE)\r\nMANDCHOURIE\r\nMARIANNES DU NORD (ILES)\r\nMAROC\r\nMARSHALL (ILES)\r\nMARTINIQUE\r\nMAURICE\r\nMAURITANIE\r\nMAYOTTE\r\nMEXIQUE\r\nMICRONESIE (ETATS FEDERES DE)\r\nMOLDAVIE\r\nMONACO\r\nMONGOLIE\r\nMONTENEGRO\r\nMONTSERRAT\r\nMOZAMBIQUE\r\nNAMIBIE\r\nNAURU\r\nNEPAL\r\nNICARAGUA\r\nNIGER\r\nNIGERIA\r\nNIUE\r\nNORFOLK (ILE)\r\nNORVEGE\r\nNOUVELLE-CALEDONIE\r\nNOUVELLE-ZELANDE\r\nOCEAN INDIEN (TERRITOIRE BRITANNIQUE DE L')\r\nOMAN\r\nOUGANDA\r\nOUZBEKISTAN\r\nPAKISTAN\r\nPALAOS (ILES)\r\nPALESTINE (Etat de)\r\nPANAMA\r\nPAPOUASIE-NOUVELLE-GUINEE\r\nPARAGUAY\r\nPAYS-BAS\r\nPEROU\r\nPHILIPPINES\r\nPITCAIRN (ILE)\r\nPOLOGNE\r\nPOLYNESIE FRANCAISE\r\nPORTO RICO\r\nPORTUGAL\r\nPOSSESSIONS BRITANNIQUES AU PROCHE-ORIENT\r\nPRESIDES\r\nPROVINCES ESPAGNOLES D'AFRIQUE\r\nQATAR\r\nREPUBLIQUE DEMOCRATIQUE ALLEMANDE\r\nREPUBLIQUE FEDERALE D'ALLEMAGNE\r\nROUMANIE\r\nROYAUME-UNI\r\nRUSSIE\r\nRWANDA\r\nSAHARA OCCIDENTAL\r\nSAINT-BARTHELEMY\r\nSAINT-CHRISTOPHE-ET-NIEVES\r\nSAINT-MARIN\r\nSAINT-MARTIN\r\nSAINT-MARTIN (PARTIE NEERLANDAISE)\r\nSAINT-PIERRE-ET-MIQUELON\r\nSAINT-VINCENT-ET-LES GRENADINES\r\nSAINTE HELENE, ASCENSION ET TRISTAN DA CUNHA\r\nSAINTE-LUCIE\r\nSALOMON (ILES)\r\nSAMOA AMERICAINES\r\nSAMOA OCCIDENTALES\r\nSAO TOME-ET-PRINCIPE\r\nSENEGAL\r\nSERBIE\r\nSEYCHELLES\r\nSIBERIE\r\nSIERRA LEONE\r\nSINGAPOUR\r\nSLOVAQUIE\r\nSLOVENIE\r\nSOMALIE\r\nSOUDAN\r\nSOUDAN ANGLO-EGYPTIEN, KENYA, OUGANDA\r\nSOUDAN DU SUD\r\nSRI LANKA\r\nSUEDE\r\nSUISSE\r\nSURINAME\r\nSVALBARD et ILE JAN MAYEN\r\nSWAZILAND\r\nSYRIE\r\nTADJIKISTAN\r\nTAIWAN\r\nTANGER\r\nTANZANIE\r\nTCHAD\r\nTCHECOSLOVAQUIE\r\nTCHEQUE (REPUBLIQUE)\r\nTERR. DES ETATS-UNIS D'AMERIQUE EN AMERIQUE\r\nTERR. DES ETATS-UNIS D'AMERIQUE EN OCEANIE\r\nTERR. DU ROYAUME-UNI DANS L'ATLANTIQUE SUD\r\nTERRE-NEUVE\r\nTERRES AUSTRALES FRANCAISES\r\nTERRITOIRES DU ROYAUME-UNI AUX ANTILLES\r\nTHAILANDE\r\nTIMOR ORIENTAL\r\nTOGO\r\nTOKELAU\r\nTONGA\r\nTRINITE-ET-TOBAGO\r\nTUNISIE\r\nTURKESTAN RUSSE\r\nTURKMENISTAN\r\nTURKS ET CAIQUES (ILES)\r\nTURQUIE\r\nTURQUIE D'EUROPE\r\nTUVALU\r\nUKRAINE\r\nURUGUAY\r\nVANUATU\r\nVATICAN, ou SAINT-SIEGE\r\nVENEZUELA\r\nVIERGES BRITANNIQUES (ILES)\r\nVIERGES DES ETATS-UNIS (ILES)\r\nVIET NAM\r\nVIET NAM DU NORD\r\nVIET NAM DU SUD\r\nWALLIS-ET-FUTUNA\r\nYEMEN\r\nYEMEN (REPUBLIQUE ARABE DU)\r\nYEMEN DEMOCRATIQUE\r\nZAMBIE\r\nZANZIBAR\r\nZIMBABWE"
|
||||
|
||||
((0..(zone_geographique_header_order_place - 1)).to_a - [siret_order_place, fonction_order_place]).each do |i|
|
||||
map_source_to_destination_champ(i, i, **(champ_opts[i] || {}))
|
||||
end
|
||||
|
||||
((pays_commercialisation_order_place + 1)..25).each do |i|
|
||||
map_source_to_destination_champ(i - 2, i, **(champ_opts[i] || {}))
|
||||
end
|
||||
|
||||
discard_source_champ(
|
||||
TypeDeChamp.new(
|
||||
type_champ: 'text',
|
||||
order_place: siret_order_place,
|
||||
libelle: 'Numéro SIRET'
|
||||
)
|
||||
)
|
||||
|
||||
discard_source_champ(
|
||||
TypeDeChamp.new(
|
||||
type_champ: 'text',
|
||||
order_place: fonction_order_place,
|
||||
libelle: 'Fonction'
|
||||
)
|
||||
)
|
||||
|
||||
compute_destination_champ(
|
||||
TypeDeChamp.new(
|
||||
type_champ: 'text',
|
||||
order_place: fonction_order_place,
|
||||
libelle: 'Fonction',
|
||||
mandatory: true
|
||||
)
|
||||
) do |d, target_tdc|
|
||||
c = d.champs.joins(:type_de_champ).find_by(types_de_champ: { order_place: fonction_order_place })
|
||||
|
||||
target_tdc.champ.create(
|
||||
value: c&.value || 'Non renseigné',
|
||||
dossier: d
|
||||
)
|
||||
end
|
||||
|
||||
compute_destination_champ(
|
||||
TypeDeChamp.new(
|
||||
type_champ: 'siret',
|
||||
order_place: siret_order_place,
|
||||
libelle: 'Numéro SIRET'
|
||||
)
|
||||
) do |d, target_tdc|
|
||||
if d.etablissement.present?
|
||||
d.etablissement.signature = d.etablissement.sign
|
||||
end
|
||||
target_tdc.champ.create(
|
||||
value: d.etablissement&.siret,
|
||||
etablissement: d.etablissement,
|
||||
dossier: d
|
||||
)
|
||||
end
|
||||
|
||||
compute_destination_champ(
|
||||
TypeDeChamp.new(
|
||||
type_champ: 'header_section',
|
||||
order_place: 18,
|
||||
libelle: 'PARTIE 3 : ZONE GEOGRAPHIQUE'
|
||||
)
|
||||
) do |d, target_tdc|
|
||||
target_tdc.champ.create(dossier: d)
|
||||
end
|
||||
|
||||
compute_destination_champ(
|
||||
TypeDeChamp.new(
|
||||
type_champ: 'multiple_drop_down_list',
|
||||
order_place: 19,
|
||||
libelle: 'Pays de commercialisation',
|
||||
drop_down_list: DropDownList.new(value: pays_drop_down_values)
|
||||
)
|
||||
) do |d, target_tdc|
|
||||
target_tdc.champ.create(dossier: d, value: JSON.unparse(['FRANCE']))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Tasks::DossierProcedureMigrator.new(source_procedure, destination_procedure, mapping).migrate_procedure
|
||||
AutoReceiveDossiersForProcedureJob.set(cron: "* * * * *").perform_later(destination_procedure_id, 'accepte')
|
||||
end
|
||||
end
|
|
@ -1,61 +0,0 @@
|
|||
class FixAutomaticDossierLogs_2019_01_16
|
||||
def find_handlers
|
||||
# rubocop:disable Security/YAMLLoad
|
||||
Delayed::Job.where(queue: 'cron')
|
||||
.map { |job| YAML.load(job.handler) }
|
||||
.select { |handler| handler.job_data['job_class'] == 'AutoReceiveDossiersForProcedureJob' }
|
||||
# rubocop:enable Security/YAMLLoad
|
||||
end
|
||||
|
||||
def run
|
||||
handlers = find_handlers
|
||||
|
||||
handlers
|
||||
.map { |handler| handler.job_data['arguments'] }
|
||||
.each do |(procedure_id, state)|
|
||||
|
||||
procedure = Procedure
|
||||
.includes(:administrateur, dossiers: [:dossier_operation_logs, :follows])
|
||||
.find(procedure_id)
|
||||
|
||||
rake_puts "working on procedure #{procedure_id}, #{procedure.libelle} whose admin is #{procedure.administrateur.email}"
|
||||
|
||||
case state
|
||||
when Dossier.states.fetch(:en_instruction)
|
||||
dossiers = procedure.dossiers.state_en_instruction
|
||||
operation = 'passer_en_instruction'
|
||||
when Dossier.states.fetch(:accepte)
|
||||
dossiers = procedure.dossiers.accepte
|
||||
operation = 'accepter'
|
||||
end
|
||||
|
||||
dossier_operation_logs = DossierOperationLog
|
||||
.where(dossier: dossiers, operation: operation)
|
||||
|
||||
rake_puts "affecting #{dossier_operation_logs.count} dossier_operation_logs"
|
||||
|
||||
dossier_operation_logs
|
||||
.update_all(gestionnaire_id: nil, automatic_operation: true)
|
||||
|
||||
# if the dossier is only followed by the procedure administrateur
|
||||
# unfollow
|
||||
if state == Dossier.states.fetch(:en_instruction)
|
||||
dossier_to_unfollows = dossiers
|
||||
.select { |d| d.follows.count == 1 && d.follows.first.gestionnaire.email == procedure.administrateur.email }
|
||||
|
||||
rake_puts "affecting #{dossier_to_unfollows.count} dossiers"
|
||||
|
||||
dossier_to_unfollows
|
||||
.each { |d| d.follows.destroy_all }
|
||||
end
|
||||
|
||||
rake_puts ""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
namespace :'2019_01_16_fix_automatic_dossier_logs' do
|
||||
task run: :environment do
|
||||
FixAutomaticDossierLogs_2019_01_16.new.run
|
||||
end
|
||||
end
|
|
@ -1,37 +0,0 @@
|
|||
require Rails.root.join("lib", "tasks", "task_helper")
|
||||
|
||||
namespace :after_party do
|
||||
desc 'Deployment task: clone_service_for_transferred_procedures'
|
||||
task clone_service_for_transferred_procedures: :environment do
|
||||
rake_puts "Running deploy task 'clone_service_for_transferred_procedures'"
|
||||
|
||||
procedures = Procedure.includes(:service).where.not(service_id: nil)
|
||||
procedures_to_fix_in_array = procedures.select do |p|
|
||||
p.administrateur_id != p.service.administrateur_id
|
||||
end
|
||||
procedures_to_fix = Procedure.where(id: procedures_to_fix_in_array.map(&:id))
|
||||
|
||||
service_and_admin_list = procedures_to_fix.group(:service_id, :administrateur_id).count.keys
|
||||
progress = ProgressReport.new(service_and_admin_list.count)
|
||||
|
||||
service_and_admin_list.each do |service_id, administrateur_id|
|
||||
cloned_service = Service.find(service_id).clone_and_assign_to_administrateur(Administrateur.find(administrateur_id))
|
||||
|
||||
if cloned_service.save
|
||||
rake_puts "Fixing Service #{service_id} for Administrateur #{administrateur_id}"
|
||||
procedures_to_fix
|
||||
.where(service_id: service_id, administrateur_id: administrateur_id)
|
||||
.update_all(service_id: cloned_service.id)
|
||||
else
|
||||
rake_puts "Cannot fix Service #{service_id} for Administrateur #{administrateur_id}, it should be fixed manually. Errors : #{cloned_service.errors.full_messages}"
|
||||
end
|
||||
progress.inc
|
||||
end
|
||||
|
||||
progress.finish
|
||||
|
||||
# Update task as completed. If you remove the line below, the task will
|
||||
# run with every deploy (or every time you call after_party:run).
|
||||
AfterParty::TaskRecord.create version: '20181219164523'
|
||||
end # task :clone_service_for_transferred_procedures
|
||||
end # namespace :after_party
|
|
@ -1,126 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe '2018_07_31_nutriscore' do
|
||||
let(:gestionnaire) { create(:gestionnaire) }
|
||||
let(:proc_from) do
|
||||
proc_from = create(:procedure, :published)
|
||||
((0..23).to_a - [1, 2, 9, 18]).each do |i|
|
||||
proc_from.types_de_champ << create(:type_de_champ_text, order_place: i, procedure: proc_from)
|
||||
end
|
||||
proc_from.types_de_champ << create(:type_de_champ_text, order_place: 9, libelle: 'Fonction', procedure: proc_from)
|
||||
proc_from.types_de_champ << create(:type_de_champ_header_section, order_place: 18, libelle: 'PARTIE 3 : ENGAGEMENT DE L’EXPLOITANT', procedure: proc_from)
|
||||
proc_from.save
|
||||
proc_from
|
||||
end
|
||||
let!(:type_champ_from) { create(:type_de_champ_textarea, order_place: 1, libelle: 'texte', procedure: proc_from) }
|
||||
let!(:type_champ_siret_from) { create(:type_de_champ_text, order_place: 2, libelle: 'Numéro SIRET', procedure: proc_from) }
|
||||
let!(:type_champ_fonction_from) {}
|
||||
|
||||
let(:etablissement) { create(:etablissement) }
|
||||
let!(:dossier) { create(:dossier, procedure: proc_from, etablissement: etablissement) }
|
||||
|
||||
let(:proc_to) do
|
||||
proc_to = create(:procedure, administrateur: proc_from.administrateur)
|
||||
((0..17).to_a - [1, 2, 9]).each do |i|
|
||||
libelle = proc_from.types_de_champ.find_by(order_place: i).libelle
|
||||
proc_to.types_de_champ << create(:type_de_champ_text, order_place: i, libelle: libelle, procedure: proc_to)
|
||||
end
|
||||
proc_to.types_de_champ << create(:type_de_champ_header_section, order_place: 18, libelle: 'PARTIE 3 : ZONE GEOGRAPHIQUE', procedure: proc_to)
|
||||
proc_to.types_de_champ << create(
|
||||
:type_de_champ_multiple_drop_down_list,
|
||||
order_place: 19,
|
||||
libelle: 'Pays de commercialisation',
|
||||
drop_down_list: create(:drop_down_list, value: (Champs::PaysChamp.pays - ['----']).join("\r\n")),
|
||||
procedure: proc_to
|
||||
)
|
||||
proc_to.types_de_champ << create(:type_de_champ_header_section, order_place: 20, libelle: 'PARTIE 4 : ENGAGEMENT DE L’EXPLOITANT', procedure: proc_to)
|
||||
(21..25).each do |i|
|
||||
libelle = proc_from.types_de_champ.find_by(order_place: i - 2).libelle
|
||||
proc_to.types_de_champ << create(:type_de_champ_text, order_place: i, libelle: libelle, procedure: proc_to)
|
||||
end
|
||||
proc_to.save
|
||||
proc_to
|
||||
end
|
||||
let!(:type_champ_to) { create(:type_de_champ_textarea, order_place: 1, libelle: 'texte', procedure: proc_to) }
|
||||
let!(:type_champ_siret_to) { create(:type_de_champ_siret, order_place: 2, libelle: 'Numéro SIRET', procedure: proc_to) }
|
||||
let!(:type_champ_fonction_to) { create(:type_de_champ_text, order_place: 9, libelle: 'Fonction', mandatory: true, procedure: proc_to) }
|
||||
|
||||
let(:rake_task) { Rake::Task['2018_07_31_nutriscore:migrate_dossiers'] }
|
||||
|
||||
def run_task
|
||||
ENV['SOURCE_PROCEDURE_ID'] = proc_from.id.to_s
|
||||
ENV['DESTINATION_PROCEDURE_ID'] = proc_to.id.to_s
|
||||
rake_task.invoke
|
||||
dossier.reload
|
||||
proc_from.reload
|
||||
proc_to.reload
|
||||
end
|
||||
|
||||
after { rake_task.reenable }
|
||||
|
||||
context 'on happy path' do
|
||||
before do
|
||||
gestionnaire.assign_to_procedure(proc_from)
|
||||
run_task
|
||||
end
|
||||
|
||||
it { expect(dossier.procedure).to eq(proc_to) }
|
||||
it { expect(dossier.champs.pluck(:type_de_champ_id)).to match_array(proc_to.types_de_champ.pluck(:id)) }
|
||||
it { expect(dossier.champs.find_by(type_de_champ: type_champ_siret_to).value).to eq(etablissement.siret) }
|
||||
it { expect(dossier.champs.find_by(type_de_champ: type_champ_siret_to).etablissement).to eq(etablissement) }
|
||||
it { expect(proc_from).to be_archivee }
|
||||
it { expect(proc_to).to be_publiee }
|
||||
it { expect(proc_to.gestionnaires).to eq([gestionnaire]) }
|
||||
end
|
||||
|
||||
context 'detecting error conditions' do
|
||||
context 'with administrateur mismatch' do
|
||||
let(:proc_to) { create(:procedure) }
|
||||
|
||||
it { expect { run_task }.to raise_exception(/^Mismatching administrateurs/) }
|
||||
end
|
||||
|
||||
context 'with champ count mismatch' do
|
||||
before { create(:type_de_champ_textarea, order_place: 26, libelle: 'texte', procedure: proc_to) }
|
||||
|
||||
it { expect { run_task }.to raise_exception('Incorrect destination size 27 (expected 26)') }
|
||||
end
|
||||
|
||||
context 'with champ libelle mismatch' do
|
||||
let!(:type_champ_to) { create(:type_de_champ_textarea, order_place: 1, libelle: 'autre texte', procedure: proc_to) }
|
||||
|
||||
it { expect { run_task }.to raise_exception(/incorrect libelle texte \(expected autre texte\)$/) }
|
||||
end
|
||||
|
||||
context 'with champ type mismatch' do
|
||||
let!(:type_champ_to) { create(:type_de_champ_text, order_place: 1, libelle: 'texte', procedure: proc_to) }
|
||||
|
||||
it { expect { run_task }.to raise_exception(/incorrect type champ textarea \(expected text\)$/) }
|
||||
end
|
||||
|
||||
context 'with champ mandatoriness mismatch' do
|
||||
let!(:type_champ_to) { create(:type_de_champ_textarea, order_place: 1, libelle: 'texte', mandatory: true, procedure: proc_to) }
|
||||
|
||||
it { expect { run_task }.to raise_exception(/champ should be mandatory$/) }
|
||||
end
|
||||
|
||||
context 'with dropdown mismatch' do
|
||||
let!(:type_champ_from) { create(:type_de_champ_drop_down_list, order_place: 1, libelle: 'dropdown', drop_down_list: create(:drop_down_list, value: 'something'), procedure: proc_from) }
|
||||
let!(:type_champ_to) { create(:type_de_champ_drop_down_list, order_place: 1, libelle: 'dropdown', drop_down_list: create(:drop_down_list, value: 'something else'), procedure: proc_to) }
|
||||
|
||||
it { expect { run_task }.to raise_exception(/incorrect drop down list \["", "something"\] \(expected \["", "something else"\]\)$/) }
|
||||
end
|
||||
|
||||
context 'with siret mismatch on source' do
|
||||
let!(:type_champ_siret_from) { create(:type_de_champ_textarea, order_place: 2, libelle: 'Numéro SIRET', procedure: proc_from) }
|
||||
|
||||
it { expect { run_task }.to raise_exception(/incorrect type champ textarea \(expected text\)$/) }
|
||||
end
|
||||
|
||||
context 'with siret mismatch on destination' do
|
||||
let!(:type_champ_siret_to) { create(:type_de_champ_text, order_place: 2, libelle: 'Numéro SIRET', procedure: proc_to) }
|
||||
|
||||
it { expect { run_task }.to raise_exception(/incorrect type champ text \(expected siret\)$/) }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,82 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
load Rails.root.join('lib', 'tasks', '2019_01_16_fix_automatic_dossier_logs.rake')
|
||||
|
||||
describe '2019_01_16_fix_automatic_dossier_logs' do
|
||||
let!(:rake_task) { Rake::Task['2019_01_16_fix_automatic_dossier_logs:run'] }
|
||||
let!(:administrateur) { create(:administrateur) }
|
||||
let!(:another_gestionnaire) { create(:gestionnaire) }
|
||||
let!(:procedure) { create(:procedure, administrateur: administrateur) }
|
||||
let!(:dossier) { create(:dossier, procedure: procedure) }
|
||||
let!(:fix_automatic_dossier_logs) { FixAutomaticDossierLogs_2019_01_16.new }
|
||||
|
||||
before do
|
||||
allow(fix_automatic_dossier_logs).to receive(:find_handlers)
|
||||
.and_return([double(job_data: { 'arguments' => [procedure.id, final_state] })])
|
||||
end
|
||||
|
||||
subject do
|
||||
fix_automatic_dossier_logs.run
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
context 'when the dossiers are automatically moved to en_instruction' do
|
||||
let(:final_state) { 'en_instruction' }
|
||||
|
||||
context 'and a dossier has been accidentally affected to an administrateur' do
|
||||
before do
|
||||
dossier.passer_en_instruction!(administrateur.gestionnaire)
|
||||
|
||||
control = DossierOperationLog.create(
|
||||
gestionnaire: another_gestionnaire,
|
||||
operation: 'refuser',
|
||||
automatic_operation: false
|
||||
)
|
||||
|
||||
dossier.dossier_operation_logs << control
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(dossier.follows.count).to eq(0) }
|
||||
|
||||
it do
|
||||
expect(dossier_logs).to match_array([
|
||||
[nil, 'passer_en_instruction', true],
|
||||
[another_gestionnaire.id, "refuser", false]
|
||||
])
|
||||
end
|
||||
end
|
||||
|
||||
context ', followed anyway by another person and accidentally ...' do
|
||||
before do
|
||||
another_gestionnaire.follow(dossier)
|
||||
dossier.passer_en_instruction!(administrateur.gestionnaire)
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(dossier.follows.count).to eq(2) }
|
||||
it { expect(dossier_logs).to match([[nil, 'passer_en_instruction', true]]) }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the dossiers are automatically moved to accepte' do
|
||||
let(:final_state) { 'accepte' }
|
||||
|
||||
context 'and a dossier has been accidentally affected to an administrateur' do
|
||||
before do
|
||||
dossier.accepter!(administrateur.gestionnaire, '')
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(dossier_logs).to match([[nil, 'accepter', true]]) }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def dossier_logs
|
||||
dossier.dossier_operation_logs.pluck(:gestionnaire_id, :operation, :automatic_operation)
|
||||
end
|
||||
end
|
|
@ -1,32 +0,0 @@
|
|||
describe '20181219164523_clone_service_for_transferred_procedures.rake' do
|
||||
let(:rake_task) { Rake::Task['after_party:clone_service_for_transferred_procedures'] }
|
||||
|
||||
subject do
|
||||
rake_task.invoke
|
||||
end
|
||||
|
||||
after do
|
||||
rake_task.reenable
|
||||
end
|
||||
|
||||
context 'procedures from different admins share the same service' do
|
||||
let(:admin1) { create(:administrateur) }
|
||||
let(:admin2) { create(:administrateur) }
|
||||
let(:service) { create(:service, administrateur: admin1) }
|
||||
let!(:procedure1) { create(:procedure, service: service, administrateur: admin1) }
|
||||
let!(:procedure2) { create(:procedure, service: service, administrateur: admin2) }
|
||||
let!(:procedure3) { create(:procedure, service: service, administrateur: admin2) }
|
||||
|
||||
it 'clones service for procedure2 & procedure3' do
|
||||
subject
|
||||
expect(procedure1.reload.service).not_to eq(procedure2.reload.service)
|
||||
expect(procedure1.reload.service).not_to eq(procedure3.reload.service)
|
||||
expect(procedure2.reload.service).to eq(procedure3.reload.service)
|
||||
end
|
||||
|
||||
it 'does nothing for procedure1' do
|
||||
subject
|
||||
expect(procedure1.reload.service).to eq(service)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue