Revu de code

This commit is contained in:
Xavier J 2015-11-04 17:27:01 +01:00
parent 591f52f654
commit 519af34c82
12 changed files with 62 additions and 73 deletions

View file

@ -0,0 +1,17 @@
.table {
#id {
width: 5%;
}
#libelle {
width: 40%;
}
#organisation {
width: 28%;
}
#direction {
width: 22%;
}
}

View file

@ -17,14 +17,7 @@ class Admin::ProceduresController < ApplicationController
end end
def create def create
@procedure = Procedure.new @procedure = Procedure.new(create_procedure_params)
@procedure.libelle = params[:procedure][:libelle]
@procedure.description = params[:procedure][:description]
@procedure.organisation = params[:procedure][:organisation]
@procedure.direction = params[:procedure][:direction]
@procedure.lien_demarche = params[:procedure][:lien_demarche]
@procedure.use_api_carto = params[:procedure][:use_api_carto]
unless @procedure.save unless @procedure.save
flash.now.alert = @procedure.errors.full_messages.join('<br />').html_safe flash.now.alert = @procedure.errors.full_messages.join('<br />').html_safe
@ -35,7 +28,6 @@ class Admin::ProceduresController < ApplicationController
process_types_de_piece_justificative_params process_types_de_piece_justificative_params
flash.notice = 'Procédure enregistrée' flash.notice = 'Procédure enregistrée'
redirect_to admin_procedures_path redirect_to admin_procedures_path
end end
@ -52,10 +44,6 @@ class Admin::ProceduresController < ApplicationController
flash.notice = 'Préocédure modifiée' flash.notice = 'Préocédure modifiée'
redirect_to admin_procedures_path redirect_to admin_procedures_path
# rescue ActiveRecord::RecordNotFound
# flash.alert = 'Procédure inéxistante'
# redirect_to admin_procedures_path
end end
private private

View file

@ -9,7 +9,6 @@ class Administrateurs::SessionsController < Devise::SessionsController
end end
def after_sign_in_path_for(resource) def after_sign_in_path_for(resource)
# stored_location_for(resource) ||
admin_procedures_path admin_procedures_path
end end
end end

View file

@ -2,7 +2,6 @@ class Procedure < ActiveRecord::Base
has_many :types_de_piece_justificative has_many :types_de_piece_justificative
has_many :types_de_champs has_many :types_de_champs
has_many :dossiers has_many :dossiers
belongs_to :evenement_vie
validates :libelle, presence: true, allow_blank: false, allow_nil: false validates :libelle, presence: true, allow_blank: false, allow_nil: false
validates :description, presence: true, allow_blank: false, allow_nil: false validates :description, presence: true, allow_blank: false, allow_nil: false

View file

@ -1,23 +1,10 @@
%br %br
.form-group{class: ('has-error' if @procedure.errors.messages[:libelle])}
%h4 Libellé*
=f.text_field :libelle, class: 'form-control', placeholder: 'Libellé'
.form-group{class: ('has-error' if @procedure.errors.messages[:description])} -{libelle: 'Libellé*', description: 'Description*', lien_demarche: 'Lien démarche', organisation: 'Organisation', direction: 'Direction'}.each do |key, value|
%h4 Description* .form-group{class: ('has-error' if @procedure.errors.messages[key])}
=f.text_area :description, class: 'form-control', placeholder: 'Description' %h4
=value
.form-group{class: ('has-error' if @procedure.errors.messages[:lien_demarche])} =f.text_field key, class: 'form-control', placeholder: value
%h4 Lien Démarche
=f.text_field :lien_demarche, class: 'form-control', placeholder: 'Lien Démarche'
.form-group{class: ('has-error' if @procedure.errors.messages[:organisation])}
%h4 Organisation
=f.text_field :organisation, class: 'form-control', placeholder: 'Organisation'
.form-group{class: ('has-error' if @procedure.errors.messages[:direction])}
%h4 Direction
=f.text_field :direction, class: 'form-control', placeholder: 'Direction'
%br %br

View file

@ -3,11 +3,11 @@
%br %br
%br %br
%table.table %table.table
%thead.row %thead
%th.col-md-4.col-lg-1 ID %th#id ID
%th.col-md-4.col-lg-4 Libellé %th#libelle Libellé
%th.col-md-2.col-lg-4 Organisation %th#organisation Organisation
%th.col-md-2.col-lg-3 Direction %th#direction Direction
- @procedures.each do |procedure| - @procedures.each do |procedure|
%tr %tr
%td= procedure.id %td= procedure.id

View file

