-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(champ): migrate champ expression reguliere type to formatted
Co-Authored-By: Christophe Robillard <christophe.robillard@mail.numerique.gouv.fr> Co-Authored-By: simon lehericey <mail@simon.lehericey.net>
- Loading branch information
1 parent
3ba79f6
commit 2427d31
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
app/tasks/maintenance/t20241127_migrate_champ_expression_reguliere_to_formatted_task.rb
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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Maintenance | ||
class T20241127MigrateChampExpressionReguliereToFormattedTask < MaintenanceTasks::Task | ||
# Documentation: les champs ExpressionReguliere sont migrés au nouveau champ Formatted | ||
# en mode avancé. | ||
# Voir aussi la maintenance task de transformation des types de champs. | ||
|
||
include RunnableOnDeployConcern | ||
include StatementsHelpersConcern | ||
|
||
# Uncomment only if this task MUST run imperatively on its first deployment. | ||
# If possible, leave commented for manual execution later. | ||
run_on_first_deploy | ||
|
||
def collection | ||
with_statement_timeout("5min") do | ||
Champ.where(type: ["Champs::ExpressionReguliereChamp", "Champs::FormattedChamp"]).in_batches | ||
end | ||
end | ||
|
||
def process(batch) | ||
batch.update_all(type: "Champs::FormattedChamp") | ||
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
28 changes: 28 additions & 0 deletions
28
.../tasks/maintenance/t20241127_migrate_champ_expression_reguliere_to_formatted_task_spec.rb
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,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
module Maintenance | ||
RSpec.describe T20241127MigrateChampExpressionReguliereToFormattedTask do | ||
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: "expression_reguliere" }, { type: "text" }]) } | ||
let(:dossier) { create(:dossier, :with_populated_champs, procedure: procedure) } | ||
|
||
describe "#process" do | ||
let(:batch_of_champs) { Champ.where(type: ["Champs::ExpressionReguliereChamp", "Champs::FormattedChamp"]).in_batches } | ||
subject(:process) { described_class.process(batch_of_champs) } | ||
|
||
it "works" do | ||
dossier | ||
process | ||
expect(Champ.first.type).to eq("Champs::FormattedChamp") | ||
end | ||
end | ||
|
||
describe '#collection' do | ||
it "works" do | ||
dossier # create dossier | ||
expect(described_class.collection.relation.map(&:type)).to eq(["Champs::ExpressionReguliereChamp"]) | ||
end | ||
end | ||
end | ||
end |