Revu de code 0

This commit is contained in:
Xavier J 2015-08-11 15:22:07 +02:00
parent f7dfcfa5a5
commit d09ac6043c
16 changed files with 886 additions and 404 deletions

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
class CommentairesController < ApplicationController class CommentairesController < ApplicationController
def create def create
@commentaire = Commentaire.create @commentaire = Commentaire.new
@commentaire.email = params['email_commentaire'] @commentaire.email = params['email_commentaire']
@commentaire.body = params['texte_commentaire'] @commentaire.body = params['texte_commentaire']
@commentaire.dossier = Dossier.find(params['dossier_id']) @commentaire.dossier = Dossier.find(params['dossier_id'])
@ -12,6 +12,5 @@ class CommentairesController < ApplicationController
else else
redirect_to url_for({controller: 'admin/dossier', action: :show, :dossier_id => params['dossier_id']}) redirect_to url_for({controller: 'admin/dossier', action: :show, :dossier_id => params['dossier_id']})
end end
end end
end end

View file

@ -1,14 +1,13 @@
class DemandesController < ApplicationController class DemandesController < ApplicationController
def show def show
@dossier = Dossier.find(params[:dossier_id]) @dossier = Dossier.find(params[:dossier_id])
@evenement_vie = EvenementVie.where(use_admi_facile: true) @evenement_vie = EvenementVie.for_admi_facile
end end
def choice def choice
@dossier = Dossier.find(params[:dossier_id]) @dossier = Dossier.find(params[:dossier_id])
@dossier.ref_formulaire = params[:ref_formulaire] @dossier.update_attributes(ref_formulaire: params[:ref_formulaire])
@dossier.save
redirect_to url_for({controller: :carte, action: :show, :dossier_id => params[:dossier_id]}) redirect_to url_for( { controller: :carte, action: :show, :dossier_id => params[:dossier_id] } )
end end
end end

View file

@ -63,4 +63,18 @@ class DossiersController < ApplicationController
flash.now.alert = 'Les conditions sont obligatoires.' flash.now.alert = 'Les conditions sont obligatoires.'
render 'show' render 'show'
end end
private
def dossier_id_is_present?
end
def siret
params[:siret]
end
def siren
siret[0..8]
end
end end

View file

@ -3,6 +3,7 @@ class RecapitulatifController < ApplicationController
@dossier = Dossier.find(params[:dossier_id]) @dossier = Dossier.find(params[:dossier_id])
@dossier = @dossier.decorate @dossier = @dossier.decorate
#mettre dans le modèle
@commentaires = @dossier.commentaires.order(created_at: :desc) @commentaires = @dossier.commentaires.order(created_at: :desc)
@commentaires = @commentaires.all.decorate @commentaires = @commentaires.all.decorate
@commentaire_email = @dossier.mail_contact @commentaire_email = @dossier.mail_contact

View file

@ -2,14 +2,17 @@ class StartController < ApplicationController
def index def index
end end
def error_siret def error_siret
flash.now.alert = 'Ce SIRET n\'est pas valide' flash.now.alert = 'Ce SIRET n\'est pas valide'
render 'index' render 'index'
end end
def error_login def error_login
flash.now.alert = 'Ce compte n\'existe pas' flash.now.alert = 'Ce compte n\'existe pas'
render 'index' render 'index'
end end
def error_dossier def error_dossier
flash.now.alert = 'Ce dossier n\'existe pas' flash.now.alert = 'Ce dossier n\'existe pas'
render 'index' render 'index'

View file

@ -6,5 +6,4 @@ class CommentaireDecorator < Draper::Decorator
rescue rescue
'dd/mm/YYYY - HH:MM' 'dd/mm/YYYY - HH:MM'
end end
end end

View file

@ -6,8 +6,4 @@ class DossierDecorator < Draper::Decorator
rescue rescue
'dd/mm/YYYY' 'dd/mm/YYYY'
end end
def date_en
date_previsionnelle.to_date.strftime("%Y-%m-%d")
end
end end

View file

