Skip to content

Commit

Permalink
Créé la liste de nouveaux tags en base et les associe aux démarches
Browse files Browse the repository at this point in the history
  • Loading branch information
kara22 committed Oct 11, 2024
1 parent 484e762 commit 54bb5f2
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 0 deletions.
110 changes: 110 additions & 0 deletions app/tasks/maintenance/create_procedure_tags_task.rb
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
[

Check warning on line 12 in app/tasks/maintenance/create_procedure_tags_task.rb

View check run for this annotation

Codecov / codecov/patch

app/tasks/maintenance/create_procedure_tags_task.rb#L12

Added line #L12 was not covered by tests
"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

Check warning on line 107 in app/tasks/maintenance/create_procedure_tags_task.rb

View check run for this annotation

Codecov / codecov/patch

app/tasks/maintenance/create_procedure_tags_task.rb#L107

Added line #L107 was not covered by tests
end
end
end
32 changes: 32 additions & 0 deletions spec/tasks/maintenance/create_procedure_tags_task_spec.rb
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

0 comments on commit 54bb5f2

Please sign in to comment.