Add rake task to activate publish draft

This commit is contained in:
Mathieu Magnin 2019-02-19 16:33:23 +01:00
parent 272a6b700d
commit 11078b7f71
2 changed files with 55 additions and 0 deletions

View file

@ -130,4 +130,28 @@ namespace :support do
user.update(email: new_email)
end
desc <<~EOD
Activate feature publish draft
EOD
task activate_publish_draft: :environment do
start_with = ENV['START_WITH']
administrateurs = Administrateur.where("email like ?", "#{start_with}%")
rake_puts("Activating publish draft for #{administrateurs.count} administrateurs...")
administrateurs.each do |a|
rake_puts("Activating publish draft for #{a.email}")
a.features["publish_draft"] = true
a.save
a.procedures.brouillon.each do |p|
if p.path.nil?
p.path = SecureRandom.uuid
p.save
end
end
end
end
end

View file

@ -0,0 +1,31 @@
require 'spec_helper'
describe 'activate_publish_draft#clean' do
let(:rake_task) { Rake::Task['support:activate_publish_draft'] }
let(:administrateur) { create(:administrateur) }
let!(:procedure) { create(:procedure, administrateur: administrateur) }
let!(:procedure2) { create(:simple_procedure, administrateur: administrateur) }
before do
ENV['START_WITH'] = administrateur.email
rake_task.invoke
administrateur.reload
end
after { rake_task.reenable }
it 'activate feature for administrateur' do
expect(administrateur.features["publish_draft"]).to eq(true)
end
it 'create a path for his brouillon procedure' do
expect(administrateur.procedures.brouillon.count).to eq(1)
expect(administrateur.procedures.brouillon.first.path).not_to eq(nil)
end
it 'does not change the path of his published procedure' do
expect(administrateur.procedures.publiee.count).to eq(1)
expect(administrateur.procedures.publiee.first.path).to eq(procedure2.path)
end
end