Merge branch 'dev'

This commit is contained in:
gregoirenovel 2017-08-29 16:56:56 +02:00
commit 12dcbf85a7
26 changed files with 74 additions and 49 deletions

View file

@ -110,7 +110,7 @@ Layout/IndentationConsistency:
Enabled: false Enabled: false
Layout/IndentationWidth: Layout/IndentationWidth:
Enabled: false Enabled: true
Layout/InitialIndentation: Layout/InitialIndentation:
Enabled: false Enabled: false
@ -170,7 +170,7 @@ Layout/SpaceAroundKeyword:
Enabled: false Enabled: false
Layout/SpaceAroundOperators: Layout/SpaceAroundOperators:
Enabled: false Enabled: true
Layout/SpaceBeforeBlockBraces: Layout/SpaceBeforeBlockBraces:
Enabled: false Enabled: false

View file

@ -12,7 +12,8 @@ class Admin::GestionnairesController < AdminController
end end
def create def create
@gestionnaire = Gestionnaire.find_by_email(params[:gestionnaire][:email]) email = params[:gestionnaire][:email].downcase
@gestionnaire = Gestionnaire.find_by_email(email)
procedure_id = params[:procedure_id] procedure_id = params[:procedure_id]
if @gestionnaire.nil? if @gestionnaire.nil?

View file

@ -5,7 +5,7 @@ class Admin::PrevisualisationsController < AdminController
@procedure @procedure
@dossier = Dossier.new(id: 0, procedure: @procedure) @dossier = Dossier.new(id: 0, procedure: @procedure)
PrevisualisationService.destroy_all_champs @dossier PrevisualisationService.delete_all_champs @dossier
@dossier.build_default_champs @dossier.build_default_champs
@champs = @dossier.ordered_champs @champs = @dossier.ordered_champs

View file

@ -92,6 +92,10 @@ class Dossier < ActiveRecord::Base
unreaded_notifications.order("created_at ASC").first unreaded_notifications.order("created_at ASC").first
end 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) def retrieve_last_piece_justificative_by_type(type)
pieces_justificatives.where(type_de_piece_justificative_id: type).last pieces_justificatives.where(type_de_piece_justificative_id: type).last
end end
@ -101,12 +105,12 @@ class Dossier < ActiveRecord::Base
end end
def build_default_champs def build_default_champs
procedure.types_de_champ.each do |type_de_champ| procedure.types_de_champ.all.each do |type_de_champ|
ChampPublic.create(type_de_champ_id: type_de_champ.id, dossier_id: id) ChampPublic.create(type_de_champ: type_de_champ, dossier: self)
end end
procedure.types_de_champ_private.each do |type_de_champ| procedure.types_de_champ_private.all.each do |type_de_champ|
ChampPrivate.create(type_de_champ_id: type_de_champ.id, dossier_id: id) ChampPrivate.create(type_de_champ: type_de_champ, dossier: self)
end end
end end
@ -117,11 +121,15 @@ class Dossier < ActiveRecord::Base
end end
def ordered_champs def ordered_champs
champs.includes(:type_de_champ).order('types_de_champ.order_place') # TODO: use the line below when the procedure preview does not leak champ with dossier_id == 0
# champs.joins(:type_de_champ).order('types_de_champ.order_place')
champs.joins(', types_de_champ').where("champs.type_de_champ_id = types_de_champ.id AND types_de_champ.procedure_id = #{procedure.id}").order('order_place')
end end
def ordered_champs_private def ordered_champs_private
champs_private.includes(:type_de_champ).order('types_de_champ.order_place') # TODO: use the line below when the procedure preview does not leak champ with dossier_id == 0
# champs_private.includes(:type_de_champ).order('types_de_champ.order_place')
champs_private.joins(', types_de_champ').where("champs.type_de_champ_id = types_de_champ.id AND types_de_champ.procedure_id = #{procedure.id}").order('order_place')
end end
def ordered_pieces_justificatives def ordered_pieces_justificatives

View file

@ -1,5 +1,5 @@
class PrevisualisationService class PrevisualisationService
def self.destroy_all_champs dossier def self.delete_all_champs dossier
Champ.where(dossier_id: dossier.id, type_de_champ_id: dossier.procedure.types_de_champ.ids).destroy_all Champ.where(dossier_id: dossier.id, type_de_champ_id: dossier.procedure.types_de_champ.ids).delete_all
end end
end end

View file

@ -35,7 +35,7 @@
- if tpj.api_entreprise - if tpj.api_entreprise
%span.text-success{ id: "piece_justificative_#{tpj.id}" } Nous l'avons récupéré pour vous. %span.text-success{ id: "piece_justificative_#{tpj.id}" } Nous l'avons récupéré pour vous.
- else - 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 = file_field_tag "piece_justificative_#{tpj.id}", accept: PieceJustificative.accept_format, :max_file_size => 6.megabytes
- else - else
%span.btn.btn-sm.btn-file.btn-success %span.btn.btn-sm.btn-file.btn-success

View file

@ -119,6 +119,22 @@ describe Admin::GestionnairesController, type: :controller do
it { expect(gestionnaire.administrateurs.size).to eq 2 } it { expect(gestionnaire.administrateurs.size).to eq 2 }
end end
context 'when an other admin will add the same email with some uppercase in it' do
let(:email) { 'Test@Plop.com' }
let(:gestionnaire) { Gestionnaire.find_by_email(email.downcase) }
before do
create :gestionnaire, email: email, administrateurs: [admin]
sign_out admin
sign_in admin_2
subject
end
it { expect(admin_2.gestionnaires).to include gestionnaire }
end
context 'Email notification' do context 'Email notification' do
it 'Notification email is sent when accompagnateur is create' do it 'Notification email is sent when accompagnateur is create' do
expect(GestionnaireMailer).to receive(:new_gestionnaire).and_return(GestionnaireMailer) expect(GestionnaireMailer).to receive(:new_gestionnaire).and_return(GestionnaireMailer)

View file

@ -1,8 +1,8 @@
require 'spec_helper' require 'spec_helper'
describe PrevisualisationService do describe PrevisualisationService do
describe '.destroy_all_champs' do describe '.delete_all_champs' do
subject { described_class.destroy_all_champs dossier } subject { described_class.delete_all_champs dossier }
let(:procedure_1) { create :procedure, :with_type_de_champ } let(:procedure_1) { create :procedure, :with_type_de_champ }
let(:procedure_2) { 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(TypeDeChamp.all.size).to eq 2 }
it { expect(Champ.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 } let(:dossier) { dossier_1 }
before do before do