make populate_zones an after_party task
This commit is contained in:
parent
f452e1014a
commit
f846393ec0
5 changed files with 35 additions and 26 deletions
28
lib/tasks/deployment/20220922151100_populate_zones.rake
Normal file
28
lib/tasks/deployment/20220922151100_populate_zones.rake
Normal file
|
@ -0,0 +1,28 @@
|
|||
namespace :after_party do
|
||||
desc 'Deployment task: populate_zones'
|
||||
task populate_zones: :environment do
|
||||
if Flipper.enabled? :zonage
|
||||
puts "Running deploy task 'populate_zones'"
|
||||
collectivite = Zone.find_or_create_by!(acronym: 'COLLECTIVITE')
|
||||
coll_label = collectivite.labels.find_or_initialize_by(designated_on: Date.parse('1977-07-30'))
|
||||
coll_label.update(name: 'Collectivité territoriale')
|
||||
|
||||
config = Psych.safe_load(File.read(Rails.root.join("config", "zones.yml")))
|
||||
config["ministeres"].each do |ministere|
|
||||
acronym = ministere.keys.first
|
||||
zone = Zone.find_or_create_by!(acronym: acronym)
|
||||
labels_a = ministere[acronym]
|
||||
labels_a.each do |label_h|
|
||||
designated_on = label_h.keys.first
|
||||
label = zone.labels.find_or_initialize_by(designated_on: designated_on)
|
||||
label.update(name: label_h[designated_on])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 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: AfterParty::TaskRecorder.new(__FILE__).timestamp
|
||||
end
|
||||
end
|
|
@ -1,21 +0,0 @@
|
|||
namespace :zones do
|
||||
task populate_zones: :environment do
|
||||
puts "Running deploy task 'populate_zones'"
|
||||
|
||||
collectivite = Zone.find_or_create_by!(acronym: 'COLLECTIVITE')
|
||||
coll_label = collectivite.labels.find_or_initialize_by(designated_on: Date.parse('1977-07-30'))
|
||||
coll_label.update(name: 'Collectivité territoriale')
|
||||
|
||||
config = Psych.safe_load(File.read(Rails.root.join("config", "zones.yml")))
|
||||
config["ministeres"].each do |ministere|
|
||||
acronym = ministere.keys.first
|
||||
zone = Zone.find_or_create_by!(acronym: acronym)
|
||||
labels_a = ministere[acronym]
|
||||
labels_a.each do |label_h|
|
||||
designated_on = label_h.keys.first
|
||||
label = zone.labels.find_or_initialize_by(designated_on: designated_on)
|
||||
label.update(name: label_h[designated_on])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,7 @@
|
|||
describe 'populate_zones' do
|
||||
let(:rake_task) { Rake::Task['zones:populate_zones'] }
|
||||
describe '20220922151100_populate_zones' do
|
||||
let(:rake_task) { Rake::Task['after_party:populate_zones'] }
|
||||
subject(:run_task) do
|
||||
Flipper.enable :zonage
|
||||
rake_task.invoke
|
||||
end
|
||||
after(:each) do
|
|
@ -1,10 +1,11 @@
|
|||
describe UpdateZoneToProceduresService do
|
||||
before(:each) do
|
||||
Rake::Task['zones:populate_zones'].invoke
|
||||
Flipper.enable :zonage
|
||||
Rake::Task['after_party:populate_zones'].invoke
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
Rake::Task['zones:populate_zones'].reenable
|
||||
Rake::Task['after_party:populate_zones'].reenable
|
||||
end
|
||||
|
||||
describe '#call' do
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
describe 'administrateurs/procedures/edit.html.haml' do
|
||||
let(:logo) { fixture_file_upload('spec/fixtures/files/logo_test_procedure.png', 'image/png') }
|
||||
let(:procedure) { create(:procedure, logo: logo, lien_site_web: 'http://some.website') }
|
||||
let(:populate_zones_task) { Rake::Task['zones:populate_zones'] }
|
||||
let(:populate_zones_task) { Rake::Task['after_party:populate_zones'] }
|
||||
|
||||
before do
|
||||
Flipper.enable(:zonage)
|
||||
|
|
Loading…
Reference in a new issue