commit
0118c43d95
5 changed files with 15 additions and 11 deletions
|
@ -5,7 +5,7 @@ class Admin::PrevisualisationsController < AdminController
|
|||
@procedure
|
||||
@dossier = Dossier.new(id: 0, procedure: @procedure)
|
||||
|
||||
PrevisualisationService.destroy_all_champs @dossier
|
||||
PrevisualisationService.delete_all_champs @dossier
|
||||
@dossier.build_default_champs
|
||||
|
||||
@champs = @dossier.ordered_champs
|
||||
|
|
|
@ -92,6 +92,10 @@ class Dossier < ActiveRecord::Base
|
|||
unreaded_notifications.order("created_at ASC").first
|
||||
end
|
||||
|
||||
def was_piece_justificative_uploaded_for_type_id?(type_id)
|
||||
pieces_justificatives.where(type_de_piece_justificative_id: type_id).count > 0
|
||||
end
|
||||
|
||||
def retrieve_last_piece_justificative_by_type(type)
|
||||
pieces_justificatives.where(type_de_piece_justificative_id: type).last
|
||||
end
|
||||
|
@ -101,12 +105,12 @@ class Dossier < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def build_default_champs
|
||||
procedure.types_de_champ.each do |type_de_champ|
|
||||
ChampPublic.create(type_de_champ_id: type_de_champ.id, dossier_id: id)
|
||||
procedure.types_de_champ.all.each do |type_de_champ|
|
||||
ChampPublic.create(type_de_champ: type_de_champ, dossier: self)
|
||||
end
|
||||
|
||||
procedure.types_de_champ_private.each do |type_de_champ|
|
||||
ChampPrivate.create(type_de_champ_id: type_de_champ.id, dossier_id: id)
|
||||
procedure.types_de_champ_private.all.each do |type_de_champ|
|
||||
ChampPrivate.create(type_de_champ: type_de_champ, dossier: self)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class PrevisualisationService
|
||||
def self.destroy_all_champs dossier
|
||||
Champ.where(dossier_id: dossier.id, type_de_champ_id: dossier.procedure.types_de_champ.ids).destroy_all
|
||||
def self.delete_all_champs dossier
|
||||
Champ.where(dossier_id: dossier.id, type_de_champ_id: dossier.procedure.types_de_champ.ids).delete_all
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
- if tpj.api_entreprise
|
||||
%span.text-success{ id: "piece_justificative_#{tpj.id}" } Nous l'avons récupéré pour vous.
|
||||
- else
|
||||
- if dossier.retrieve_last_piece_justificative_by_type(tpj.id).nil?
|
||||
- if !dossier.was_piece_justificative_uploaded_for_type_id?(tpj.id)
|
||||
= file_field_tag "piece_justificative_#{tpj.id}", accept: PieceJustificative.accept_format, :max_file_size => 6.megabytes
|
||||
- else
|
||||
%span.btn.btn-sm.btn-file.btn-success
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe PrevisualisationService do
|
||||
describe '.destroy_all_champs' do
|
||||
subject { described_class.destroy_all_champs dossier }
|
||||
describe '.delete_all_champs' do
|
||||
subject { described_class.delete_all_champs dossier }
|
||||
|
||||
let(:procedure_1) { create :procedure, :with_type_de_champ }
|
||||
let(:procedure_2) { create :procedure, :with_type_de_champ }
|
||||
|
@ -14,7 +14,7 @@ describe PrevisualisationService do
|
|||
it { expect(TypeDeChamp.all.size).to eq 2 }
|
||||
it { expect(Champ.all.size).to eq 2 }
|
||||
|
||||
context 'when function destroy_all_champs is call' do
|
||||
context 'when function delete_all_champs is call' do
|
||||
let(:dossier) { dossier_1 }
|
||||
|
||||
before do
|
||||
|
|
Loading…
Reference in a new issue