remove useless function in admin dossier controller and fix tests

This commit is contained in:
Tanguy PATTE 2015-08-20 12:20:54 +02:00
parent 92e522eb3d
commit 4f5587cb66
9 changed files with 42 additions and 36 deletions

View file

@ -11,8 +11,8 @@ class Admin::DossierController < ApplicationController
@commentaire_email = current_user.email
@formulaire = @dossier.formulaire
@liste_pieces_jointes = @dossier.types_piece_jointe
@array_id_pj_valides = PieceJointe.get_array_id_pj_valid_for_dossier @dossier.id
@dossier = @dossier.decorate
rescue ActiveRecord::RecordNotFound
redirect_start

View file

@ -3,9 +3,9 @@ class DescriptionController < ApplicationController
@dossier = Dossier.find(params[:dossier_id])
@dossier = @dossier.decorate
@array_id_pj_valides = PieceJointe.get_array_id_pj_valid_for_dossier @dossier.id
@formulaire = @dossier.formulaire
@liste_pieces_jointes = @dossier.types_piece_jointe
rescue ActiveRecord::RecordNotFound
redirect_to url_for(controller: :start, action: :error_dossier)
end

View file

@ -2,6 +2,7 @@ class PieceJointe < ActiveRecord::Base
belongs_to :dossier
belongs_to :type_piece_jointe
delegate :api_entreprise, :libelle, to: :type_piece_jointe
alias_attribute :type, :type_piece_jointe_id
mount_uploader :content, PieceJointeUploader

View file

@ -1,4 +1,4 @@
%h1#dossier_id{:class => 'text-info', :style => 'text-align:right'}
%h1#dossier_id.text-info{ :style => 'text-align:right'}
= "Dossier n°#{@dossier.id}"
%script{type: 'text/javascript'}
@ -11,7 +11,7 @@
%br
%br
.content{class: 'row'}
.content.row
#map_qp.col-lg-6.col-md-6{style: 'height:500px'}
#pieces_jointes.col-lg-6.col-md-6
%h3.text-info Liste des pièces jointes
@ -22,20 +22,20 @@
%th{class:'col-lg-6'}
='CERFA'
%td.col-lg-4.col-md-4
- if @array_id_pj_valides.include?(0)
%a{ href: "#{@dossier.get_pj(0).content}", target: '_blank' } Consulter
- if !@dossier.cerfa.empty?
%a{ href: "#{@dossier.cerfa.content}", target: '_blank' } Consulter
- else
= 'Pièce non fournie'
-@liste_pieces_jointes.each do |pj|
%tr{id: "piece_jointe_#{pj.id}"}
-@dossier.pieces_jointes.each do |piece_jointe|
%tr{id: "piece_jointe_#{piece_jointe.type}"}
%th{class:'col-lg-6'}
=pj.libelle
=piece_jointe.libelle
%td.col-lg-4.col-md-4
- if pj.api_entreprise
- if piece_jointe.api_entreprise
%a{ href: '' } Récupérer
- elsif @array_id_pj_valides.include?(pj.id)
%a{ href: "#{@dossier.get_pj(pj.id).content}", target: '_blank' } Consulter
- elsif !piece_jointe.empty?
%a{ href: "#{piece_jointe.content}", target: '_blank' } Consulter
- else
= 'Pièce non fournie'

View file

