manual task for populating zones

This commit is contained in:
Christophe Robillard 2021-12-14 14:33:19 +01:00
parent dec1f787a7
commit 84c648eef0
4 changed files with 21 additions and 28 deletions

View file

@ -1,17 +0,0 @@
namespace :after_party do
desc 'Deployment task: populate_zones'
task populate_zones: :environment do
puts "Running deploy task 'populate_zones'"
Zone.create!(acronym: 'COLLECTIVITE', label: 'Collectivité territoriale')
config = Psych.safe_load(File.read(Rails.root.join("config", "zones.yml")))
config["ministeres"].each do |ministere|
acronym = ministere.keys.first
Zone.create!(acronym: acronym, label: ministere["label"])
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

View file

@ -0,0 +1,10 @@
task populate_zones: :environment do
puts "Running deploy task 'populate_zones'"
Zone.create!(acronym: 'COLLECTIVITE', label: 'Collectivité territoriale')
config = Psych.safe_load(File.read(Rails.root.join("config", "zones.yml")))
config["ministeres"].each do |ministere|
acronym = ministere.keys.first
Zone.create!(acronym: acronym, label: ministere["label"])
end
end

View file

@ -1,11 +0,0 @@
describe '20211116140232_populate_zones' do
let(:rake_task) { Rake::Task['after_party:populate_zones'] }
subject(:run_task) do
rake_task.invoke
end
it 'populates zones' do
run_task
expect(Zone.find_by(acronym: 'SPM').label).to eq "Premier ministre"
end
end

View file

@ -0,0 +1,11 @@
describe 'populate_zones' do
let(:rake_task) { Rake::Task['populate_zones'] }
subject(:run_task) do
rake_task.invoke
end
it 'populates zones' do
run_task
expect(Zone.find_by(acronym: 'PM').label).to eq "Premier ministre"
end
end