-
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.
- Loading branch information
Showing
2 changed files
with
45 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,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module Maintenance | ||
class BackfillAddressValueJSONTask < MaintenanceTasks::Task | ||
include RunnableOnDeployConcern | ||
include StatementsHelpersConcern | ||
|
||
no_collection | ||
|
||
def process | ||
sql = "UPDATE champs SET value_json = data WHERE type = 'Champs::AddressChamp' AND data IS NOT NULL;" | ||
|
||
with_statement_timeout("5min") do | ||
Champ.connection.execute(sql) | ||
end | ||
end | ||
end | ||
end |
27 changes: 27 additions & 0 deletions
27
spec/tasks/maintenance/backfill_address_value_json_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,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
module Maintenance | ||
RSpec.describe BackfillAddressValueJSONTask do | ||
describe "#process" do | ||
subject(:process) { described_class.process } | ||
|
||
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :address, libelle: 'address' }]) } | ||
let(:dossier) { create(:dossier, procedure:) } | ||
let(:address_champ) { dossier.project_champs_public.first } | ||
let(:address_data) { { 'address' => 'address' } } | ||
|
||
before { address_champ.update(data: address_data) } | ||
|
||
it do | ||
expect(address_champ.value_json).to be_nil | ||
|
||
process | ||
address_champ.reload | ||
|
||
expect(address_champ.value_json).to eq(address_data) | ||
end | ||
end | ||
end | ||
end |