@ -41,7 +41,7 @@
%h3 Documents administratifs
%br
//TODO a refactorer DO
//TODO a refactorer
%table{class:'table', style:'width:55%; margin-left:5%'}
%tr
%th{class:'col-lg-6'}
@ -51,31 +51,31 @@
%a{style:'font-size:0.9em; padding-left:3px', id: 'lien_cerfa' ,href: "#{@formulaire.lien_demarche}", :target => '_blank'} Lien CERFA
%td{class:'col-lg-5'}
-if @array_id_pj_valides.include?(0)
-if !@dossier.cerfa.empty?
%span.btn.btn-sm.btn-file.btn-success
="Modifier"
Modifier
%input{type: 'file', name:'cerfa_pdf', id:'cerfa_pdf', accept: ".pdf"}
-else
%span.btn.btn-sm.btn-file.btn-info
="Choisir"
Choisir
%input{type: 'file', name:'cerfa_pdf', id:'cerfa_pdf', accept: ".pdf"}
-@liste_pieces_jointes.each do |pj|
- @dossier.pieces_jointes.each do |piece_jointe|
%tr
%th{class:'col-lg-6'}
=pj.libelle
%td{class:'col-lg-5'}
-if pj.api_entreprise
%span.text-success{id: "piece_jointe_#{pj.id}"} Nous l'avons récupéré pour vous.
%th.col-lg-6
= piece_jointe.libelle
%td.col-lg-5
-if piece_jointe.api_entreprise
%span.text-success{ id: "piece_jointe_#{piece_jointe.type}" } Nous l'avons récupéré pour vous.
-else
-if @array_id_pj_valides.include?(pj.id)
%span.btn.btn-sm.btn-file.btn-success
="Modifier"
%input{type: 'file', name:"piece_jointe_#{pj.id}", id:"piece_jointe_#{pj.id}", accept: ".pdf"}
-else
-if piece_jointe.empty?
%span.btn.btn-sm.btn-file.btn-info
="Choisir"
%input{type: 'file', name:"piece_jointe_#{pj.id}", id:"piece_jointe_#{pj.id}", accept: ".pdf"}
Choisir
= file_field_tag "piece_jointe_#{piece_jointe.type}", accept: '.pdf'
-else
%span.btn.btn-sm.btn-file.btn-success
Modifier
= file_field_tag "piece_jointe_#{piece_jointe.type}", accept: '.pdf'
//END
%div{style: 'text-align:right'}

View file

@ -12,11 +12,11 @@ RSpec.describe DemandesController, type: :controller do
end
describe 'POST #upated' do
context 'dans tous les cas on affiche la carte' do
it {
context 'when dossier is not linked to formulaire' do
it 'redirect to carte controller' do
post :update, :dossier_id => dossier_id, :formulaire => '1'
expect(response).to redirect_to(controller: :carte, action: :show, dossier_id: dossier_id)
}
end
end
context 'when dossier is already linked to formaulaire' do
let(:dossier) { create(:dossier) }

View file

@ -10,6 +10,7 @@ feature '_Commentaires_Flux Admin/Dossier#Show Page' do
let(:body) { 'Commentaire de test' }
before do
dossier.build_default_pieces_jointes
login_admin
visit "/admin/dossier/#{dossier_id}"
end

View file

@ -5,6 +5,7 @@ feature 'Admin/Dossier#Show Page' do
let(:dossier_id) { dossier.id }
before do
dossier.build_default_pieces_jointes
login_admin
visit "/admin/dossier/#{dossier_id}"
end
@ -61,10 +62,12 @@ feature 'Admin/Dossier#Show Page' do
context 'Devis' do
let(:id_piece_jointe){388}
let(:piece_jointe_388) {File.open('./spec/support/files/piece_jointe_388.pdf')}
let!(:piece_jointe) { create(:piece_jointe, dossier: dossier, type_piece_jointe_id: id_piece_jointe, content: piece_jointe_388) }
let(:content) {File.open('./spec/support/files/piece_jointe_388.pdf')}
before do
piece_jointe = dossier.pieces_jointes.where(type_piece_jointe_id: 388).first
piece_jointe.content = content
piece_jointe.save!
visit "/admin/dossier/#{dossier_id}"
end

View file

@ -5,6 +5,7 @@ feature 'Description#Show Page' do
let(:dossier_id) { dossier.id }
before do
dossier.build_default_pieces_jointes
visit "/dossiers/#{dossier_id}/description"
end