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
def create
@procedure = Procedure.new
@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]
@procedure = Procedure.new(create_procedure_params)
unless @procedure.save
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
flash.notice = 'Procédure enregistrée'
redirect_to admin_procedures_path
end
@ -52,10 +44,6 @@ class Admin::ProceduresController < ApplicationController
flash.notice = 'Préocédure modifiée'
redirect_to admin_procedures_path
# rescue ActiveRecord::RecordNotFound
# flash.alert = 'Procédure inéxistante'
# redirect_to admin_procedures_path
end
private

View file

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

View file

@ -2,7 +2,6 @@ class Procedure < ActiveRecord::Base
has_many :types_de_piece_justificative
has_many :types_de_champs
has_many :dossiers
belongs_to :evenement_vie
validates :libelle, 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
.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])}
%h4 Description*
=f.text_area :description, class: 'form-control', placeholder: 'Description'
.form-group{class: ('has-error' if @procedure.errors.messages[:lien_demarche])}
%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'
-{libelle: 'Libellé*', description: 'Description*', lien_demarche: 'Lien démarche', organisation: 'Organisation', direction: 'Direction'}.each do |key, value|
.form-group{class: ('has-error' if @procedure.errors.messages[key])}
%h4
=value
=f.text_field key, class: 'form-control', placeholder: value
%br

View file

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

View file

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

View file

@ -1,11 +1,11 @@
%div.row#recap_dossier
%div.col-md-2.col-lg-2
.row#recap_dossier
.col-md-2.col-lg-2
%h2
='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'}
= "Dossier n°#{@dossier.id}"

View file

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

View file

@ -10,7 +10,7 @@ describe UsersController, type: :controller do
sign_in user
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 }
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
it { is_expected.to have_db_column(:email) }
it { is_expected.to have_db_column(:encrypted_password) }

View file

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