Add procedure edition functionality
This commit is contained in:
parent
49627fccad
commit
270d28f6da
12 changed files with 314 additions and 2 deletions
60
app/controllers/admin/procedures_controller.rb
Normal file
60
app/controllers/admin/procedures_controller.rb
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
class Admin::ProceduresController < ApplicationController
|
||||||
|
before_action :authenticate_administrateur!
|
||||||
|
|
||||||
|
def index
|
||||||
|
@procedures = Procedure.all
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
@procedure = Procedure.find(params[:id])
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
flash.alert = 'Procédure inéxistante'
|
||||||
|
redirect_to admin_procedures_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@procedure ||= Procedure.new
|
||||||
|
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]
|
||||||
|
|
||||||
|
unless @procedure.save
|
||||||
|
flash.now.alert = @procedure.errors.full_messages.join('<br />').html_safe
|
||||||
|
return render 'new'
|
||||||
|
end
|
||||||
|
|
||||||
|
flash.notice = 'Procédure enregistrée'
|
||||||
|
|
||||||
|
redirect_to admin_procedures_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@procedure = Procedure.find(params[:id])
|
||||||
|
|
||||||
|
unless @procedure.update_attributes(create_params)
|
||||||
|
flash.now.alert = @procedure.errors.full_messages.join('<br />').html_safe
|
||||||
|
return render 'show'
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
def create_params
|
||||||
|
params.require(:procedure).permit(:libelle, :description, :organisation, :direction, :lien_demarche, :use_api_carto)
|
||||||
|
end
|
||||||
|
end
|
|
@ -2,5 +2,6 @@ class AdminController < ApplicationController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
redirect_to(controller: '/administrateurs/sessions', action: :new) unless administrateur_signed_in?
|
redirect_to(controller: '/administrateurs/sessions', action: :new) unless administrateur_signed_in?
|
||||||
|
redirect_to (admin_procedures_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,6 +10,6 @@ class Administrateurs::SessionsController < Devise::SessionsController
|
||||||
|
|
||||||
def after_sign_in_path_for(resource)
|
def after_sign_in_path_for(resource)
|
||||||
# stored_location_for(resource) ||
|
# stored_location_for(resource) ||
|
||||||
admin_path
|
admin_procedures_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
%p Coucou
|
|
36
app/views/admin/procedures/_informations.html.haml
Normal file
36
app/views/admin/procedures/_informations.html.haml
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
%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'
|
||||||
|
|
||||||
|
%br
|
||||||
|
|
||||||
|
%label{ style:'font-weight:normal' }
|
||||||
|
=f.check_box :use_api_carto
|
||||||
|
Utilisation de l'API Carto
|
||||||
|
|
||||||
|
%br
|
||||||
|
%br
|
||||||
|
%h4
|
||||||
|
Liste des champs à remplir pour un dossier
|
||||||
|
|
||||||
|
%br
|
||||||
|
%br
|
||||||
|
%h4
|
||||||
|
Liste des pièces justificatives à fournir pour un dossier
|
17
app/views/admin/procedures/index.html.haml
Normal file
17
app/views/admin/procedures/index.html.haml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
= link_to("Nouvelle procédure", "/admin/procedures/new", class: 'btn btn-success', style: 'float:right')
|
||||||
|
%h2 Gestion des procédures
|
||||||
|
%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
|
||||||
|
- @procedures.each do |procedure|
|
||||||
|
%tr
|
||||||
|
%td= procedure.id
|
||||||
|
%td
|
||||||
|
= link_to(procedure.libelle, "/admin/procedures/#{procedure.id}")
|
||||||
|
%td= procedure.organisation
|
||||||
|
%td= procedure.direction
|
7
app/views/admin/procedures/new.html.haml
Normal file
7
app/views/admin/procedures/new.html.haml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
%h2 Nouvelle procédure
|
||||||
|
|
||||||
|
#procedure_new.section.section-label
|
||||||
|
= form_for @procedure, url: {controller: 'admin/procedures', action: :create} do |f|
|
||||||
|
=render partial: 'informations', locals: {f: f}
|
||||||
|
%br
|
||||||
|
=f.submit 'Valider', class: 'btn btn-info', style: 'float:right'
|
8
app/views/admin/procedures/show.html.haml
Normal file
8
app/views/admin/procedures/show.html.haml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
%h2.text-info
|
||||||
|
=@procedure.libelle
|
||||||
|
|
||||||
|
#procedure_new.section.section-label
|
||||||
|
= form_for @procedure, url: {controller: 'admin/procedures', action: :update} do |f|
|
||||||
|
=render partial: 'informations', locals: {f: f}
|
||||||
|
%br
|
||||||
|
=f.submit 'Editer', class: 'btn btn-success', style: 'float:right'
|
12
config/locales/models/procedure/fr.yml
Normal file
12
config/locales/models/procedure/fr.yml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
fr:
|
||||||
|
activerecord:
|
||||||
|
errors:
|
||||||
|
models:
|
||||||
|
procedure:
|
||||||
|
attributes:
|
||||||
|
libelle:
|
||||||
|
blank: Attribut manquant
|
||||||
|
description:
|
||||||
|
blank: Attribut manquant
|
||||||
|
lien_demarche:
|
||||||
|
blank: Attribut manquant
|
|
@ -43,12 +43,16 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
namespace :admin do
|
namespace :admin do
|
||||||
get 'sign_in' => '/administrateurs/sessions#new'
|
get 'sign_in' => '/administrateurs/sessions#new'
|
||||||
|
resources :procedures do
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
get 'backoffice' => 'backoffice#index'
|
get 'backoffice' => 'backoffice#index'
|
||||||
|
|
||||||
namespace :backoffice do
|
namespace :backoffice do
|
||||||
get 'sign_in' => '/gestionnaires/sessions#new'
|
get 'sign_in' => '/gestionnaires/sessions#new'
|
||||||
|
|
||||||
resources :dossiers do
|
resources :dossiers do
|
||||||
post 'confirme' => 'dossiers#confirme'
|
post 'confirme' => 'dossiers#confirme'
|
||||||
post 'process' => 'dossiers#process_end'
|
post 'process' => 'dossiers#process_end'
|
||||||
|
|
161
spec/controllers/admin/procedures_controller_spec.rb
Normal file
161
spec/controllers/admin/procedures_controller_spec.rb
Normal file
|
@ -0,0 +1,161 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Admin::ProceduresController, type: :controller do
|
||||||
|
let(:admin) { create(:administrateur) }
|
||||||
|
|
||||||
|
let(:bad_procedure_id) { 100000 }
|
||||||
|
|
||||||
|
let(:libelle) { 'Procédure de test' }
|
||||||
|
let(:description) { 'Description de test' }
|
||||||
|
let(:organisation) { 'Organisation de test' }
|
||||||
|
let(:direction) { 'Direction de test' }
|
||||||
|
let(:lien_demarche) { 'http://localhost.com' }
|
||||||
|
let(:use_api_carto) { '1' }
|
||||||
|
|
||||||
|
let(:procedure_params) {
|
||||||
|
{
|
||||||
|
libelle: libelle,
|
||||||
|
description: description,
|
||||||
|
organisation: organisation,
|
||||||
|
direction: direction,
|
||||||
|
lien_demarche: lien_demarche,
|
||||||
|
use_api_carto: use_api_carto
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
before do
|
||||||
|
sign_in admin
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'GET #show' do
|
||||||
|
let(:procedure) { create(:procedure) }
|
||||||
|
|
||||||
|
subject { get :show, id: procedure.id }
|
||||||
|
|
||||||
|
context 'when user is not connected' do
|
||||||
|
before do
|
||||||
|
sign_out admin
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(subject).to redirect_to new_administrateur_session_path }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when user is connected' do
|
||||||
|
context 'when procedure exist' do
|
||||||
|
it { expect(subject).to have_http_status(:success) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when procedure doesn't exist" do
|
||||||
|
before do
|
||||||
|
procedure.id = bad_procedure_id
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(subject).to redirect_to admin_procedures_path }
|
||||||
|
it { expect(flash[:alert]).to be_present }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'POST #create' do
|
||||||
|
context 'when all attributs are informed' do
|
||||||
|
describe 'new procedure in database' do
|
||||||
|
subject { post :create, procedure: procedure_params }
|
||||||
|
|
||||||
|
it { expect { subject }.to change { Procedure.count }.by(1) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when procedure is correctly save' do
|
||||||
|
before do
|
||||||
|
post :create, procedure: procedure_params
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'procedure attributs in database' do
|
||||||
|
subject { Procedure.last }
|
||||||
|
|
||||||
|
it { expect(subject.libelle).to eq(libelle) }
|
||||||
|
it { expect(subject.description).to eq(description) }
|
||||||
|
it { expect(subject.organisation).to eq(organisation) }
|
||||||
|
it { expect(subject.direction).to eq(direction) }
|
||||||
|
it { expect(subject.lien_demarche).to eq(lien_demarche) }
|
||||||
|
it { expect(subject.use_api_carto).to be_truthy }
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(subject).to redirect_to(admin_procedures_path) }
|
||||||
|
|
||||||
|
it { expect(flash[:notice]).to be_present }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when many attributs are not valid' do
|
||||||
|
let(:libelle) { '' }
|
||||||
|
let(:description) { '' }
|
||||||
|
|
||||||
|
describe 'no new procedure in database' do
|
||||||
|
subject { post :create, procedure: procedure_params }
|
||||||
|
|
||||||
|
it { expect { subject }.to change { Procedure.count }.by(0) }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'flash message is present' do
|
||||||
|
before do
|
||||||
|
post :create, procedure: procedure_params
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(flash[:alert]).to be_present }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'PUT #update' do
|
||||||
|
let!(:procedure) { create(:procedure) }
|
||||||
|
|
||||||
|
context 'when administrateur is not connected' do
|
||||||
|
before do
|
||||||
|
sign_out admin
|
||||||
|
end
|
||||||
|
|
||||||
|
subject { put :update, id: procedure.id }
|
||||||
|
|
||||||
|
it { expect(subject).to redirect_to new_administrateur_session_path }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when administrateur is connected' do
|
||||||
|
before do
|
||||||
|
put :update, id: procedure.id, procedure: procedure_params
|
||||||
|
procedure.reload
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when all attributs are informated' do
|
||||||
|
let(:libelle) { 'Blable' }
|
||||||
|
let(:description) { 'blabla' }
|
||||||
|
let(:organisation) { 'plop' }
|
||||||
|
let(:direction) { 'plap' }
|
||||||
|
let(:lien_demarche) { 'http://plip.com' }
|
||||||
|
let(:use_api_carto) { '0' }
|
||||||
|
|
||||||
|
describe 'procedure attributs in database' do
|
||||||
|
subject { procedure }
|
||||||
|
|
||||||
|
it { expect(subject.libelle).to eq(libelle) }
|
||||||
|
it { expect(subject.description).to eq(description) }
|
||||||
|
it { expect(subject.organisation).to eq(organisation) }
|
||||||
|
it { expect(subject.direction).to eq(direction) }
|
||||||
|
it { expect(subject.lien_demarche).to eq(lien_demarche) }
|
||||||
|
it { expect(subject.use_api_carto).to be_falsey }
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(subject).to redirect_to(admin_procedures_path) }
|
||||||
|
it { expect(flash[:notice]).to be_present }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when many attributs are not valid' do
|
||||||
|
let(:libelle) { '' }
|
||||||
|
let(:description) { '' }
|
||||||
|
|
||||||
|
describe 'flash message is present' do
|
||||||
|
it { expect(flash[:alert]).to be_present }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
7
spec/factories/administrateur.rb
Normal file
7
spec/factories/administrateur.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
FactoryGirl.define do
|
||||||
|
sequence(:administrateur_email) { |n| "plop#{n}@plop.com" }
|
||||||
|
factory :administrateur do
|
||||||
|
email { generate(:administrateur_email) }
|
||||||
|
password 'password'
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue