Merge branch 'dev'

This commit is contained in:
gregoirenovel 2018-05-30 10:48:26 +02:00
commit 6bec2f43a3
5 changed files with 56 additions and 14 deletions

View file

@ -79,10 +79,7 @@ class Procedure < ApplicationRecord
procedure_path = ProcedurePath.find_by(path: path) procedure_path = ProcedurePath.find_by(path: path)
if procedure_path.present? if procedure_path.present?
if procedure_path.procedure != self procedure_path.publish!(self)
procedure_path.procedure.archive!
procedure_path.update(procedure: self)
end
else else
ProcedurePath.create(procedure: self, administrateur: administrateur, path: path) ProcedurePath.create(procedure: self, administrateur: administrateur, path: path)
end end

View file

@ -11,15 +11,24 @@ class ProcedurePath < ApplicationRecord
where(procedure: procedure).or(where(test_procedure: procedure)).last where(procedure: procedure).or(where(test_procedure: procedure)).last
end end
def hide!(procedure) def hide!(new_procedure)
if self.procedure == procedure if procedure == new_procedure
update(procedure: nil) update(procedure: nil)
end end
if self.test_procedure == procedure if test_procedure == new_procedure
update(test_procedure: nil) update(test_procedure: nil)
end end
if procedure.nil? && test_procedure.nil? if procedure.nil? && test_procedure.nil?
destroy destroy
end end
end end
def publish!(new_procedure)
if procedure != new_procedure
if procedure&.publiee?
procedure.archive!
end
update(procedure: new_procedure)
end
end
end end

View 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

View file

@ -365,6 +365,22 @@ describe Admin::ProceduresController, type: :controller do
end end
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 context 'procedure path exists and is not owned by current administrator' do
let(:procedure_path) { procedure3.path } let(:procedure_path) { procedure3.path }
@ -605,7 +621,7 @@ describe Admin::ProceduresController, type: :controller do
end end
it { expect(procedure.hidden_at).not_to be_nil } 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 end
context "when procedure has no path" do context "when procedure has no path" do

View file

@ -164,12 +164,6 @@ describe Users::DossiersController, type: :controller do
it { expect(subject.status).to eq 200 } it { expect(subject.status).to eq 200 }
end 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 context 'when procedure path dose not exist' do
let(:path) { 'hello' } let(:path) { 'hello' }