@ -18,15 +18,13 @@
%br %br
-unless @champs.nil? -unless @champs.nil?
.row %table.table#liste_champs
.col-lg-12.col-md-12 -@champs.each do |champ|
%table.table#liste_champs %tr
-@champs.each do |champ| %th{ style: 'width:25%' }
%tr =champ.libelle
%th.col-md-3.col-lg-3 %td
=champ.libelle =champ.value
%td
=champ.value
%div.row{style: 'text-align:right'} %div.row{style: 'text-align:right'}
-unless gestionnaire_signed_in? -unless gestionnaire_signed_in?

View file

@ -1,11 +1,11 @@
%div.row#recap_dossier .row#recap_dossier
%div.col-md-2.col-lg-2 .col-md-2.col-lg-2
%h2 %h2
='Récapitulatif' ='Récapitulatif'
%div.col-md-7.col-lg-7 .col-md-7.col-lg-7
%div.col-md-3.col-lg-3 .col-md-3.col-lg-3
%h2#dossier_id{:class => 'text-info', :style => 'text-align:right; margin-bottom:15px'} %h2#dossier_id{:class => 'text-info', :style => 'text-align:right; margin-bottom:15px'}
= "Dossier n°#{@dossier.id}" = "Dossier n°#{@dossier.id}"

View file