@ -5,10 +5,6 @@ class EntrepriseDecorator < Draper::Decorator
raison_sociale.nil? ? nom + '' + prenom : raison_sociale raison_sociale.nil? ? nom + '' + prenom : raison_sociale
end end
def siege_social_true_false
siege_social? ? 'Cet établissement est le siège social' : 'Cet établissement n\'est pas le siège social'
end
def code_effectif_entreprise_libelle def code_effectif_entreprise_libelle
case code_effectif_entreprise.to_s case code_effectif_entreprise.to_s

View file

@ -1,2 +1,6 @@
class EvenementVie < ActiveRecord::Base class EvenementVie < ActiveRecord::Base
#TODO a tester
def self.for_admi_facile
where(use_admi_facile: true)
end
end end

View file

@ -13,8 +13,6 @@
.content{class: 'row'} .content{class: 'row'}
#map_qp{style: 'height:500px', class: 'col-lg-6 col-md-6'} #map_qp{style: 'height:500px', class: 'col-lg-6 col-md-6'}
%object{ data: "#{@dossier_pdf.ref_dossier_pdf.url}", type: "application/pdf", title:"Dossier PDF", class: 'col-lg-6 col-md-6', style: 'height:500px'}
= render partial: '/carte/carte_sources_CSS' = render partial: '/carte/carte_sources_CSS'
= render partial: '/carte/carte_sources_JS_backend' = render partial: '/carte/carte_sources_JS_backend'
%br %br

View file

@ -1,6 +1,6 @@
%div#sources_CSS_api_carto %div#sources_CSS_api_carto
%link{:href => "http://leaflet.github.io/Leaflet.draw/leaflet.draw.css", :rel => "stylesheet", :type => "text/css"}/ %link{:href => "http://leaflet.github.io/Leaflet.draw/leaflet.draw.css", :rel => "stylesheet", :type => "text/css"}
%link{:href => "http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css", :rel => "stylesheet", :type => "text/css"}/ %link{:href => "http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css", :rel => "stylesheet", :type => "text/css"}
%link{:href => "/assets/api_carto/lib/leaflet.photon.css", :rel => "stylesheet", :type => "text/css"}/ %link{:href => "/assets/api_carto/lib/leaflet.photon.css", :rel => "stylesheet", :type => "text/css"}
%link{:href => "http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css", :rel => "stylesheet"}/ %link{:href => "http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css", :rel => "stylesheet"}
%link{:href => "https://cdn.rawgit.com/CliffCloud/Leaflet.EasyButton/dd04bbf160aa33c44aa63e8a744b3632c162c340/src/easy-button.css", :rel => "stylesheet"}/ %link{:href => "https://cdn.rawgit.com/CliffCloud/Leaflet.EasyButton/dd04bbf160aa33c44aa63e8a744b3632c162c340/src/easy-button.css", :rel => "stylesheet"}

View file

@ -16,7 +16,7 @@
%h4{style: 'margin-bottom:2%'} Nouveau %h4{style: 'margin-bottom:2%'} Nouveau
= form_tag(url_for({controller: '/commentaires', action: :create}), class: 'form-inline', method: 'POST') do = form_tag(url_for({controller: '/commentaires', action: :create}), class: 'form-inline', method: 'POST') do
%input.form-control{:type => 'text', style: 'width: 30%; margin-bottom:2%', :id => 'email_commentaire', :name => 'email_commentaire', :value => @commentaire_email} %input.form-control{:type => 'text', style: 'width: 30%; margin-bottom:2%', :id => 'email_commentaire', :name => 'email_commentaire', :value => @commentaire_email}
%textarea.form-control{:id => 'texte_commentaire', :name => 'texte_commentaire', style: 'width: 100%; margin-bottom:2%', rows: '5'} %textarea.form-control{:id => 'texte_commentaire', :name => 'texte_commentaire', style: 'width: 100%; margin-bottom:2%', rows: '5', maxlength: '255'}
%br %br
%input.form-control.btn.btn-success{:type => 'submit', :value => 'Poster', style: 'float:right'} %input.form-control.btn.btn-success{:type => 'submit', :value => 'Poster', style: 'float:right'}
%br %br

View file

@ -8,12 +8,12 @@ RSpec.describe CarteController, type: :controller do
describe "GET #show" do describe "GET #show" do
it "returns http success" do it "returns http success" do
get :show, :dossier_id => dossier_id get :show, dossier_id: dossier_id
expect(response).to have_http_status(:success) expect(response).to have_http_status(:success)
end end
it 'redirection vers start si mauvais dossier ID' do it 'redirection vers start si mauvais dossier ID' do
get :show, :dossier_id => bad_dossier_id get :show, dossier_id: bad_dossier_id
expect(response).to redirect_to('/start/error_dossier') expect(response).to redirect_to('/start/error_dossier')
end end
end end
@ -29,28 +29,27 @@ RSpec.describe CarteController, type: :controller do
context 'En train de modifier la localisation' do context 'En train de modifier la localisation' do
before do before do
post :save_ref_api_carto, :dossier_id => dossier_id, :ref_dossier => ref_dossier, :back_url => 'recapitulatif' post :save_ref_api_carto, :dossier_id => dossier_id, :ref_dossier => ref_dossier, :back_url => 'recapitulatif'
@last_commentaire_id = ActiveRecord::Base.connection.execute("SELECT currval('commentaires_id_seq')").getvalue(0,0)
end end
context 'Enregistrement d\'un commentaire informant la modification' do context 'Enregistrement d\'un commentaire informant la modification' do
subject{Commentaire.find(@last_commentaire_id)} subject { Commentaire.last }
it 'champs email' do it 'champs email' do
expect(subject.email).to eq('Modification localisation') expect(subject.email).to eq('Modification localisation')
end
it 'champs body' do
expect(subject.body).to eq('La localisation de la demande a été modifiée. Merci de le prendre en compte.')
end
it 'champs dossier' do
expect(subject.dossier.id).to eq(dossier_id)
end
end end
it 'Redirection vers la page récapitulatif' do it 'champs body' do
expect(response).to redirect_to("/dossiers/#{dossier_id}/recapitulatif") expect(subject.body).to eq('La localisation de la demande a été modifiée. Merci de le prendre en compte.')
end end
it 'champs dossier' do
expect(subject.dossier.id).to eq(dossier_id)
end
end
it 'Redirection vers la page récapitulatif' do
expect(response).to redirect_to("/dossiers/#{dossier_id}/recapitulatif")
end
end end
end end
@ -61,6 +60,8 @@ RSpec.describe CarteController, type: :controller do
get :get_position, :dossier_id => dossier_id get :get_position, :dossier_id => dossier_id
end end
#TODO Test carto geocodeur ne revoit rien / nil
context 'retour d\'un fichier JSON avec 3 attributs' do context 'retour d\'un fichier JSON avec 3 attributs' do
subject {JSON.parse(response.body)} subject {JSON.parse(response.body)}

View file

@ -1,6 +1,6 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe CommentairesController, type: :controller do describe CommentairesController, type: :controller do
let (:dossier_id){10000} let (:dossier_id){10000}
let (:email_commentaire){'test@test.com'} let (:email_commentaire){'test@test.com'}
let (:texte_commentaire){'Commentaire de test'} let (:texte_commentaire){'Commentaire de test'}

View file

@ -24,13 +24,13 @@ RSpec.describe DossiersController, type: :controller do
describe 'POST #create' do describe 'POST #create' do
before do before do
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{bad_siret}?token=#{SIADETOKEN}"). stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{bad_siret}?token=#{SIADETOKEN}").
to_return(:status => 404, :body => 'fake body', :headers => {}) to_return(:status => 404, :body => 'fake body')
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret}?token=#{SIADETOKEN}"). stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret}?token=#{SIADETOKEN}").
to_return(:status => 200, :body => File.read('spec/support/files/etablissement.json'), :headers => {}) to_return(:status => 200, :body => File.read('spec/support/files/etablissement.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}"). stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}").
to_return(:status => 200, :body => File.read('spec/support/files/entreprise.json'), :headers => {}) to_return(:status => 200, :body => File.read('spec/support/files/entreprise.json'))
end end
context 'Le SIRET est correct' do context 'Le SIRET est correct' do