-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Créé la liste de nouveaux tags en base et les associe aux démarches
- Loading branch information
Showing
2 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# frozen_string_literal: true | ||
|
||
# this task is used to create the procedure_tags and backfill the procedures that have the tag in their tags array | ||
|
||
module Maintenance | ||
class CreateProcedureTagsTask < MaintenanceTasks::Task | ||
include RunnableOnDeployConcern | ||
include StatementsHelpersConcern | ||
run_on_first_deploy | ||
|
||
def collection | ||
[ | ||
"Aap", | ||
"Accompagnement", | ||
"Action sociale", | ||
"Adeli", | ||
"Affectation", | ||
"Agrément", | ||
"Agriculture", | ||
"agroécologie", | ||
"Aide aux entreprises", | ||
"Aide financière", | ||
"Appel à manifestation d'intérêt", | ||
"AMI", | ||
"Animaux", | ||
"Appel à projets", | ||
"Association", | ||
"Auto-école", | ||
"Autorisation", | ||
"Autorisation d'exercer", | ||
"Bilan", | ||
"Biodiversité", | ||
"Candidature", | ||
"Cerfa", | ||
"Chasse", | ||
"Cinéma", | ||
"Cmg", | ||
"Collectivé territoriale", | ||
"Collège", | ||
"Convention", | ||
"Covid", | ||
"Culture", | ||
"Dérogation", | ||
"Diplôme", | ||
"Drone", | ||
"DSDEN", | ||
"Eau", | ||
"Ecoles", | ||
"Education", | ||
"Elections", | ||
"Energie", | ||
"Enseignant", | ||
"ENT", | ||
"Environnement", | ||
"Étrangers", | ||
"Formation", | ||
"FPRNM", | ||
"Funéraire", | ||
"Handicap", | ||
"Hygiène", | ||
"Industrie", | ||
"innovation", | ||
"Inscription", | ||
"Logement", | ||
"Lycée", | ||
"Manifestation", | ||
"Médicament", | ||
"Micro-crèche", | ||
"MODELE DS", | ||
"Numérique", | ||
"Permis", | ||
"Pompiers", | ||
"Préfecture", | ||
"Professionels de santé", | ||
"Recrutement", | ||
"Rh", | ||
"Santé", | ||
"Scolaire", | ||
"SDIS", | ||
"Sécurité", | ||
"Sécurité routière", | ||
"Sécurité sociale", | ||
"Séjour", | ||
"Service civique", | ||
"Subvention", | ||
"Supérieur", | ||
"Taxi", | ||
"Télétravail", | ||
"Tirs", | ||
"Transition écologique", | ||
"Transport", | ||
"Travail", | ||
"Université", | ||
"Urbanisme" | ||
] | ||
end | ||
|
||
def process(tag) | ||
procedure_tag = ProcedureTag.find_or_create_by(name: tag) | ||
|
||
Procedure.where("? ILIKE ANY(tags)", tag).find_each(batch_size: 500) do |procedure| | ||
procedure.procedure_tags << procedure_tag unless procedure.procedure_tags.include?(procedure_tag) | ||
end | ||
end | ||
|
||
def count | ||
collection.size | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
module Maintenance | ||
RSpec.describe CreateProcedureTagsTask do | ||
describe "#process" do | ||
subject(:process) { described_class.new.process(tag) } | ||
|
||
let(:tag) { "Accompagnement" } | ||
let!(:procedure) { create(:procedure, tags: ["Accompagnement"]) } | ||
|
||
it "creates the ProcedureTag if it does not exist" do | ||
expect { process }.to change { ProcedureTag.count }.by(1) | ||
expect(ProcedureTag.last.name).to eq(tag) | ||
end | ||
|
||
context "when the ProcedureTag already exists" do | ||
let!(:procedure_tag) { ProcedureTag.create(name: tag) } | ||
|
||
it "does not create a duplicate ProcedureTag" do | ||
expect { process }.not_to change { ProcedureTag.count } | ||
end | ||
end | ||
|
||
it "associates procedures with the ProcedureTag" do | ||
process | ||
expect(procedure.reload.procedure_tags.map(&:name)).to include(tag) | ||
end | ||
end | ||
end | ||
end |