Merge branch 'dev'
This commit is contained in:
commit
6bec2f43a3
5 changed files with 56 additions and 14 deletions
|
@ -79,10 +79,7 @@ class Procedure < ApplicationRecord
|
|||
procedure_path = ProcedurePath.find_by(path: path)
|
||||
|
||||
if procedure_path.present?
|
||||
if procedure_path.procedure != self
|
||||
procedure_path.procedure.archive!
|
||||
procedure_path.update(procedure: self)
|
||||
end
|
||||
procedure_path.publish!(self)
|
||||
else
|
||||
ProcedurePath.create(procedure: self, administrateur: administrateur, path: path)
|
||||
end
|
||||
|
|
|
@ -11,15 +11,24 @@ class ProcedurePath < ApplicationRecord
|
|||
where(procedure: procedure).or(where(test_procedure: procedure)).last
|
||||
end
|
||||
|
||||
def hide!(procedure)
|
||||
if self.procedure == procedure
|
||||
def hide!(new_procedure)
|
||||
if procedure == new_procedure
|
||||
update(procedure: nil)
|
||||
end
|
||||
if self.test_procedure == procedure
|
||||
if test_procedure == new_procedure
|
||||
update(test_procedure: nil)
|
||||
end
|
||||
if procedure.nil? && test_procedure.nil?
|
||||
destroy
|
||||
end
|
||||
end
|
||||
|
||||
def publish!(new_procedure)
|
||||
if procedure != new_procedure
|
||||
if procedure&.publiee?
|
||||
procedure.archive!
|
||||
end
|
||||
update(procedure: new_procedure)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
26
lib/tasks/2018_05_21_cerfa_to_pj.rake
Normal file
26
lib/tasks/2018_05_21_cerfa_to_pj.rake
Normal file
|
@ -0,0 +1,26 @@
|
|||
namespace :'2018_05_21_cerfa_to_pj' do
|
||||
task set: :environment do
|
||||
dossiers = Cerfa.includes(dossier: [:procedure]).all.reject(&:empty?).map(&:dossier).compact.uniq
|
||||
|
||||
dossiers.group_by(&:procedure).each do |procedure, dossiers|
|
||||
if !procedure.type_de_champs.find_by(libelle: 'CERFA')
|
||||
procedure.administrateur.enable_feature(:champ_pj)
|
||||
type_de_champ = procedure.type_de_champs.create(
|
||||
type_champ: 'piece_justificative',
|
||||
libelle: 'CERFA'
|
||||
)
|
||||
dossiers.each do |dossier|
|
||||
cerfa = dossier.cerfa.last
|
||||
champ = type_de_champ.champ.create(dossier: dossier)
|
||||
response = Typhoeus.get(cerfa.content_url, timeout: 5)
|
||||
if response.success?
|
||||
champ.piece_justificative_file.attach(
|
||||
io: StringIO.new(response.body),
|
||||
filename: cerfa.content.filename
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -365,6 +365,22 @@ describe Admin::ProceduresController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
context 'procedure path exists and has archived procedure' do
|
||||
let(:procedure_path) { procedure2.path }
|
||||
let(:procedure2) { create(:procedure, :archived, administrateur: admin) }
|
||||
|
||||
it 'publish the given procedure' do
|
||||
expect(procedure.publiee?).to be_truthy
|
||||
expect(procedure.path).to eq(procedure_path)
|
||||
expect(response.status).to eq 302
|
||||
expect(flash[:notice]).to have_content 'Procédure publiée'
|
||||
end
|
||||
|
||||
it 'archive previous procedure' do
|
||||
expect(procedure2.archivee?).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
context 'procedure path exists and is not owned by current administrator' do
|
||||
let(:procedure_path) { procedure3.path }
|
||||
|
||||
|
@ -605,7 +621,7 @@ describe Admin::ProceduresController, type: :controller do
|
|||
end
|
||||
|
||||
it { expect(procedure.hidden_at).not_to be_nil }
|
||||
it { expect(procedure.procedure_path.procedure).to be_nil }
|
||||
it { expect(procedure.procedure_path).to be_nil }
|
||||
end
|
||||
|
||||
context "when procedure has no path" do
|
||||
|
|
|
@ -164,12 +164,6 @@ describe Users::DossiersController, type: :controller do
|
|||
it { expect(subject.status).to eq 200 }
|
||||
end
|
||||
|
||||
context 'when procedure is hidden' do
|
||||
let(:procedure) { create(:procedure, :hidden) }
|
||||
|
||||
it { expect(subject).to redirect_to(root_path) }
|
||||
end
|
||||
|
||||
context 'when procedure path dose not exist' do
|
||||
let(:path) { 'hello' }
|
||||
|
||||
|
|
Loading…
Reference in a new issue