@ -4,7 +4,6 @@ describe Admin::ProceduresController, type: :controller do
let(:admin) { create(:administrateur) } let(:admin) { create(:administrateur) }
let(:bad_procedure_id) { 100000 } let(:bad_procedure_id) { 100000 }
let(:procedure_id) { 1 }
let(:libelle) { 'Procédure de test' } let(:libelle) { 'Procédure de test' }
let(:description) { 'Description de test' } let(:description) { 'Description de test' }
@ -78,6 +77,7 @@ describe Admin::ProceduresController, type: :controller do
describe 'GET #show' do describe 'GET #show' do
let(:procedure) { create(:procedure, :with_type_de_champs, :with_two_type_de_piece_justificative) } let(:procedure) { create(:procedure, :with_type_de_champs, :with_two_type_de_piece_justificative) }
let(:procedure_id) { procedure.id }
subject { get :show, id: procedure_id } subject { get :show, id: procedure_id }
@ -104,7 +104,7 @@ describe Admin::ProceduresController, type: :controller do
end end
describe 'POST #create' do describe 'POST #create' do
context 'when all attributs are informed' do context 'when all attributs are filled' do
describe 'new procedure in database' do describe 'new procedure in database' do
subject { post :create, procedure: procedure_params } subject { post :create, procedure: procedure_params }
@ -159,12 +159,12 @@ describe Admin::ProceduresController, type: :controller do
subject { Procedure.last } subject { Procedure.last }
context 'when no type de champs is informed' do context 'when no type de champs is filled' do
let(:types_de_champs_params) { {} } let(:types_de_champs_params) { {} }
it { expect(subject.types_de_champs.size).to eq(0) } it { expect(subject.types_de_champs.size).to eq(0) }
end end
context 'when two types de champs are informed' do context 'when two types de champs are filled' do
it { expect(subject.types_de_champs.size).to eq(2) } it { expect(subject.types_de_champs.size).to eq(2) }
describe ' check types de champs attributs present into database' do describe ' check types de champs attributs present into database' do
@ -196,12 +196,12 @@ describe Admin::ProceduresController, type: :controller do
subject { Procedure.last } subject { Procedure.last }
context 'when no type de piece justificative is informed' do context 'when no type de piece justificative is filled' do
let(:types_de_piece_justificative_params) { {} } let(:types_de_piece_justificative_params) { {} }
it { expect(subject.types_de_piece_justificative.size).to eq(0) } it { expect(subject.types_de_piece_justificative.size).to eq(0) }
end end
context 'when two types de piece justificative are informed' do context 'when two types de piece justificative are filled' do
it { expect(subject.types_de_piece_justificative.size).to eq(2) } it { expect(subject.types_de_piece_justificative.size).to eq(2) }
describe ' check types de piece justificative attributs present into database' do describe ' check types de piece justificative attributs present into database' do
@ -277,12 +277,12 @@ describe Admin::ProceduresController, type: :controller do
describe 'type_de_champs processing' do describe 'type_de_champs processing' do
subject { procedure } subject { procedure }
context 'when no type de champs is informed' do context 'when no type de champs is filled' do
let(:types_de_champs_params) { {} } let(:types_de_champs_params) { {} }
it { expect(subject.types_de_champs.size).to eq(1) } it { expect(subject.types_de_champs.size).to eq(1) }
end end
context 'when two types de champs are informed' do context 'when two types de champs are filled' do
it { expect(subject.types_de_champs.size).to eq(3) } it { expect(subject.types_de_champs.size).to eq(3) }
describe ' check types de champs attributs added into database' do describe ' check types de champs attributs added into database' do
@ -301,12 +301,13 @@ describe Admin::ProceduresController, type: :controller do
end end
context 'when one of two types de champs have not a libelle' do context 'when one of two types de champs have not a libelle' do
let(:procedure) { create(:procedure) }
let(:types_de_champs_params) { types_de_champs_params_errors } let(:types_de_champs_params) { types_de_champs_params_errors }
it { expect(subject.types_de_champs.size).to eq(2) } it { expect(subject.types_de_champs.size).to eq(1) }
end end
context 'when one types de champs is edit' do context 'when user edit the filed' do
let(:types_de_champs_params) { let(:types_de_champs_params) {
{'0' => {'0' =>
{libelle: 'Champs de test editée', {libelle: 'Champs de test editée',
@ -326,7 +327,6 @@ describe Admin::ProceduresController, type: :controller do
it { expect(subject.type_champs).to eq(types_de_champs_params['0'][:type]) } it { expect(subject.type_champs).to eq(types_de_champs_params['0'][:type]) }
it { expect(subject.description).to eq(types_de_champs_params['0'][:description]) } it { expect(subject.description).to eq(types_de_champs_params['0'][:description]) }
it { expect(subject.order_place).to eq(types_de_champs_params['0'][:order_place]) } it { expect(subject.order_place).to eq(types_de_champs_params['0'][:order_place]) }
end end
end end
@ -371,22 +371,23 @@ describe Admin::ProceduresController, type: :controller do
describe 'type_de_piece_justificative processing' do describe 'type_de_piece_justificative processing' do
subject { procedure } subject { procedure }
context 'when no type de piece justificative is informed' do context 'when no type de piece justificative is filled' do
let(:types_de_piece_justificative_params) { {} } let(:types_de_piece_justificative_params) { {} }
it { expect(subject.types_de_piece_justificative.size).to eq(2) } it { expect(subject.types_de_piece_justificative.size).to eq(2) }
end end
context 'when two types de piece justificative are informed' do context 'when two types de piece justificative are filled' do
it { expect(subject.types_de_piece_justificative.size).to eq(4) } let(:procedure) { create(:procedure) }
it { expect(subject.types_de_piece_justificative.size).to eq(2) }
describe ' check types de piece justificative attributs added into database' do describe ' check types de piece justificative attributs added into database' do
subject { procedure.types_de_piece_justificative } subject { procedure.types_de_piece_justificative }
it { expect(subject[2].libelle).to eq(types_de_piece_justificative_params['0'][:libelle]) } it { expect(subject[0].libelle).to eq(types_de_piece_justificative_params['0'][:libelle]) }
it { expect(subject[2].description).to eq(types_de_piece_justificative_params['0'][:description]) } it { expect(subject[0].description).to eq(types_de_piece_justificative_params['0'][:description]) }
it { expect(subject[3].libelle).to eq(types_de_piece_justificative_params['1'][:libelle]) } it { expect(subject[1].libelle).to eq(types_de_piece_justificative_params['1'][:libelle]) }
it { expect(subject[3].description).to eq(types_de_piece_justificative_params['1'][:description]) } it { expect(subject[1].description).to eq(types_de_piece_justificative_params['1'][:description]) }
end end
end end

View file

@ -10,7 +10,7 @@ describe UsersController, type: :controller do
sign_in user sign_in user
end end
context 'when no dossier_id is informed' do context 'when no dossier_id is filled' do
it { expect{ subject.current_user_dossier }.to raise_error } it { expect{ subject.current_user_dossier }.to raise_error }
end end

View file

@ -1,6 +1,6 @@
require 'rails_helper' require 'spec_helper'
RSpec.describe Administrateur, type: :model do describe Administrateur, type: :model do
describe 'database column' do describe 'database column' do
it { is_expected.to have_db_column(:email) } it { is_expected.to have_db_column(:email) }
it { is_expected.to have_db_column(:encrypted_password) } it { is_expected.to have_db_column(:encrypted_password) }

View file

@ -121,7 +121,7 @@ describe Dossier do
subject.update_attributes(description: 'plop') subject.update_attributes(description: 'plop')
end end
it 'does not create default champss' do it 'does not create default champs' do
expect(subject).not_to receive(:build_default_champs) expect(subject).not_to receive(:build_default_champs)
subject.update_attributes(description: 'plop') subject.update_attributes(description: 'plop')
end end