Merge branch 'develop' into staging

This commit is contained in:
Xavier J 2015-11-04 17:27:21 +01:00
commit 34e4dc06d1
95 changed files with 2658 additions and 579 deletions

66
README.md Normal file
View file

@ -0,0 +1,66 @@
# TPS - TéléProcédure Simplifié
## Context
TéléProcédure Simplifiée, ou TPS pour les intimes, est une plateforme 100% web et 0% email, conçue afin de répondre au besoin urgent de l'État d'appliquer la directive sur le 100% démat' à l'horizon 2018 pour les démarches administratives.
## Technologies utilisées
Ruby : 2.1.5
Rails : 4.2.0
## Initialisation de l'environnement de développement
Afin d'initialiser l'environnement de développement, éxécutez la commande suivante :
bundle install
## Création de la base de données
L'application utilise une base de donnée Postgresql. Pour en installer une, utilisez la commande suivante :
sudo apt-get install postgresql
Les informations nécessaire à l'initialisation de la base doivent être pré-configurer à la main grâce à la procédure suivante :
su - postgres
psql
> create user tps with password 'lol' createdb;
> \q
Afin de générer la BDD de l'application, il est nécessaire d'éxécuter les commandes suivantes :
rake db:create db:schema:load db:migrate
rake db:create db:schema:load db:migrate RAILS_ENV=test
## Installation de Phantom JS
Installer PhantomJS qui est utilisé par les tests automatisés de l'application.
## Exécution des tests (Rspec)
Pour éxécuter les tests de l'application, plusieurs possibilités :
- Lancer tous les tests
rake spec
rspec
- Lancer un test en particulier
rake spec SPEC=file_path/file_name_spec.rb:line_number
rspec file_path/file_name_spec.rb:line_number
- Lancer tous les tests d'un fichier
rake spec SPEC=file_path/file_name_spec.rb
rspec file_path/file_name_spec.rb

View file

@ -1,28 +0,0 @@
== README
This README would normally document whatever steps are necessary to get the
application up and running.
Things you may want to cover:
* Ruby version
* System dependencies
* Configuration
* Database creation
* Database initialization
* How to run the test suite
* Services (job queues, cache servers, search engines, etc.)
* Deployment instructions
* ...
Please feel free to use a different markup language if you do not plan to run
<tt>rake doc:app</tt>.

View file

@ -0,0 +1,194 @@
var ready = function () {
$("#add_type_de_champs_procedure").on('click', function (e) {
add_new_type_de('champs');
});
$("#add_type_de_piece_justificative_procedure").on('click', function (e) {
add_new_type_de('piece_justificative');
});
add_delete_listener_on_click_for_type_de("champs", "#liste_champs .btn-danger");
add_delete_listener_on_click_for_type_de("champs", "#new_type_de_champs .btn-danger");
add_delete_listener_on_click_for_type_de("piece_justificative", "#liste_piece_justificative .btn-danger");
add_delete_listener_on_click_for_type_de("piece_justificative", "#new_type_de_piece_justificative .btn-danger");
config_up_and_down_button();
add_action_listener_on_click_for_button_up(".button_up");
add_action_listener_on_click_for_button_down(".button_down");
};
$(document).ready(ready);
$(document).on('page:load', ready);
function add_delete_listener_on_click_for_type_de(type_libelle, node_id) {
$(node_id).on('click', function (e) {
var index = (e.target.id).replace('delete_type_de_' + type_libelle + '_', '').replace('_procedure', '');
delete_type_de(type_libelle, index);
});
}
function add_new_type_de(type_libelle) {
var CHAMPS = 0,
PJ = 1,
ERROR = -1;
if (is_champs_or_pj() == ERROR) return false;
function is_champs_or_pj() {
if (type_libelle == 'champs') return CHAMPS;
else if (type_libelle == 'piece_justificative') return PJ;
else return ERROR;
}
function which_index() {
return (is_champs_or_pj() == CHAMPS ? types_de_champs_index : types_de_piece_justificative_index)
}
$("#liste_" + type_libelle).append($("#type_de_" + type_libelle + "_" + which_index()));
$("#new_type_de_" + type_libelle).append($("#type_de_" + type_libelle + "_" + which_index()).clone());
$("#delete_type_de_" + type_libelle + "_" + which_index() + "_button").show();
if (is_champs_or_pj() == CHAMPS) {
types_de_champs_index++;
add_new_type_de_champs_params(which_index());
}
else if (is_champs_or_pj() == PJ) {
types_de_piece_justificative_index++;
add_new_type_de_piece_justificative_params(which_index());
}
$("#new_type_de_" + type_libelle + " .form-inline").attr('id', 'type_de_' + type_libelle + '_' + which_index());
$("#new_type_de_" + type_libelle + " #id_type_de_" + type_libelle + "").attr('name', 'type_de_' + type_libelle + '[' + which_index() + '][id_type_de_' + type_libelle + ']');
$("#new_type_de_" + type_libelle + " #id_type_de_" + type_libelle + "").val('');
$("#new_type_de_" + type_libelle + " #delete").attr('name', 'type_de_' + type_libelle + '[' + which_index() + '][delete]');
$("#new_type_de_" + type_libelle + " #delete").val('false');
$("#new_type_de_" + type_libelle + " #delete_type_de_" + type_libelle + "_" + (which_index() - 1) + "_button").attr('id', "delete_type_de_" + type_libelle + "_" + which_index() + "_button");
$("#new_type_de_" + type_libelle + " #delete_type_de_" + type_libelle + "_" + (which_index() - 1) + "_procedure").attr('id', "delete_type_de_" + type_libelle + "_" + which_index() + "_procedure");
if (is_champs_or_pj() == CHAMPS)
add_delete_listener_on_click_for_type_de("champs", "#delete_type_de_champs_" + which_index() + "_procedure");
else if (is_champs_or_pj() == PJ)
add_delete_listener_on_click_for_type_de("piece_justificative", "#delete_type_de_piece_justificative_" + which_index() + "_procedure");
$("#new_type_de_" + type_libelle + " #add_type_de_" + type_libelle + "_button").remove();
$("#new_type_de_" + type_libelle + " .form-inline").append($("#add_type_de_" + type_libelle + "_button"))
add_action_listener_on_click_for_button_up("#new_type_de_" + type_libelle + " .button_up")
add_action_listener_on_click_for_button_down("#new_type_de_" + type_libelle + " .button_down")
config_up_and_down_button();
}
function add_new_type_de_champs_params() {
$("#new_type_de_champs #libelle").attr('name', 'type_de_champs[' + types_de_champs_index + '][libelle]');
$("#new_type_de_champs #libelle").val('');
$("#new_type_de_champs #description").attr('name', 'type_de_champs[' + types_de_champs_index + '][description]');
$("#new_type_de_champs #description").val('');
$("#new_type_de_champs #type_champs").attr('name', 'type_de_champs[' + types_de_champs_index + '][type]');
$("#new_type_de_champs .order_place").attr('name', 'type_de_champs[' + types_de_champs_index + '][order_place]');
$("#new_type_de_champs .order_place").val(parseInt($("#liste_champs .order_place").last().val()) + 1);
$("#new_type_de_champs .order_type_de_champs_button").attr('id', 'order_type_de_champs_' + types_de_champs_index + '_button')
$("#new_type_de_champs .order_type_de_champs_button .button_up").attr('id', 'order_type_de_champs_' + types_de_champs_index + '_up_procedure')
$("#new_type_de_champs .order_type_de_champs_button .button_down").attr('id', 'order_type_de_champs_' + types_de_champs_index + '_down_procedure')
}
function add_new_type_de_piece_justificative_params() {
$("#new_type_de_piece_justificative #libelle").attr('name', 'type_de_piece_justificative[' + types_de_piece_justificative_index + '][libelle]');
$("#new_type_de_piece_justificative #libelle").val('');
$("#new_type_de_piece_justificative #description").attr('name', 'type_de_piece_justificative[' + types_de_piece_justificative_index + '][description]');
$("#new_type_de_piece_justificative #description").val('');
}
function delete_type_de(type_libelle, index) {
var delete_node = $("#type_de_" + type_libelle + "_" + index).hide();
$("#liste_delete_" + type_libelle).append(delete_node);
$("#type_de_" + type_libelle + "_" + index + " #delete").val('true');
if (type_libelle == 'champs') {
var next_order_place = parseInt($("#type_de_" + type_libelle + "_" + index + " .order_place").val());
var type_de_champs_to_change_order_place = $("#liste_champs .order_place");
type_de_champs_to_change_order_place.each(function () {
if ($(this).val() > next_order_place) {
$(this).val(next_order_place++);
}
});
$("#new_type_de_champs .order_place").val(next_order_place);
config_up_and_down_button();
}
}
function config_up_and_down_button() {
if ($("#liste_champs .order_place").size() > 0) {
var first_index = $("#liste_champs .order_place").first()
.attr('name')
.replace('type_de_champs[', '')
.replace('][order_place]', '');
var last_index = $("#liste_champs .order_place").last()
.attr('name')
.replace('type_de_champs[', '')
.replace('][order_place]', '');
$(".button_up").show();
$(".button_down").show();
$("#liste_champs .order_type_de_champs_button").show();
$("#order_type_de_champs_" + first_index + "_up_procedure").hide();
$("#order_type_de_champs_" + last_index + "_down_procedure").hide();
}
}
function add_action_listener_on_click_for_button_up(node_id) {
$(node_id).on('click', function (e) {
var index = (e.target.id).replace('order_type_de_champs_', '').replace('_up_procedure', '');
var order_place = parseInt($("#type_de_champs_" + index + " .order_place").val());
var order_place_before = order_place - 1;
var node_before = $("input[class='order_place'][value='" + order_place_before + "']").parent();
var index_before = (node_before.attr('id')).replace('type_de_champs_', '');
$("#type_de_champs_" + index).insertBefore("#type_de_champs_" + index_before);
$("#type_de_champs_" + index_before);
$("#type_de_champs_" + index_before + " .order_place").val(order_place);
$("#type_de_champs_" + index + " .order_place").val(order_place_before);
config_up_and_down_button();
});
}
function add_action_listener_on_click_for_button_down(node_id) {
$(node_id).on('click', function (e) {
var index = (e.target.id).replace('order_type_de_champs_', '').replace('_down_procedure', '');
var order_place = parseInt($("#type_de_champs_" + index + " .order_place").val());
var order_place_after = order_place + 1;
var node_after = $("input[class='order_place'][value='" + order_place_after + "']").parent();
var index_after = (node_after.attr('id')).replace('type_de_champs_', '');
$("#type_de_champs_" + index).insertAfter("#type_de_champs_" + index_after);
$("#type_de_champs_" + index_after);
$("#type_de_champs_" + index_after + " .order_place").val(order_place);
$("#type_de_champs_" + index + " .order_place").val(order_place_after);
config_up_and_down_button();
});
}

View file

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

View file

@ -0,0 +1,45 @@
@import "bootstrap";
@import "bootstrap-datepicker3";
#description_page #liste_champs{
h4{
margin-top: 35px;
}
}
.type_champs-text {
@extend .col-md-6;
@extend .col-lg-6;
input[type='text'] {
width: 100%;
}
}
.type_champs-textarea {
@extend .col-md-8;
@extend .col-lg-8;
textarea.form-control {
width:100%;
height: 133px;
}
}
.type_champs-number {
@extend .col-md-3;
@extend .col-lg-3;
input[type='number']{
width: 100%;
}
}
.type_champs-datetime {
@extend .col-md-2;
@extend .col-lg-2;
input[type='number']{
width: 100%;
}
}

View file

@ -0,0 +1,114 @@
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(create_procedure_params)
unless @procedure.save
flash.now.alert = @procedure.errors.full_messages.join('<br />').html_safe
return render 'new'
end
process_types_de_champs_params
process_types_de_piece_justificative_params
flash.notice = 'Procédure enregistrée'
redirect_to admin_procedures_path
end
def update
@procedure = Procedure.find(params[:id])
unless @procedure.update_attributes(create_procedure_params)
flash.now.alert = @procedure.errors.full_messages.join('<br />').html_safe
return render 'show'
end
process_types_de_champs_params
process_types_de_piece_justificative_params
flash.notice = 'Préocédure modifiée'
redirect_to admin_procedures_path
end
private
def process_types_de_champs_params
unless params[:type_de_champs].nil? || params[:type_de_champs].size == 0
params[:type_de_champs].each do |index, type_de_champs|
if type_de_champs[:delete] == 'true'
unless type_de_champs[:id_type_de_champs].nil? || type_de_champs[:id_type_de_champs] == ''
TypeDeChamps.destroy(type_de_champs[:id_type_de_champs])
end
else
if type_de_champs[:id_type_de_champs].nil? || type_de_champs[:id_type_de_champs] == ''
bdd_object = TypeDeChamps.new
else
bdd_object = TypeDeChamps.find(type_de_champs[:id_type_de_champs])
end
save_type_de_champs bdd_object, type_de_champs
end
end
end
end
def process_types_de_piece_justificative_params
unless params[:type_de_piece_justificative].nil? || params[:type_de_piece_justificative].size == 0
params[:type_de_piece_justificative].each do |index, type_de_piece_justificative|
if type_de_piece_justificative[:delete] == 'true'
unless type_de_piece_justificative[:id_type_de_piece_justificative].nil? || type_de_piece_justificative[:id_type_de_piece_justificative] == ''
TypeDePieceJustificative.destroy(type_de_piece_justificative[:id_type_de_piece_justificative])
end
else
if type_de_piece_justificative[:id_type_de_piece_justificative].nil? || type_de_piece_justificative[:id_type_de_piece_justificative] == ''
bdd_object = TypeDePieceJustificative.new
else
bdd_object = TypeDePieceJustificative.find(type_de_piece_justificative[:id_type_de_piece_justificative])
end
save_type_de_piece_justificative bdd_object, type_de_piece_justificative
end
end
end
end
def save_type_de_champs database_object, source
database_object.libelle = source[:libelle]
database_object.type_champs = source[:type]
database_object.description = source[:description]
database_object.order_place = source[:order_place]
database_object.procedure = @procedure
database_object.save
end
def save_type_de_piece_justificative database_object, source
database_object.libelle = source[:libelle]
database_object.description = source[:description]
database_object.procedure = @procedure
database_object.save
end
def create_procedure_params
params.require(:procedure).permit(:libelle, :description, :organisation, :direction, :lien_demarche, :use_api_carto)
end
end

View file

@ -0,0 +1,7 @@
class AdminController < ApplicationController
def index
redirect_to(controller: '/administrateurs/sessions', action: :new) unless administrateur_signed_in?
redirect_to (admin_procedures_path)
end
end

View file

@ -0,0 +1,14 @@
class Administrateurs::SessionsController < Devise::SessionsController
def new
@administrateur = Administrateur.new
end
def create
super
end
def after_sign_in_path_for(resource)
admin_procedures_path
end
end

View file

@ -2,29 +2,44 @@ class Backoffice::DossiersController < ApplicationController
before_action :authenticate_gestionnaire!
def show
@dossier = Dossier.find(params[:id])
initialize_instance_params params[:id]
end
def valid
initialize_instance_params params[:dossier_id]
@dossier.next_step! 'gestionnaire', 'valid'
flash.notice = 'Dossier confirmé avec succès.'
render 'show'
end
def close
initialize_instance_params params[:dossier_id]
@dossier.next_step! 'gestionnaire', 'close'
flash.notice = 'Dossier traité avec succès.'
render 'show'
end
private
def initialize_instance_params dossier_id
@dossier = Dossier.find(dossier_id)
@entreprise = @dossier.entreprise.decorate
@etablissement = @dossier.etablissement
@pieces_justificatives = @dossier.pieces_justificatives
@commentaires = @dossier.commentaires.order(created_at: :desc)
@commentaires = @dossier.ordered_commentaires
@commentaires = @commentaires.all.decorate
@commentaire_email = current_gestionnaire.email
@procedure = @dossier.procedure
@dossier = @dossier.decorate
@champs = @dossier.ordered_champs
rescue ActiveRecord::RecordNotFound
flash.alert = t('errors.messages.dossier_not_found')
redirect_to url_for(controller: '/backoffice')
end
def confirme
params[:id] = params[:dossier_id]
show
@dossier.next_step! 'gestionnaire', 'confirme'
flash.notice = 'Dossier confirmé avec succès.'
render 'show'
end
end

View file

@ -1,73 +1,3 @@
class DossiersController < ApplicationController
# def show
# @dossier = Dossier.find(params[:id])
# @etablissement = @dossier.etablissement
# @entreprise = @dossier.entreprise.decorate
# rescue ActiveRecord::RecordNotFound
# flash.alert = t('errors.messages.dossier_not_found')
# redirect_to url_for(controller: :siret)
# end
# def create
# procedure = Procedure.find(params['procedure_id'])
# @etablissement = Etablissement.new(SIADE::EtablissementAdapter.new(siret).to_params)
# @entreprise = Entreprise.new(SIADE::EntrepriseAdapter.new(siren).to_params)
# @dossier = Dossier.create
# @dossier.draft!
# @dossier.procedure = procedure
# @dossier.save
# @entreprise.dossier = @dossier
# @entreprise.save
# @etablissement.dossier = @dossier
# @etablissement.entreprise = @entreprise
# @etablissement.save
# redirect_to url_for(controller: :dossiers, action: :show, id: @dossier.id)
# rescue RestClient::ResourceNotFound
# flash.alert = t('errors.messages.invalid_siret')
# redirect_to url_for(controller: :siret, procedure_id: params['procedure_id'])
# rescue ActiveRecord::RecordNotFound
# flash.alert = t('errors.messages.dossier_not_found')
# redirect_to url_for(controller: :siret)
# end
# def update
# @dossier = Dossier.find(params[:id])
# if checked_autorisation_donnees?
# @dossier.update_attributes(update_params)
# redirect_to url_for(controller: :description, action: :show, dossier_id: @dossier.id)
# else
# @etablissement = @dossier.etablissement
# @entreprise = @dossier.entreprise.decorate
# flash.now.alert = 'Les conditions sont obligatoires.'
# render 'show'
# end
# end
# private
# def update_params
# params.require(:dossier).permit(:autorisation_donnees)
# end
# def dossier_id_is_present?
# @dossier_id != ''
# end
# def checked_autorisation_donnees?
# update_params[:autorisation_donnees] == '1'
# end
# def siret
# params[:siret]
# end
# def siren
# siret[0..8]
# end
end

View file

@ -0,0 +1,14 @@
class RootController < ApplicationController
def index
if user_signed_in?
redirect_to users_dossiers_path
elsif gestionnaire_signed_in?
redirect_to backoffice_path
elsif administrateur_signed_in?
redirect_to admin_procedures_path
else
redirect_to new_user_session_path
end
end
end

View file

@ -1,23 +1,24 @@
class Users::CarteController < ApplicationController
class Users::CarteController < UsersController
include DossierConcern
def show
@dossier = current_dossier
@dossier = current_user_dossier
rescue ActiveRecord::RecordNotFound
redirect_to url_for(controller: :dossiers, action: :index)
flash.alert = t('errors.messages.dossier_not_found')
redirect_to url_for(root_path)
end
def save_ref_api_carto
dossier = current_dossier
dossier = current_user_dossier
if dossier.draft?
dossier.update_attributes(ref_dossier_carto: params[:ref_dossier])
#dossier.update_attributes(ref_dossier_carto: params[:ref_dossier])
redirect_to url_for(controller: :description, action: :show, dossier_id: params[:dossier_id])
else
commentaire_params = {
email: 'Modification localisation',
body: 'La localisation de la demande a été modifiée. Merci de le prendre en compte.',
dossier_id: dossier.id
email: 'Modification localisation',
body: 'La localisation de la demande a été modifiée. Merci de le prendre en compte.',
dossier_id: dossier.id
}
commentaire = Commentaire.new commentaire_params
commentaire.save
@ -27,18 +28,12 @@ class Users::CarteController < ApplicationController
end
def get_position
dossier = current_dossier
tmp_position = Carto::Geocodeur.convert_adresse_to_point(current_user_dossier.etablissement.adresse.gsub("\r\n", ' '))
if dossier.position_lat.nil?
tmp_position = Carto::Geocodeur.convert_adresse_to_point(dossier.etablissement.adresse.gsub("\r\n", ' '))
if tmp_position.point.nil?
dossier.update_attributes(position_lat: '0', position_lon: '0')
else
dossier.update_attributes(position_lat: tmp_position.point.y, position_lon: tmp_position.point.x)
end
if !tmp_position.point.nil?
render json: {lon: tmp_position.point.x.to_s, lat: tmp_position.point.y.to_s, dossier_id: params[:dossier_id]}
else
render json: {lon: '0', lat: '0', dossier_id: params[:dossier_id]}
end
render json: { lon: dossier.position_lon, lat: dossier.position_lat, dossier_id: params[:dossier_id] }
end
end

View file

@ -1,13 +1,14 @@
class Users::DescriptionController < ApplicationController
class Users::DescriptionController < UsersController
def show
@dossier = Dossier.find(params[:dossier_id])
@dossier = current_user_dossier
@dossier = @dossier.decorate
@procedure = @dossier.procedure
@champs = @dossier.ordered_champs
rescue ActiveRecord::RecordNotFound
flash.alert = t('errors.messages.dossier_not_found')
redirect_to url_for(controller: :siret)
redirect_to url_for(root_path)
end
def error
@ -17,8 +18,8 @@ class Users::DescriptionController < ApplicationController
end
def create
@dossier = Dossier.find(params[:dossier_id])
unless @dossier.update_attributes(create_params)
@dossier = current_user_dossier
unless @dossier.update_attributes(create_params)
@dossier = @dossier.decorate
@procedure = @dossier.procedure
@ -31,6 +32,13 @@ class Users::DescriptionController < ApplicationController
cerfa.save
end
unless params[:champs].nil?
@dossier.champs.each do |champ|
champ.value = params[:champs]["'#{champ.id}'"]
champ.save
end
end
@dossier.pieces_justificatives.each do |piece_justificative|
unless params["piece_justificative_#{piece_justificative.type}"].nil?
piece_justificative.content = params["piece_justificative_#{piece_justificative.type}"]
@ -45,17 +53,16 @@ class Users::DescriptionController < ApplicationController
commentaire.dossier = @dossier
commentaire.save
else
@dossier.proposed!
@dossier.initiated!
end
flash.notice = 'Félicitation, votre demande a bien été enregistrée.'
redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: @dossier.id)
end
private
def create_params
params.permit(:nom_projet, :description, :montant_projet, :montant_aide_demande, :date_previsionnelle)
params.permit(:nom_projet, :description)
end
end

View file

@ -1,11 +1,12 @@
class Users::DossiersController < UsersController
before_action :authenticate_user!
def index
@dossiers = current_user.dossiers.order(updated_at: 'DESC').decorate
end
def show
@dossier = Dossier.find(params[:id])
@dossier = current_user_dossier params[:id]
@etablissement = @dossier.etablissement
@entreprise = @dossier.entreprise.decorate
@ -43,7 +44,7 @@ class Users::DossiersController < UsersController
def update
@dossier = Dossier.find(params[:id])
@dossier = current_user_dossier params[:id]
if checked_autorisation_donnees?
@dossier.update_attributes(update_params)

View file

@ -1,34 +1,32 @@
class Users::RecapitulatifController < UsersController
def show
@dossier = Dossier.find(params[:dossier_id])
@dossier = current_user_dossier
@dossier = @dossier.decorate
@procedure = @dossier.procedure
@champs = @dossier.ordered_champs
# mettre dans le modele
@commentaires = @dossier.commentaires.order(created_at: :desc)
@commentaires = @dossier.ordered_commentaires
@commentaires = @commentaires.all.decorate
#TODO load user email
@commentaire_email = 'user@email'
@commentaire_email = current_user.email
rescue ActiveRecord::RecordNotFound
flash.alert = t('errors.messages.dossier_not_found')
redirect_to url_for(controller: :siret)
redirect_to url_for(root_path)
end
def propose
def initiate
show
@dossier.next_step! 'user', 'propose'
@dossier.next_step! 'user', 'initiate'
flash.notice = 'Dossier soumis avec succès.'
render 'show'
end
def depose
def submit
show
@dossier.next_step! 'user', 'depose'
@dossier.next_step! 'user', 'submit'
flash.notice = 'Dossier déposé avec succès.'
render 'show'

View file

@ -1,3 +1,9 @@
class UsersController < ApplicationController
before_action :authenticate_user!
def current_user_dossier dossier_id=nil
dossier_id ||= params[:dossier_id]
current_user.dossiers.find(dossier_id)
end
end

View file

@ -15,17 +15,17 @@ class DossierDecorator < Draper::Decorator
case state
when 'draft'
'Brouillon'
when 'proposed'
when 'initiated'
'Soumis'
when 'reply'
when 'replied'
'Répondu'
when 'updated'
'Mis à jour'
when 'confirmed'
when 'validated'
'Validé'
when 'deposited'
when 'submitted'
'Déposé'
when 'processed'
when 'closed'
'Traité'
else
fail 'State not valid'

View file

@ -0,0 +1,6 @@
class Administrateur < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end

5
app/models/champ.rb Normal file
View file

@ -0,0 +1,5 @@
class Champ < ActiveRecord::Base
belongs_to :dossier
belongs_to :type_de_champs
delegate :libelle, :type_champs, :order_place, to: :type_de_champs
end

View file

@ -1,16 +1,17 @@
class Dossier < ActiveRecord::Base
enum state: { draft: 'draft',
proposed: 'proposed',
reply: 'reply',
updated: 'updated',
confirmed: 'confirmed',
deposited: 'deposited',
processed: 'processed' }
enum state: {draft: 'draft',
initiated: 'initiated',
replied: 'replied',
updated: 'updated',
validated: 'validated',
submitted: 'submitted', #-submit_validated
closed: 'closed'} #-processed
has_one :etablissement, dependent: :destroy
has_one :entreprise, dependent: :destroy
has_one :cerfa, dependent: :destroy
has_many :pieces_justificatives, dependent: :destroy
has_many :champs, dependent: :destroy
belongs_to :procedure
belongs_to :user
has_many :commentaires, dependent: :destroy
@ -18,16 +19,15 @@ class Dossier < ActiveRecord::Base
delegate :siren, to: :entreprise
delegate :siret, to: :etablissement
delegate :types_de_piece_justificative, to: :procedure
delegate :types_de_champs, to: :procedure
before_create :build_default_cerfa
after_save :build_default_pieces_justificatives, if: Proc.new { procedure_id_changed? }
after_save :build_default_champs, if: Proc.new { procedure_id_changed? }
validates :nom_projet, presence: true, allow_blank: false, allow_nil: true
validates :description, presence: true, allow_blank: false, allow_nil: true
validates :montant_projet, presence: true, allow_blank: false, allow_nil: true
validates :montant_aide_demande, presence: true, allow_blank: false, allow_nil: true
validates :date_previsionnelle, presence: true, allow_blank: false, unless: Proc.new { description.nil? }
validates :user, presence: true
def retrieve_piece_justificative_by_type(type)
@ -35,11 +35,26 @@ class Dossier < ActiveRecord::Base
end
def build_default_pieces_justificatives
procedure.types_de_piece_justificative.each do |type_de_piece_justificative|
PieceJustificative.create(type_de_piece_justificative_id: type_de_piece_justificative.id, dossier_id: id)
end
end
def build_default_champs
procedure.types_de_champs.each do |type_de_champs|
Champ.create(type_de_champs_id: type_de_champs.id, dossier_id: id)
end
end
def ordered_champs
champs.joins(', types_de_champs').where('champs.type_de_champs_id = types_de_champs.id').order('order_place')
end
def ordered_commentaires
commentaires.order(created_at: :desc)
end
def sous_domaine
if Rails.env.production?
'tps'
@ -49,7 +64,7 @@ class Dossier < ActiveRecord::Base
end
def next_step! role, action
unless %w(propose reply update comment confirme depose process).include?(action)
unless %w(initiate update comment valid submit close).include?(action)
fail 'action is not valid'
end
@ -59,20 +74,20 @@ class Dossier < ActiveRecord::Base
if role == 'user'
case action
when 'propose'
when 'initiate'
if draft?
proposed!
initiated!
end
when 'depose'
if confirmed?
deposited!
when 'submit'
if validated?
submitted!
end
when 'update'
if reply?
if replied?
updated!
end
when 'comment'
if reply?
if replied?
updated!
end
end
@ -80,21 +95,21 @@ class Dossier < ActiveRecord::Base
case action
when 'comment'
if updated?
reply!
elsif proposed?
reply!
replied!
elsif initiated?
replied!
end
when 'confirme'
when 'valid'
if updated?
confirmed!
elsif reply?
confirmed!
elsif proposed?
confirmed!
validated!
elsif replied?
validated!
elsif initiated?
validated!
end
when 'process'
if deposited?
processed!
when 'close'
if submitted?
closed!
end
end
end
@ -102,15 +117,15 @@ class Dossier < ActiveRecord::Base
end
def self.a_traiter
Dossier.where("state='proposed' OR state='updated' OR state='deposited'").order('updated_at ASC')
Dossier.where("state='initiated' OR state='updated' OR state='submitted'").order('updated_at ASC')
end
def self.en_attente
Dossier.where("state='reply' OR state='confirmed'").order('updated_at ASC')
Dossier.where("state='replied' OR state='validated'").order('updated_at ASC')
end
def self.termine
Dossier.where("state='processed'").order('updated_at ASC')
Dossier.where("state='closed'").order('updated_at ASC')
end
private

View file

@ -5,7 +5,6 @@ class PieceJustificative < ActiveRecord::Base
alias_attribute :type, :type_de_piece_justificative_id
mount_uploader :content, PieceJustificativeUploader
def empty?
content.blank?
end

View file

@ -1,9 +1,8 @@
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
validates :lien_demarche, presence: true, allow_blank: false, allow_nil: false
end

View file

@ -0,0 +1,14 @@
class TypeDeChamps < ActiveRecord::Base
enum type_champs: {text: 'text',
textarea: 'textarea',
datetime: 'datetime',
number: 'number'
}
belongs_to :procedure
has_many :champ
validates :libelle, presence: true, allow_blank: false, allow_nil: false
validates :type_champs, presence: true, allow_blank: false, allow_nil: false
validates :order_place, presence: true, allow_blank: false, allow_nil: false
end

View file

@ -0,0 +1,31 @@
%br
-{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
%label{ style:'font-weight:normal' }
=f.check_box :use_api_carto
Utilisation de l'API Carto
%br
%br
%h3.text-info
Liste des champs à remplir pour un dossier
=render partial: 'admin/procedures/types_de_champs/liste', locals: {f: f}
%br
%br
%h3.text-info
Liste des pièces justificatives à fournir pour un dossier
=render partial: 'admin/procedures/types_de_piece_justificative/liste', locals: {f: f}
%br
%div.small{style:'text-align:right'}
*Attributs obligatoires

View 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
%th#id ID
%th#libelle Libellé
%th#organisation Organisation
%th#direction Direction
- @procedures.each do |procedure|
%tr
%td= procedure.id
%td
= link_to(procedure.libelle, "/admin/procedures/#{procedure.id}")
%td= procedure.organisation
%td= procedure.direction

View file

@ -0,0 +1,8 @@
%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}
=f.submit 'Valider', class: 'btn btn-info', style: 'float:right'
%br
%br

View file

@ -0,0 +1,9 @@
%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}
=f.submit 'Editer', class: 'btn btn-success', style: 'float:right'
%br
%br

View file

@ -0,0 +1,40 @@
.form-inline{id:"type_de_champs_#{index}", style: 'padding-bottom:8px'}
.form-group{ style: 'padding-right: 2%' }
%h4 Libellé
%input.form-control#libelle{ type: 'text', placeholder: 'Libelle', name:"type_de_champs[#{index}][libelle]", size: 40, value: ("#{ type_de_champs.libelle }" unless type_de_champs.nil? ) }
.form-group{ style: 'padding-right: 2%' }
%h4 Type
%select.form-control#type_champs{ name: "type_de_champs[#{index}][type]" }
%option{ value: 'text', selected: (type_de_champs.type_champs == 'text' unless type_de_champs.nil?)}
Simple texte
%option{ value: 'textarea', selected: (type_de_champs.type_champs == 'textarea' unless type_de_champs.nil?)}
Texte multi-lignes
%option{ value: 'datetime', selected: (type_de_champs.type_champs == 'datetime' unless type_de_champs.nil?)}
Date
%option{ value: 'number', selected: (type_de_champs.type_champs == 'number' unless type_de_champs.nil?)}
Valeur numérique
.form-group{ style: 'padding-right: 2%' }
%h4
Description
%textarea.form-control#description{cols: 60, placeholder: 'Description', name: "type_de_champs[#{index}][description]"}
=("#{ type_de_champs.description }" unless type_de_champs.nil? )
%input.order_place{type: 'hidden', name: "type_de_champs[#{index}][order_place]", value: (("#{ type_de_champs.order_place }" unless type_de_champs.nil?) || index+1)}
%input#id_type_de_champs{type: 'hidden', name: "type_de_champs[#{index}][id_type_de_champs]", value: (("#{ type_de_champs.id}" unless type_de_champs.nil?))}
%input#delete{type: 'hidden', name: "type_de_champs[#{index}][delete]", value: 'false'}
-if type_de_champs.nil?
.form-group#add_type_de_champs_button
%br &nbsp;
%button.form-control.btn.btn-success#add_type_de_champs_procedure{type: 'button'} Ajouter
.form-group.order_type_de_champs_button{id: "order_type_de_champs_#{index}_button", style: ("display:none" if type_de_champs.nil?)}
%br &nbsp;
%button.form-control.btn.btn-default.button_up.fa.fa-chevron-up{type: 'button', id: "order_type_de_champs_#{index}_up_procedure"}
%button.form-control.btn.btn-default.button_down.fa.fa-chevron-down{type: 'button', id: "order_type_de_champs_#{index}_down_procedure"}
.form-group{id: "delete_type_de_champs_#{index}_button", style: ("display:none" if type_de_champs.nil?)}
%br &nbsp;
%button.form-control.btn.btn-danger.fa.fa-trash-o{type: 'button', id: "delete_type_de_champs_#{index}_procedure"}

View file

@ -0,0 +1,12 @@
#liste_champs
-if @procedure.types_de_champs.size > 0
- @procedure.types_de_champs.order(:order_place).each_with_index do |type_de_champs, index|
=render partial: 'admin/procedures/types_de_champs/form', locals:{ type_de_champs: type_de_champs, index: index }
#liste_delete_champs
#new_type_de_champs
=render partial: 'admin/procedures/types_de_champs/form', locals:{ type_de_champs: nil, index: @procedure.types_de_champs.size }
%script{ type:'text/javascript' }
="var types_de_champs_index = #{@procedure.types_de_champs.size}"

View file

@ -0,0 +1,22 @@
.form-inline{id:"type_de_piece_justificative_#{index}", style: 'padding-bottom:8px'}
.form-group{ style: 'padding-right: 2%' }
%h4 Libellé
%input.form-control#libelle{ type: 'text', placeholder: 'Libelle', name:"type_de_piece_justificative[#{index}][libelle]", size: 40, value: ("#{ type_de_piece_justificative.libelle }" unless type_de_piece_justificative.nil? ) }
.form-group{ style: 'padding-right: 2%' }
%h4
Description
%textarea.form-control#description{cols: 60, placeholder: 'Description', name: "type_de_piece_justificative[#{index}][description]"}
=("#{ type_de_piece_justificative.description }" unless type_de_piece_justificative.nil? )
%input#id_type_de_piece_justificative{type: 'hidden', name: "type_de_piece_justificative[#{index}][id_type_de_piece_justificative]", value: (("#{ type_de_piece_justificative.id}" unless type_de_piece_justificative.nil?))}
%input#delete{type: 'hidden', name: "type_de_piece_justificative[#{index}][delete]", value: 'false'}
-if type_de_piece_justificative.nil?
.form-group#add_type_de_piece_justificative_button
%br &nbsp;
%button.form-control.btn.btn-success#add_type_de_piece_justificative_procedure{type: 'button'} Ajouter
.form-group{id: "delete_type_de_piece_justificative_#{index}_button", style: ("display:none" if type_de_piece_justificative.nil?)}
%br &nbsp;
%button.form-control.btn.btn-danger.fa.fa-trash-o{type: 'button', id: "delete_type_de_piece_justificative_#{index}_procedure"}

View file

@ -0,0 +1,12 @@
#liste_piece_justificative
-if @procedure.types_de_piece_justificative.size > 0
- @procedure.types_de_piece_justificative.order(:libelle).each_with_index do |type_de_piece_justificative, index|
=render partial: 'admin/procedures/types_de_piece_justificative/form', locals:{ type_de_piece_justificative: type_de_piece_justificative, index: index }
#liste_delete_piece_justificative
#new_type_de_piece_justificative
=render partial: 'admin/procedures/types_de_piece_justificative/form', locals:{ type_de_piece_justificative: nil, index: @procedure.types_de_piece_justificative.size }
%script{ type:'text/javascript' }
="var types_de_piece_justificative_index = #{@procedure.types_de_piece_justificative.size}"

View file

@ -0,0 +1,10 @@
%h1 Bienvenue sur TPS - Administration
%br
#gestionnaire_login
= form_for @administrateur, url: {controller: 'administrateurs/sessions', action: :create } do |f|
.form-group-lg
.form-group
= f.text_field :email, class: 'form-control', placeholder: 'Email'
.form-group
= f.password_field :password, class: 'form-control', placeholder: 'Mot de passe'
= f.submit 'Se connecter', class: %w(btn btn-lg btn-success), data: { disable_with: 'Connexion', submit: true }

View file

@ -6,25 +6,6 @@
%h3.text-info
= @dossier.nom_projet
%br
%div.row
.col-lg-6.col-md-6
%h4 Montant total
%p{style:'margin-left:5%'}
=number_to_currency(@dossier.montant_projet.to_f, :unit => " ", :separator => ",", :delimiter => " ")
!='&euro;'
.col-lg-6.col-md-6
%h4 Début du projet souhaité
%p{style:'margin-left:5%'}
= @dossier.date_fr
%div.row
.col-lg-6.col-md-6
%h4 Montant souhaité
%p{style:'margin-left:5%'}
=number_to_currency(@dossier.montant_aide_demande.to_f, :unit => " ", :separator => ",", :delimiter => " ")
!='&euro;'
%br
.description
- begin
- @dossier.description.split(/(?:\n\r?|\r\n?')/).each do |line|
@ -32,20 +13,32 @@
%br
- rescue
=''
.col-lg-6.col-md-6
=render partial: '/dossiers/pieces_justificatives'
-#= pie_chart({"Montant à charge #{(100 - @dossier.montant_aide_demande.to_f/@dossier.montant_projet.to_f*100).round(2)}%" => (@dossier.montant_projet.to_f - @dossier.montant_aide_demande.to_f), "Montant souhaité #{(@dossier.montant_aide_demande.to_f/@dossier.montant_projet.to_f*100).round(2)}%" => @dossier.montant_aide_demande})
%br
-unless @champs.nil?
%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?
-if !@dossier.confirmed? && !@dossier.deposited? && !@dossier.processed?
-if !@dossier.validated? && !@dossier.submitted? && !@dossier.closed?
%a#maj_infos.btn.btn-info{href: "/users/dossiers/#{@dossier.id}/description?back_url=recapitulatif"}
= 'Editer mon dossier'
-unless user_signed_in?
-if !@dossier.confirmed? && !@dossier.deposited? && !@dossier.processed?
= form_tag(url_for({controller: 'backoffice/dossiers', action: :confirme, dossier_id: @dossier.id}), class: 'form-inline', method: 'POST') do
-if !@dossier.validated? && !@dossier.submitted? && !@dossier.closed?
= form_tag(url_for({controller: 'backoffice/dossiers', action: :valid, dossier_id: @dossier.id}), class: 'form-inline', method: 'POST') do
%button#action_button.btn.btn-success
= 'Valider le dossier'
-elsif @dossier.submitted?
= form_tag(url_for({controller: 'backoffice/dossiers', action: :close, dossier_id: @dossier.id}), class: 'form-inline', method: 'POST') do
%button#action_button.btn.btn-success
= 'Traiter le dossier'

View file

@ -1,4 +1,4 @@
%h1 Bienvenue sur TPS
%h1 Bienvenue sur TPS - Gestionnaire
%br
#gestionnaire_login
= form_for @gestionnaire, url: {controller: 'gestionnaires/sessions', action: :create } do |f|

View file

@ -17,6 +17,11 @@
%div{style: 'decorate:none; box-shadow:none; float:right; margin-top:8px'}
= current_gestionnaire.email
= link_to "Déconnexion", '/gestionnaires/sign_out', method: :delete, :class => 'btn btn-md'
-elsif administrateur_signed_in?
%div{style: 'decorate:none; box-shadow:none; float:right; margin-top:8px'}
= current_administrateur.email
= link_to "Déconnexion", '/administrateurs/sign_out', method: :delete, :class => 'btn btn-md'
- elsif user_signed_in?
%div.user{style: 'decorate:none; box-shadow:none; float:right; margin-top:8px'}
-if current_user.loged_in_with_france_connect

View file

@ -1 +0,0 @@
%h1 coucou

View file

@ -2,8 +2,8 @@
%h2 Description de votre projet
%br
-#TODO use form_for
= form_tag(url_for({controller: :description, action: :create, dossier_id: @dossier.id}), class: 'form-inline', method: 'POST', multipart: true) do
%div
.row
.col-md-12
@ -14,22 +14,28 @@
.col-md-12
%h4 Description de votre projet *
= text_area_tag :description, @dossier.description, rows: '6', placeholder: 'Description du projet', class: 'form-control'
%br
.row
.col-lg-6.col-md-6
%h4 Montant du projet *
= number_field_tag :montant_projet, @dossier.montant_projet, class: 'form-control', placeholder: 'Montant du projet'
!= '&euro;'
.col-lg-6.col-md-6
%h4 Montant des aides que vous sollicitez *
= number_field_tag :montant_aide_demande, @dossier.montant_aide_demande, class: 'form-control', placeholder: 'Montant des aides'
!='&euro;'
%br
.row
.col-lg-6.col-md-6
%h4 Date prévisionnelle du début de votre projet *
= text_field_tag :date_previsionnelle, @dossier.date_previsionnelle, placeholder: 'Date prévisionnelle', class: 'form-control', 'data-provide' => 'datepicker', 'data-date-format' => 'dd/mm/yyyy'
#liste_champs
-unless @champs.nil?
-@champs.each do |champ|
.row
%div{class: "type_champs-#{champ.type_champs}"}
%h4
= champ.libelle
-if champ.type_champs == 'textarea'
%textarea.form-control{name:"champs['#{champ.id}']",
placeholder: champ.libelle,
id: "champs_#{champ.id}"}
=champ.value
-else
%input.form-control{name:"champs['#{champ.id}']",
placeholder: champ.libelle,
id: "champs_#{champ.id}",
value: champ.value,
type:"#{champ.type_champs}",
'data-provide' => ('datepicker' if champ.type_champs == 'datetime'),
'data-date-format' => ('dd/mm/yyyy' if champ.type_champs == 'datetime')}
%br
%h3 Documents administratifs

View file

@ -1,21 +1,21 @@
%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-8.col-lg-8
.col-md-7.col-lg-7
%div.col-md-2.col-lg-2
.col-md-3.col-lg-3
%h2#dossier_id{:class => 'text-info', :style => 'text-align:right; margin-bottom:15px'}
= "Dossier n°#{@dossier.id}"
- unless gestionnaire_signed_in?
-if @dossier.draft?
= form_tag(url_for({controller: :recapitulatif, action: :propose, dossier_id: @dossier.id}), class: 'form-inline', method: 'POST') do
= form_tag(url_for({controller: :recapitulatif, action: :initiate, dossier_id: @dossier.id}), class: 'form-inline', method: 'POST') do
%button#action_button.btn.btn-success
= 'Soumettre mon dossier'
-elsif @dossier.confirmed?
= form_tag(url_for({controller: :recapitulatif, action: :depose, dossier_id: @dossier.id}), class: 'form-inline', method: 'POST') do
-elsif @dossier.validated?
= form_tag(url_for({controller: :recapitulatif, action: :submit, dossier_id: @dossier.id}), class: 'form-inline', method: 'POST') do
%button#action_button.btn.btn-success
= 'Déposer mon dossier'
-else

View file

@ -30,5 +30,15 @@
= render "users/shared/links"
%div{style:'text-align:center'}
\-
%br
%a{href: '/gestionnaires/sign_in'}
= 'Gestionnaire'
%br
%a{href: '/administrateurs/sign_in'}
= 'Administrateur'

View file

@ -11,6 +11,7 @@ ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.acronym 'API'
inflect.irregular 'piece_justificative', 'pieces_justificatives'
inflect.irregular 'type_de_piece_justificative', 'types_de_piece_justificative'
inflect.irregular 'type_de_champs', 'types_de_champs'
end
# These inflection rules are supported but not enabled by default:

View file

@ -78,7 +78,7 @@ fr:
not_saved:
one: "1 erreur a empêché ce(tte) %{resource} d'être sauvegardé(e) :"
other: "%{count} erreurs ont empêché ce(tte) %{resource} d'être sauvegardé(e) :"
dossier_not_found: "Le dossier n'existe pas"
dossier_not_found: "Le dossier n'existe pas ou vous n'y avez pas accès."
invalid_siret: "Le siret est incorrect"
france_connect:
connexion: "Erreur lors de la connexion à France Connect."

View file

@ -0,0 +1,12 @@
fr:
activerecord:
errors:
models:
procedure:
attributes:
libelle:
blank: Attribut manquant
description:
blank: Attribut manquant
lien_demarche:
blank: Attribut manquant

View file

@ -1,14 +1,18 @@
Rails.application.routes.draw do
devise_for :users, controllers: {
sessions: 'users/sessions'
}
devise_for :administrateurs, controllers: {
sessions: 'administrateurs/sessions'
}, skip: [:password, :registrations]
devise_for :gestionnaires, controllers: {
sessions: 'gestionnaires/sessions'
}, skip: [:password, :registrations]
root 'users/dossiers#index'
devise_for :users, controllers: {
sessions: 'users/sessions'
}
root 'root#index'
get 'france_connect' => 'france_connect#login'
get 'france_connect/callback' => 'france_connect#callback'
@ -21,10 +25,8 @@ Rails.application.routes.draw do
get '/description/error' => 'description#error'
post 'description' => 'description#create'
get '/recapitulatif' => 'recapitulatif#show'
post '/recapitulatif/propose' => 'recapitulatif#propose'
post '/recapitulatif/depose' => 'recapitulatif#depose'
get '/demande' => 'demandes#show'
post '/demande' => 'demandes#update'
post '/recapitulatif/initiate' => 'recapitulatif#initiate'
post '/recapitulatif/submit' => 'recapitulatif#submit'
post '/commentaire' => 'commentaires#create'
get '/carte/position' => 'carte#get_position'
@ -35,33 +37,27 @@ Rails.application.routes.draw do
resource :dossiers
end
get 'admin' => 'admin#index'
# resources :dossiers do
# # get '/carte/position' => 'carte#get_position'
# # get '/carte' => 'carte#show'
# # post '/carte' => 'carte#save_ref_api_carto'
# # get '/description' => 'description#show'
# # get '/description/error' => 'description#error'
# # post 'description' => 'description#create'
# post '/commentaire' => 'commentaires#create'
# end
namespace :admin do
get 'sign_in' => '/administrateurs/sessions#new'
resources :procedures do
end
end
get 'backoffice' => 'backoffice#index'
namespace :backoffice do
get 'sign_in' => '/gestionnaires/sessions#new'
resources :dossiers do
post 'confirme' => 'dossiers#confirme'
post 'valid' => 'dossiers#valid'
post 'close' => 'dossiers#close'
end
resources :commentaires, only: [:create]
end
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

View file

@ -0,0 +1,42 @@
class DeviseCreateAdministrateurs < ActiveRecord::Migration
def change
create_table(:administrateurs) do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.inet :current_sign_in_ip
t.inet :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
t.timestamps
end
add_index :administrateurs, :email, unique: true
add_index :administrateurs, :reset_password_token, unique: true
# add_index :administrateurs, :confirmation_token, unique: true
# add_index :administrateurs, :unlock_token, unique: true
end
end

View file

@ -0,0 +1,11 @@
class CreateTypesDeChamps < ActiveRecord::Migration
def change
create_table :types_de_champs do |t|
t.string :libelle
t.string :type
t.integer :order_place
t.belongs_to :procedure
end
end
end

View file

@ -0,0 +1,6 @@
class ChangeAttributsToTypeDeChamps < ActiveRecord::Migration
def change
rename_column :types_de_champs, :type, :type_champs
add_column :types_de_champs, :description, :text
end
end

View file

@ -0,0 +1,5 @@
class ChangeStateProposedToSubmitted < ActiveRecord::Migration
def change
Dossier.where(state: 'proposed').update_all(state: 'submitted')
end
end

View file

@ -0,0 +1,5 @@
class ChangeStatereplyToReplied < ActiveRecord::Migration
def change
Dossier.where(state: 'reply').update_all(state: 'replied')
end
end

View file

@ -0,0 +1,6 @@
class ChangeStateConfirmedToValidated < ActiveRecord::Migration
def change
Dossier.where(state: 'confirmed').update_all(state: 'validated')
end
end

View file

@ -0,0 +1,5 @@
class ChangeStateDepositedToSubmitValidate < ActiveRecord::Migration
def change
Dossier.where(state: 'deposited').update_all(state: 'submit_validated')
end
end

View file

@ -0,0 +1,5 @@
class ChangeStateProcessedToClosed < ActiveRecord::Migration
def change
Dossier.where(state: 'processed').update_all(state: 'closed')
end
end

View file

@ -0,0 +1,5 @@
class ChangeStateSubmittedToInitiated < ActiveRecord::Migration
def change
Dossier.where(state: 'submitted').update_all(state: 'initiated')
end
end

View file

@ -0,0 +1,5 @@
class ChangeStateSubmitValidatedToSubmitted < ActiveRecord::Migration
def change
Dossier.where(state: 'submit_validated').update_all(state: 'submitted')
end
end

View file

@ -0,0 +1,12 @@
class DeleteAttributsToDossier < ActiveRecord::Migration
def change
remove_column :dossiers, :montant_projet
remove_column :dossiers, :montant_aide_demande
remove_column :dossiers, :date_previsionnelle
remove_column :dossiers, :position_lat
remove_column :dossiers, :position_lon
remove_column :dossiers, :ref_dossier_carto
end
end

View file

@ -0,0 +1,9 @@
class CreateChamps < ActiveRecord::Migration
def change
create_table :champs do |t|
t.string :value
end
add_reference :champs, :type_de_champs, references: :types_de_champs
add_reference :champs, :dossier, references: :dossiers
end
end

View file

@ -11,11 +11,29 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20151008090835) do
ActiveRecord::Schema.define(version: 20151103091603) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "administrateurs", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.inet "current_sign_in_ip"
t.inet "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "administrateurs", ["email"], name: "index_administrateurs_on_email", unique: true, using: :btree
add_index "administrateurs", ["reset_password_token"], name: "index_administrateurs_on_reset_password_token", unique: true, using: :btree
create_table "cerfas", force: :cascade do |t|
t.string "content"
t.integer "dossier_id"
@ -23,6 +41,12 @@ ActiveRecord::Schema.define(version: 20151008090835) do
add_index "cerfas", ["dossier_id"], name: "index_cerfas_on_dossier_id", using: :btree
create_table "champs", force: :cascade do |t|
t.string "value"
t.integer "type_de_champs_id"
t.integer "dossier_id"
end
create_table "commentaires", force: :cascade do |t|
t.string "email"
t.datetime "created_at", null: false
@ -36,14 +60,8 @@ ActiveRecord::Schema.define(version: 20151008090835) do
create_table "dossiers", force: :cascade do |t|
t.string "description"
t.boolean "autorisation_donnees"
t.string "position_lat"
t.string "position_lon"
t.string "ref_dossier_carto"
t.string "nom_projet"
t.string "montant_projet"
t.string "montant_aide_demande"
t.integer "procedure_id"
t.date "date_previsionnelle"
t.datetime "created_at", default: '2015-09-22 09:25:29'
t.datetime "updated_at", default: '2015-09-22 09:25:29'
t.string "state"
@ -124,6 +142,14 @@ ActiveRecord::Schema.define(version: 20151008090835) do
t.boolean "use_api_carto", default: false
end
create_table "types_de_champs", force: :cascade do |t|
t.string "libelle"
t.string "type_champs"
t.integer "order_place"
t.integer "procedure_id"
t.text "description"
end
create_table "types_de_piece_justificative", force: :cascade do |t|
t.string "libelle"
t.string "description"

View file

@ -0,0 +1,461 @@
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
}
}
let(:types_de_champs_params) {
{'0' =>
{libelle: 'Champs de test',
type: 'number',
description: 'Description de test',
order_place: 1},
'1' =>
{libelle: 'Champs de test 2',
type: 'text',
description: 'Description de test 2',
order_place: 2}
}
}
let(:types_de_champs_params_errors) {
{'0' =>
{libelle: '',
type: 'number',
description: 'Description de test',
order_place: 1},
'1' =>
{libelle: 'Champs de test 2',
type: 'text',
description: 'Description de test 2',
order_place: 2}
}
}
let(:types_de_piece_justificative_params_errors) {
{'0' =>
{libelle: '',
description: 'Description de test'},
'1' =>
{libelle: 'Champs de test 2',
description: 'Description de test 2'}
}
}
let(:types_de_piece_justificative_params) {
{'0' =>
{libelle: 'PJ de test',
description: 'Description de test'},
'1' =>
{libelle: 'PJ de test 2',
description: 'Description de test 2'}
}
}
before do
sign_in admin
end
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 }
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
let(:procedure_id) { procedure.id }
it { expect(subject).to have_http_status(:success) }
end
context "when procedure doesn't exist" do
let(:procedure_id) { bad_procedure_id }
it { expect(subject).to redirect_to admin_procedures_path }
end
end
end
describe 'POST #create' do
context 'when all attributs are filled' 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
describe 'type_de_champs processing' do
before do
post :create, procedure: procedure_params, type_de_champs: types_de_champs_params
end
subject { Procedure.last }
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 filled' do
it { expect(subject.types_de_champs.size).to eq(2) }
describe ' check types de champs attributs present into database' do
subject { TypeDeChamps.all }
it { expect(subject[0].libelle).to eq(types_de_champs_params['0'][:libelle]) }
it { expect(subject[0].type_champs).to eq(types_de_champs_params['0'][:type]) }
it { expect(subject[0].description).to eq(types_de_champs_params['0'][:description]) }
it { expect(subject[0].order_place).to eq(types_de_champs_params['0'][:order_place]) }
it { expect(subject[1].libelle).to eq(types_de_champs_params['1'][:libelle]) }
it { expect(subject[1].type_champs).to eq(types_de_champs_params['1'][:type]) }
it { expect(subject[1].description).to eq(types_de_champs_params['1'][:description]) }
it { expect(subject[1].order_place).to eq(types_de_champs_params['1'][:order_place]) }
end
end
context 'when one of two types de champs have not a libelle' do
let(:types_de_champs_params) { types_de_champs_params_errors }
it { expect(subject.types_de_champs.size).to eq(1) }
end
end
describe 'type_de_piece_justificative processing' do
before do
post :create, procedure: procedure_params, type_de_piece_justificative: types_de_piece_justificative_params
end
subject { Procedure.last }
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 filled' do
it { expect(subject.types_de_piece_justificative.size).to eq(2) }
describe ' check types de piece justificative attributs present into database' do
subject { TypeDePieceJustificative.all }
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[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
context 'when one of two types de piece justificative have not a libelle' do
let(:types_de_piece_justificative_params) { types_de_piece_justificative_params_errors }
it { expect(subject.types_de_piece_justificative.size).to eq(1) }
end
end
end
describe 'PUT #update' do
let!(:procedure) { create(:procedure, :with_type_de_champs, :with_two_type_de_piece_justificative) }
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, type_de_champs: types_de_champs_params, type_de_piece_justificative: types_de_piece_justificative_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
describe 'type_de_champs processing' do
subject { procedure }
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 filled' do
it { expect(subject.types_de_champs.size).to eq(3) }
describe ' check types de champs attributs added into database' do
subject { procedure.types_de_champs }
it { expect(subject[1].libelle).to eq(types_de_champs_params['0'][:libelle]) }
it { expect(subject[1].type_champs).to eq(types_de_champs_params['0'][:type]) }
it { expect(subject[1].description).to eq(types_de_champs_params['0'][:description]) }
it { expect(subject[1].order_place).to eq(types_de_champs_params['0'][:order_place]) }
it { expect(subject[2].libelle).to eq(types_de_champs_params['1'][:libelle]) }
it { expect(subject[2].type_champs).to eq(types_de_champs_params['1'][:type]) }
it { expect(subject[2].description).to eq(types_de_champs_params['1'][:description]) }
it { expect(subject[2].order_place).to eq(types_de_champs_params['1'][:order_place]) }
end
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(1) }
end
context 'when user edit the filed' do
let(:types_de_champs_params) {
{'0' =>
{libelle: 'Champs de test editée',
type: 'number',
description: 'Description de test editée',
order_place: 1,
id_type_de_champs: procedure.types_de_champs.first.id}
}
}
it { expect(subject.types_de_champs.size).to eq(1) }
describe ' check types de champs attributs updated into database' do
subject { procedure.types_de_champs.first }
it { expect(subject.libelle).to eq(types_de_champs_params['0'][:libelle]) }
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
context 'when delete a type de champs' do
let(:types_de_champs_params) {
{'0' =>
{libelle: 'Champs de test editée',
type: 'number',
description: 'Description de test editée',
order_place: 1,
delete: 'true',
id_type_de_champs: procedure.types_de_champs.first.id}
}
}
it { expect(subject.types_de_champs.size).to eq(0) }
end
context 'when delete a type de champs present in database and a type champ not present in database' do
let(:types_de_champs_params) {
{'0' =>
{libelle: 'Champs de test editée',
type: 'number',
description: 'Description de test editée',
order_place: 1,
delete: 'true',
id_type_de_champs: procedure.types_de_champs.first.id},
'1' =>
{libelle: 'Champs de test editée',
type: 'number',
description: 'Description de test editée',
order_place: 1,
delete: 'true',
id_type_de_champs: ''}
}
}
it { expect(subject.types_de_champs.size).to eq(0) }
end
end
describe 'type_de_piece_justificative processing' do
subject { procedure }
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 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[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[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
context 'when one of two types de piece justificative have not a libelle' do
let(:types_de_piece_justificative_params) { types_de_piece_justificative_params_errors }
it { expect(subject.types_de_piece_justificative.size).to eq(3) }
end
context 'when one types de piece justificative is edit' do
let(:types_de_piece_justificative_params) {
{'0' =>
{libelle: 'PJ de test editée',
type: 'number',
description: 'Description de test editée',
order_place: 1,
id_type_de_piece_justificative: procedure.types_de_piece_justificative.first.id}
}
}
it { expect(subject.types_de_piece_justificative.size).to eq(2) }
describe ' check types de piece justificative attributs updated into database' do
subject { procedure.types_de_piece_justificative.first }
it { expect(subject.libelle).to eq(types_de_piece_justificative_params['0'][:libelle]) }
it { expect(subject.description).to eq(types_de_piece_justificative_params['0'][:description]) }
end
end
context 'when delete a type de piece justificative' do
let(:types_de_piece_justificative_params) {
{'0' =>
{libelle: 'PJ de test editée',
type: 'number',
description: 'Description de test editée',
order_place: 1,
delete: 'true',
id_type_de_piece_justificative: procedure.types_de_piece_justificative.first.id}
}
}
it { expect(subject.types_de_piece_justificative.size).to eq(1) }
end
context 'when delete a type de piece justificative present in database and a type piece justificative not present in database' do
let(:types_de_piece_justificative_params) {
{'0' =>
{libelle: 'PJ de test editée',
type: 'number',
description: 'Description de test editée',
order_place: 1,
delete: 'true',
id_type_de_piece_justificative: procedure.types_de_piece_justificative.first.id},
'1' =>
{libelle: 'PJ de test editée',
type: 'number',
description: 'Description de test editée',
order_place: 1,
delete: 'true',
id_type_de_piece_justificative: ''}
}
}
it { expect(subject.types_de_piece_justificative.size).to eq(1) }
end
end
end
end
end

View file

@ -30,7 +30,7 @@ describe Backoffice::CommentairesController, type: :controller do
subject { dossier.state }
it {is_expected.to eq('reply')}
it {is_expected.to eq('replied')}
end
end
end

View file

@ -7,7 +7,7 @@ describe Backoffice::DossiersController, type: :controller do
let(:gestionnaire) { create(:gestionnaire) }
describe 'GET #show' do
context "l'utilisateur est connecté" do
context 'gestionnaire is connected' do
before do
sign_in gestionnaire
end
@ -17,31 +17,43 @@ describe Backoffice::DossiersController, type: :controller do
expect(response).to have_http_status(200)
end
it "le numéro de dossier n'existe pas" do
it 'dossier id doesnt exist' do
get :show, id: bad_dossier_id
expect(response).to redirect_to('/backoffice')
end
end
context "L'utilisateur n'est pas connecté mais le numéro de dossier est correct" do
context 'gestionnaire doesnt connected but dossier id is correct' do
subject { get :show, id: dossier_id }
it { is_expected.to redirect_to('/gestionnaires/sign_in') }
end
end
describe 'POST #confirme' do
context 'le gestionnaire valide un dossier' do
before do
dossier.proposed!
sign_in gestionnaire
end
describe 'POST #valid' do
before do
dossier.initiated!
sign_in gestionnaire
end
it 'dossier change is state for confirmed' do
post :confirme, dossier_id: dossier_id
it 'dossier change is state for validated' do
post :valid, dossier_id: dossier_id
dossier.reload
expect(dossier.state).to eq('confirmed')
end
dossier.reload
expect(dossier.state).to eq('validated')
end
end
describe 'POST #close' do
before do
dossier.submitted!
sign_in gestionnaire
end
it 'dossier change is state to closed' do
post :close, dossier_id: dossier_id
dossier.reload
expect(dossier.state).to eq('closed')
end
end
end

View file

@ -17,10 +17,10 @@ describe Users::CommentairesController, type: :controller do
describe 'change dossier state after post a comment' do
context 'when user is connected' do
context 'when dossier is at state reply' do
context 'when dossier is at state replied' do
before do
sign_in dossier.user
dossier.reply!
dossier.replied!
post :create, dossier_id: dossier_id, texte_commentaire: texte_commentaire
dossier.reload

View file

@ -0,0 +1,34 @@
require 'spec_helper'
describe RootController, type: :controller do
subject { get :index }
context 'when User is connected' do
before do
sign_in create(:user)
end
it { expect(subject).to redirect_to(users_dossiers_path) }
end
context 'when Gestionnaire is connected' do
before do
sign_in create(:gestionnaire)
end
it { expect(subject).to redirect_to(backoffice_path) }
end
context 'when Administrateur is connected' do
before do
sign_in create(:administrateur)
end
it { expect(subject).to redirect_to(admin_procedures_path) }
end
context 'when nobody is connected' do
it { expect(subject).to redirect_to(new_user_session_path) }
end
end

View file

@ -8,10 +8,24 @@ RSpec.describe Users::CarteController, type: :controller do
let!(:etablissement) { create(:etablissement, dossier: dossier) }
let(:dossier_id) { dossier.id }
let(:bad_dossier_id) { Dossier.count + 1000 }
let(:ref_dossier_carto) { 'IATRQPQY' }
let(:adresse) { etablissement.adresse }
before do
sign_in dossier.user
end
describe 'GET #show' do
context 'user is not connected' do
before do
sign_out dossier.user
end
it 'redirects to users/sign_in' do
get :show, dossier_id: dossier_id
expect(response).to redirect_to('/users/sign_in')
end
end
it 'returns http success' do
get :show, dossier_id: dossier_id
expect(response).to have_http_status(:success)
@ -19,22 +33,24 @@ RSpec.describe Users::CarteController, type: :controller do
it 'redirection vers la liste des dossiers du user si dossier ID n\'existe pas' do
get :show, dossier_id: bad_dossier_id
expect(response).to redirect_to(controller: :dossiers, action: :index)
expect(response).to redirect_to(root_path)
end
it_behaves_like "not owner of dossier", :show
end
describe 'POST #save_ref_api_carto' do
context 'Aucune localisation n\'a jamais été enregistrée' do
it do
post :save_ref_api_carto, dossier_id: dossier_id, ref_dossier_carto: ref_dossier_carto
post :save_ref_api_carto, dossier_id: dossier_id
expect(response).to redirect_to("/users/dossiers/#{dossier_id}/description")
end
end
context 'En train de modifier la localisation' do
let(:dossier) { create(:dossier, :with_procedure, :with_user, ref_dossier_carto: ref_dossier_carto, state: 'proposed') }
let(:dossier) { create(:dossier, :with_procedure, :with_user, state: 'initiated') }
before do
post :save_ref_api_carto, dossier_id: dossier_id, ref_dossier_carto: ref_dossier_carto
post :save_ref_api_carto, dossier_id: dossier_id
end
context 'Enregistrement d\'un commentaire informant la modification' do
@ -69,11 +85,11 @@ RSpec.describe Users::CarteController, type: :controller do
get :get_position, dossier_id: dossier.id
end
subject { dossier.reload }
subject { JSON.parse(response.body) }
it 'on enregistre des coordonnées lat et lon à 0' do
expect(subject.position_lat).to eq('0')
expect(subject.position_lon).to eq('0')
expect(subject['lat']).to eq('0')
expect(subject['lon']).to eq('0')
end
end

View file

@ -6,7 +6,22 @@ describe Users::DescriptionController, type: :controller do
let(:dossier_id) { dossier.id }
let(:bad_dossier_id) { Dossier.count + 10 }
before do
sign_in dossier.user
end
describe 'GET #show' do
context 'user is not connected' do
before do
sign_out dossier.user
end
it 'redirects to users/sign_in' do
get :show, dossier_id: dossier_id
expect(response).to redirect_to('/users/sign_in')
end
end
it 'returns http success' do
get :show, dossier_id: dossier_id
expect(response).to have_http_status(:success)
@ -14,17 +29,16 @@ describe Users::DescriptionController, type: :controller do
it 'redirection vers start si mauvais dossier ID' do
get :show, dossier_id: bad_dossier_id
expect(response).to redirect_to(controller: :siret)
expect(response).to redirect_to(root_path)
end
it_behaves_like "not owner of dossier", :show
end
describe 'POST #create' do
let(:timestamp) { Time.now }
let(:nom_projet) { 'Projet de test' }
let(:description) { 'Description de test Coucou, je suis un saut à la ligne Je suis un double saut la ligne.' }
let(:montant_projet) { 12_000 }
let(:montant_aide_demande) { 3000 }
let(:date_previsionnelle) { '20/01/2016' }
let(:name_piece_justificative) { 'dossierPDF.pdf' }
let(:name_piece_justificative_0) { 'piece_justificative_0.pdf' }
@ -39,7 +53,7 @@ describe Users::DescriptionController, type: :controller do
describe 'Premier enregistrement des données' do
before do
dossier.draft!
post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description, montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, date_previsionnelle: date_previsionnelle
post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description
dossier.reload
end
@ -48,15 +62,15 @@ describe Users::DescriptionController, type: :controller do
end
it 'etat du dossier est soumis' do
expect(dossier.state).to eq('proposed')
expect(dossier.state).to eq('initiated')
end
end
# TODO changer les valeurs des champs et check in bdd
context 'En train de manipuler un dossier non brouillon' do
before do
dossier.proposed!
post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description, montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, date_previsionnelle: date_previsionnelle
dossier.initiated!
post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description
dossier.reload
end
@ -91,10 +105,7 @@ describe Users::DescriptionController, type: :controller do
post :create,
dossier_id: dossier_id,
nom_projet: nom_projet,
description: description,
montant_projet: montant_projet,
montant_aide_demande: montant_aide_demande,
date_previsionnelle: date_previsionnelle
description: description
}
before { subject }
@ -109,34 +120,13 @@ describe Users::DescriptionController, type: :controller do
it { is_expected.to render_template(:show) }
it { expect(flash[:alert]).to be_present }
end
context 'montant_projet empty' do
let(:montant_projet) { '' }
it { is_expected.to render_template(:show) }
it { expect(flash[:alert]).to be_present }
end
context 'montant_aide_demande empty' do
let(:montant_aide_demande) { '' }
it { is_expected.to render_template(:show) }
it { expect(flash[:alert]).to be_present }
end
context 'date_previsionnelle empty' do
let(:date_previsionnelle) { '' }
it { is_expected.to render_template(:show) }
it { expect(flash[:alert]).to be_present }
end
end
end
context 'Sauvegarde du CERFA PDF' do
before do
post :create, dossier_id: dossier_id,
nom_projet: nom_projet,
description: description,
montant_projet: montant_projet,
montant_aide_demande: montant_aide_demande,
date_previsionnelle: date_previsionnelle,
cerfa_pdf: cerfa_pdf
dossier.reload
end
@ -154,7 +144,7 @@ describe Users::DescriptionController, type: :controller do
context 'les anciens CERFA PDF sont écrasées à chaque fois' do
it 'il n\'y a qu\'un CERFA PDF par dossier' do
post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description, montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, date_previsionnelle: date_previsionnelle, cerfa_pdf: cerfa_pdf
post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description, cerfa_pdf: cerfa_pdf
cerfa = PieceJustificative.where(type_de_piece_justificative_id: '0', dossier_id: dossier_id)
expect(cerfa.many?).to eq(false)
end
@ -165,15 +155,35 @@ describe Users::DescriptionController, type: :controller do
end
end
context 'Sauvegarde des champs' do
let(:champs_dossier) { dossier.champs }
let(:dossier_champs_first) { 'test value' }
before do
post :create, {dossier_id: dossier_id,
nom_projet: nom_projet,
description: description,
champs: {
"'#{dossier.champs.first.id}'" => dossier_champs_first
}
}
dossier.reload
end
it { expect(dossier.champs.first.value).to eq(dossier_champs_first) }
context 'when champs value is empty' do
let(:dossier_champs_first) { 'test value' }
it { expect(dossier.champs.first.value).to eq(dossier_champs_first) }
end
end
context 'Sauvegarde des pièces justificatives' do
let(:all_pj_type){ dossier.procedure.type_de_piece_justificative_ids }
before do
post :create, {dossier_id: dossier_id,
nom_projet: nom_projet,
description: description,
montant_projet: montant_projet,
montant_aide_demande: montant_aide_demande,
date_previsionnelle: date_previsionnelle,
'piece_justificative_'+all_pj_type[0].to_s => piece_justificative_0,
'piece_justificative_'+all_pj_type[1].to_s => piece_justificative_1}
dossier.reload

View file

@ -30,7 +30,7 @@ describe Users::DossiersController, type: :controller do
describe 'GET #show' do
before do
sign_in create(:user)
sign_in dossier.user
end
it 'returns http success with dossier_id valid' do
get :show, id: dossier_id
@ -130,7 +130,7 @@ describe Users::DossiersController, type: :controller do
describe 'PUT #update' do
before do
sign_in create(:user)
sign_in dossier.user
put :update, id: dossier_id, dossier: { autorisation_donnees: autorisation_donnees }
end
context 'when Checkbox is checked' do

View file

@ -16,40 +16,43 @@ describe Users::RecapitulatifController, type: :controller do
it 'redirection vers siret si mauvais dossier ID' do
get :show, dossier_id: bad_dossier_id
expect(response).to redirect_to('/users/siret')
expect(response).to redirect_to('/')
end
it_behaves_like "not owner of dossier", :show
end
describe 'POST #propose' do
context 'when an user propose his dossier' do
describe 'POST #initiate' do
context 'when an user initiate his dossier' do
before do
post :propose, dossier_id: dossier.id
post :initiate, dossier_id: dossier.id
end
it 'dossier change his state for processed' do
it 'dossier change his state for closed' do
dossier.reload
expect(dossier.state).to eq('proposed')
expect(dossier.state).to eq('initiated')
end
it 'a message informe user what his dossier is proposed' do
it 'a message informe user what his dossier is initiated' do
expect(flash[:notice]).to include('Dossier soumis avec succès.')
end
end
end
describe 'POST #depose' do
describe 'POST #submit' do
context 'when an user depose his dossier' do
before do
dossier.confirmed!
post :depose, dossier_id: dossier.id
dossier.validated!
post :submit, dossier_id: dossier.id
end
it 'dossier change his state for deposed' do
it 'dossier change his state for submitted' do
dossier.reload
expect(dossier.state).to eq('deposited')
expect(dossier.state).to eq('submitted')
end
it 'a message informe user what his dossier is proposed' do
it 'a message informe user what his dossier is initiated' do
expect(flash[:notice]).to include('Dossier déposé avec succès.')
end
end

View file

@ -0,0 +1,55 @@
require 'spec_helper'
describe UsersController, type: :controller do
describe '#current_user_dossier' do
let(:user) { create(:user) }
let(:dossier) { create(:dossier, user: user)}
before do
sign_in user
end
context 'when no dossier_id is filled' do
it { expect{ subject.current_user_dossier }.to raise_error }
end
context 'when dossier_id is given as a param' do
context 'when dossier id is valid' do
it 'returns current user dossier' do
expect(subject.current_user_dossier dossier.id).to eq(dossier)
end
end
context 'when dossier id is incorrect' do
it { expect{ subject.current_user_dossier 1 }.to raise_error }
end
end
context 'when no params[] is given' do
context 'when dossier id is valid' do
before do
subject.params[:dossier_id] = dossier.id
end
it 'returns current user dossier' do
expect(subject.current_user_dossier).to eq(dossier)
end
end
context 'when dossier id is incorrect' do
it { expect{ subject.current_user_dossier }.to raise_error }
end
context 'when dossier_id is given as a param' do
before do
subject.params[:dossier_id] = 1
end
it 'returns dossier with the id on params past' do
expect(subject.current_user_dossier dossier.id).to eq(dossier)
end
end
end
end
end

View file

@ -17,13 +17,13 @@ describe DossierDecorator do
expect(subject).to eq('Brouillon')
end
it 'proposed is propose' do
dossier.proposed!
it 'initiated is initiate' do
dossier.initiated!
expect(subject).to eq('Soumis')
end
it 'reply is repondu' do
dossier.reply!
it 'replied is repondu' do
dossier.replied!
expect(subject).to eq('Répondu')
end
@ -32,18 +32,18 @@ describe DossierDecorator do
expect(subject).to eq('Mis à jour')
end
it 'confirmed is valide' do
dossier.confirmed!
it 'validated is valide' do
dossier.validated!
expect(subject).to eq('Validé')
end
it 'deposited is dépose' do
dossier.deposited!
it 'submitted is dépose' do
dossier.submitted!
expect(subject).to eq('Déposé')
end
it 'processed is traité' do
dossier.processed!
it 'closed is traité' do
dossier.closed!
expect(subject).to eq('Traité')
end
end

View 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

View file

@ -2,6 +2,7 @@ FactoryGirl.define do
factory :dossier do
nom_projet "Demande de subvention dans le cadre d'accompagnement d'enfant à l'étranger"
state 'draft'
trait :with_entreprise do
after(:build) do |dossier, _evaluator|
etablissement = create(:etablissement)
@ -13,7 +14,7 @@ FactoryGirl.define do
trait :with_procedure do
after(:build) do |dossier, _evaluator|
procedure = create(:procedure, :with_two_type_de_piece_justificative)
procedure = create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champs)
dossier.procedure = procedure
end
end

View file

@ -4,6 +4,14 @@ FactoryGirl.define do
libelle 'Demande de subvention'
description "Demande de subvention à l'intention des associations"
trait :with_type_de_champs do
after(:build) do |procedure, _evaluator|
type_de_champs = create(:type_de_champs)
procedure.types_de_champs << type_de_champs
end
end
trait :with_two_type_de_piece_justificative do
after(:build) do |procedure, _evaluator|
rib = create(:type_de_piece_justificative, :rib)

View file

@ -0,0 +1,8 @@
FactoryGirl.define do
factory :type_de_champs do
libelle 'Libellé'
description 'description de votre projet'
type_champs 'textarea'
order_place 1
end
end

View file

@ -0,0 +1,77 @@
require 'spec_helper'
feature 'add a new type de champs', js: true do
let(:administrateur) { create(:administrateur) }
before do
login_as administrateur, scope: :administrateur
end
context 'when create a new procedure' do
before do
visit new_admin_procedure_path
end
scenario 'page have form to created new type de champs' do
expect(page).to have_css('#type_de_champs_0')
expect(page).to have_css('input[name="type_de_champs[0][libelle]"]')
expect(page).to have_css('select[name="type_de_champs[0][type]"]')
expect(page).to have_css('textarea[name="type_de_champs[0][description]"]')
expect(page).to have_css('input[name="type_de_champs[0][order_place]"]', visible: false)
expect(page).to have_css('input[name="type_de_champs[0][id_type_de_champs]"]', visible: false)
expect(page).to have_css('input[name="type_de_champs[0][delete]"]', visible: false)
expect(page).to have_css('#order_type_de_champs_0_button', visible: false);
expect(page).to have_css('#order_type_de_champs_0_up_procedure', visible: false);
expect(page).to have_css('#order_type_de_champs_0_down_procedure', visible: false);
expect(page).to have_css('#new_type_de_champs #add_type_de_champs_button')
end
context 'when user add a new champs type' do
before do
page.find_by_id('type_de_champs_0').find_by_id('libelle').set 'Libelle de test'
page.find_by_id('type_de_champs_0').find_by_id('description').set 'Description de test'
page.click_on 'add_type_de_champs_procedure'
end
scenario 'a new champs type line is appeared with increment index id' do
expect(page).to have_css('#type_de_champs_1')
expect(page).to have_css('input[name="type_de_champs[1][libelle]"]')
expect(page).to have_css('select[name="type_de_champs[1][type]"]')
expect(page).to have_css('textarea[name="type_de_champs[1][description]"]')
expect(page).to have_css('input[name="type_de_champs[1][order_place]"]', visible: false)
expect(page).to have_css('input[name="type_de_champs[1][id_type_de_champs]"]', visible: false)
expect(page).to have_css('input[name="type_de_champs[1][delete]"]', visible: false)
expect(page).to have_css('#order_type_de_champs_1_button', visible: false);
expect(page).to have_css('#order_type_de_champs_1_up_procedure', visible: false);
expect(page).to have_css('#order_type_de_champs_1_down_procedure', visible: false);
end
scenario 'the first line is filled' do
expect(page.find_by_id('type_de_champs_0').find_by_id('libelle').value).to eq('Libelle de test')
expect(page.find_by_id('type_de_champs_0').find_by_id('description').value).to eq('Description de test')
expect(page.find_by_id('type_de_champs_0').find('input[class="order_place"]', visible: false).value).to eq('1')
end
scenario 'the first line have new button delete' do
expect(page).to have_css('#delete_type_de_champs_0_button')
expect(page).to have_css('#delete_type_de_champs_0_procedure')
end
scenario 'the new line is empty' do
expect(page.find_by_id('type_de_champs_1').find_by_id('libelle').value).to eq('')
expect(page.find_by_id('type_de_champs_1').find_by_id('description').value).to eq('')
expect(page.find_by_id('type_de_champs_1').find('input[class="order_place"]', visible: false).value).to eq('2')
expect(page.find_by_id('type_de_champs_1').find_by_id('id_type_de_champs', visible: false).value).to eq('')
expect(page.find_by_id('type_de_champs_1').find_by_id('delete', visible: false).value).to eq('false')
end
scenario 'the button Ajouter is at side new line' do
expect(page).to have_css('#new_type_de_champs #type_de_champs_1 #add_type_de_champs_button')
expect(page).not_to have_css('#type_de_champs_0 #add_type_de_champs_button')
end
end
end
end

View file

@ -0,0 +1,58 @@
require 'spec_helper'
feature 'add a new type de piece justificative', js: true do
let(:administrateur) { create(:administrateur) }
before do
login_as administrateur, scope: :administrateur
end
context 'when create a new procedure' do
before do
visit new_admin_procedure_path
end
scenario 'page have form to created new type de piece justificative' do
expect(page).to have_css('#type_de_piece_justificative_0')
expect(page).to have_css('input[name="type_de_piece_justificative[0][libelle]"]')
expect(page).to have_css('textarea[name="type_de_piece_justificative[0][description]"]')
expect(page).to have_css('input[name="type_de_piece_justificative[0][id_type_de_piece_justificative]"]', visible: false)
expect(page).to have_css('input[name="type_de_piece_justificative[0][delete]"]', visible: false)
expect(page).to have_css('#new_type_de_piece_justificative #add_type_de_piece_justificative_button')
end
context 'when user add a new piece justificative type' do
before do
page.find_by_id('type_de_piece_justificative_0').find_by_id('libelle').set 'Libelle de test'
page.find_by_id('type_de_piece_justificative_0').find_by_id('description').set 'Description de test'
page.click_on 'add_type_de_piece_justificative_procedure'
end
scenario 'a new piece justificative type line is appeared with increment index id' do
expect(page).to have_css('#type_de_piece_justificative_1')
expect(page).to have_css('input[name="type_de_piece_justificative[1][libelle]"]')
expect(page).to have_css('textarea[name="type_de_piece_justificative[1][description]"]')
expect(page).to have_css('input[name="type_de_piece_justificative[1][id_type_de_piece_justificative]"]', visible: false)
expect(page).to have_css('input[name="type_de_piece_justificative[1][delete]"]', visible: false)
end
scenario 'the first line is filled' do
expect(page.find_by_id('type_de_piece_justificative_0').find_by_id('libelle').value).to eq('Libelle de test')
expect(page.find_by_id('type_de_piece_justificative_0').find_by_id('description').value).to eq('Description de test')
end
scenario 'the new line is empty' do
expect(page.find_by_id('type_de_piece_justificative_1').find_by_id('libelle').value).to eq('')
expect(page.find_by_id('type_de_piece_justificative_1').find_by_id('description').value).to eq('')
expect(page.find_by_id('type_de_piece_justificative_1').find_by_id('id_type_de_piece_justificative', visible: false).value).to eq('')
expect(page.find_by_id('type_de_piece_justificative_1').find_by_id('delete', visible: false).value).to eq('false')
end
scenario 'the button Ajouter is at side new line' do
expect(page).to have_css('#new_type_de_piece_justificative #type_de_piece_justificative_1 #add_type_de_piece_justificative_button')
expect(page).not_to have_css('#type_de_piece_justificative_0 #add_type_de_piece_justificative_button')
end
end
end
end

View file

@ -0,0 +1,125 @@
require 'spec_helper'
feature 'config up and down button display', js: true do
let(:administrateur) { create(:administrateur) }
before do
login_as administrateur, scope: :administrateur
end
context 'when procedure have not type de champs' do
let!(:procedure) { create(:procedure) }
before do
visit admin_procedure_path id: procedure.id
end
scenario 'type_de_champs_0 have not up and down button visible' do
expect(page.find_by_id('order_type_de_champs_0_up_procedure', visible: false).visible?).to be_falsey
expect(page.find_by_id('order_type_de_champs_0_down_procedure', visible: false).visible?).to be_falsey
end
end
context 'when procedure have one type de champs' do
let!(:procedure) { create(:procedure, :with_type_de_champs) }
before do
visit admin_procedure_path id: procedure.id
end
scenario 'type_de_champs_0 have not up and down button visible' do
expect(page.find_by_id('order_type_de_champs_0_up_procedure', visible: false).visible?).to be_falsey
expect(page.find_by_id('order_type_de_champs_0_down_procedure', visible: false).visible?).to be_falsey
end
scenario 'type_de_champs_1 have not up and down button visible' do
expect(page.find_by_id('order_type_de_champs_1_up_procedure', visible: false).visible?).to be_falsey
expect(page.find_by_id('order_type_de_champs_1_down_procedure', visible: false).visible?).to be_falsey
end
end
context 'when procedure have two type de champs' do
let!(:procedure) { create(:procedure, :with_type_de_champs) }
let!(:type_de_champs) { create(:type_de_champs, procedure: procedure, order_place: 2) }
before do
visit admin_procedure_path id: procedure.id
end
scenario 'type_de_champs_0 have not up visible and down button visible' do
expect(page.find_by_id('order_type_de_champs_0_up_procedure', visible: false).visible?).to be_falsey
expect(page.find_by_id('order_type_de_champs_0_down_procedure').visible?).to be_truthy
end
scenario 'type_de_champs_1 have up button visible and down button not visible' do
expect(page.find_by_id('order_type_de_champs_1_up_procedure').visible?).to be_truthy
expect(page.find_by_id('order_type_de_champs_1_down_procedure', visible: false).visible?).to be_falsey
end
scenario 'type_de_champs_2 have not up and down button visible' do
expect(page.find_by_id('order_type_de_champs_2_up_procedure', visible: false).visible?).to be_falsey
expect(page.find_by_id('order_type_de_champs_2_down_procedure', visible: false).visible?).to be_falsey
end
end
context 'when procedure have two type de champs into database and one type de champs add to form' do
let!(:procedure) { create(:procedure, :with_type_de_champs) }
let!(:type_de_champs) { create(:type_de_champs, procedure: procedure, order_place: 2) }
before do
visit admin_procedure_path id: procedure.id
page.click_on 'add_type_de_champs_procedure'
end
scenario 'type_de_champs_0 have not up visible and down button visible' do
expect(page.find_by_id('order_type_de_champs_0_up_procedure', visible: false).visible?).to be_falsey
expect(page.find_by_id('order_type_de_champs_0_down_procedure').visible?).to be_truthy
end
scenario 'type_de_champs_1 have up button and down button visible' do
expect(page.find_by_id('order_type_de_champs_1_up_procedure').visible?).to be_truthy
expect(page.find_by_id('order_type_de_champs_1_down_procedure').visible?).to be_truthy
end
scenario 'type_de_champs_2 have up visible and down button not visible' do
expect(page.find_by_id('order_type_de_champs_2_up_procedure').visible?).to be_truthy
expect(page.find_by_id('order_type_de_champs_2_down_procedure', visible: false).visible?).to be_falsey
end
scenario 'type_de_champs_3 have not up and down button visible' do
expect(page.find_by_id('order_type_de_champs_3_up_procedure', visible: false).visible?).to be_falsey
expect(page.find_by_id('order_type_de_champs_3_down_procedure', visible: false).visible?).to be_falsey
end
end
context 'when procedure have two type de champs into database and one type de champs add to form and delete one type_de_champs' do
let!(:procedure) { create(:procedure, :with_type_de_champs) }
let!(:type_de_champs) { create(:type_de_champs, procedure: procedure, order_place: 2) }
before do
visit admin_procedure_path id: procedure.id
page.click_on 'add_type_de_champs_procedure'
page.click_on 'delete_type_de_champs_2_procedure'
end
scenario 'type_de_champs_0 have not up visible and down button visible' do
expect(page.find_by_id('order_type_de_champs_0_up_procedure', visible: false).visible?).to be_falsey
expect(page.find_by_id('order_type_de_champs_0_down_procedure').visible?).to be_truthy
end
scenario 'type_de_champs_1 have up button visible and down button not visible' do
expect(page.find_by_id('order_type_de_champs_1_up_procedure').visible?).to be_truthy
expect(page.find_by_id('order_type_de_champs_1_down_procedure', visible: false).visible?).to be_falsey
end
scenario 'type_de_champs_2 have up and down button not visible' do
expect(page.find_by_id('order_type_de_champs_2_up_procedure', visible: false).visible?).to be_falsey
expect(page.find_by_id('order_type_de_champs_2_down_procedure', visible: false).visible?).to be_falsey
end
scenario 'type_de_champs_3 have not up and down button visible' do
expect(page.find_by_id('order_type_de_champs_3_up_procedure', visible: false).visible?).to be_falsey
expect(page.find_by_id('order_type_de_champs_3_down_procedure', visible: false).visible?).to be_falsey
end
end
end

View file

@ -0,0 +1,80 @@
require 'spec_helper'
feature 'delete a type de champs form', js: true do
let(:administrateur) { create(:administrateur) }
before do
login_as administrateur, scope: :administrateur
end
context 'when user click on type de trash button' do
let!(:procedure) { create(:procedure, :with_type_de_champs) }
before do
visit admin_procedure_path id: procedure.id
end
context 'when user edit a type de champs already save in database' do
let(:type_de_champs) { procedure.types_de_champs.first }
before do
page.click_on 'delete_type_de_champs_0_procedure'
end
scenario 'form is mask for the user' do
expect(page.find_by_id('type_de_champs_0', visible: false).visible?).to be_falsey
end
scenario 'delete attribut of type de champs is turn to true' do
expect(page.find_by_id('type_de_champs_0', visible: false).find_by_id('delete', visible: false).value).to eq('true')
end
scenario 'attribut node is to move into div liste_delete_champs' do
expect(page).to have_css('#liste_delete_champs #type_de_champs_0', visible: false)
end
end
context 'when user edit a type de champs just add on the form page' do
before do
page.click_on 'add_type_de_champs_procedure'
page.click_on 'add_type_de_champs_procedure'
page.click_on 'add_type_de_champs_procedure'
page.click_on 'add_type_de_champs_procedure'
page.click_on 'add_type_de_champs_procedure'
page.click_on 'delete_type_de_champs_1_procedure'
page.click_on 'delete_type_de_champs_2_procedure'
end
scenario 'form is mask for the user' do
expect(page.find_by_id('type_de_champs_1', visible: false).visible?).to be_falsey
expect(page.find_by_id('type_de_champs_2', visible: false).visible?).to be_falsey
end
scenario 'delete attribut of type de champs is turn to true' do
expect(page.find_by_id('type_de_champs_1', visible: false).find_by_id('delete', visible: false).value).to eq('true')
expect(page.find_by_id('type_de_champs_2', visible: false).find_by_id('delete', visible: false).value).to eq('true')
end
scenario 'attribut node is to move into div liste_delete_champs' do
expect(page).to have_css('#liste_delete_champs #type_de_champs_1', visible: false)
expect(page).to have_css('#liste_delete_champs #type_de_champs_2', visible: false)
end
scenario 'order_place type_de_champs_0_procedure is 1' do
expect(page.find_by_id('type_de_champs_0').find("input[class='order_place']", visible: false).value).to eq('1')
end
scenario 'order_place type_de_champs_3_procedure is 2' do
expect(page.find_by_id('type_de_champs_3').find("input[class='order_place']", visible: false).value).to eq('2')
end
scenario 'order_place type_de_champs_4_procedure is 3' do
expect(page.find_by_id('type_de_champs_4').find("input[class='order_place']", visible: false).value).to eq('3')
end
scenario 'order_place type_de_champs_5_procedure is 4' do
expect(page.find_by_id('type_de_champs_5').find("input[class='order_place']", visible: false).value).to eq('4')
end
end
end
end

View file

@ -0,0 +1,52 @@
require 'spec_helper'
feature 'delete a type de piece_justificative form', js: true do
let(:administrateur) { create(:administrateur) }
before do
login_as administrateur, scope: :administrateur
end
context 'when user click on type de piece_justificative red X button' do
let!(:procedure) { create(:procedure, :with_two_type_de_piece_justificative) }
before do
visit admin_procedure_path id: procedure.id
end
context 'when user edit a type de piece_justificative already save in database' do
let(:type_de_piece_justificative) { procedure.types_de_piece_justificative.first }
before do
page.click_on 'delete_type_de_piece_justificative_0_procedure'
end
scenario 'form is mask for the user' do
expect(page.find_by_id('type_de_piece_justificative_0', visible: false).visible?).to be_falsey
end
scenario 'delete attribut of type de piece_justificative is turn to true' do
expect(page.find_by_id('type_de_piece_justificative_0', visible: false).find_by_id('delete', visible: false).value).to eq('true')
end
end
context 'when user edit a type de piece_justificative just add on the form page' do
before do
page.click_on 'add_type_de_piece_justificative_procedure'
page.click_on 'add_type_de_piece_justificative_procedure'
page.click_on 'delete_type_de_piece_justificative_2_procedure'
page.click_on 'delete_type_de_piece_justificative_3_procedure'
end
scenario 'form is mask for the user' do
expect(page.find_by_id('type_de_piece_justificative_2', visible: false).visible?).to be_falsey
expect(page.find_by_id('type_de_piece_justificative_3', visible: false).visible?).to be_falsey
end
scenario 'delete attribut of type de piece_justificative is turn to true' do
expect(page.find_by_id('type_de_piece_justificative_2', visible: false).find_by_id('delete', visible: false).value).to eq('true')
expect(page.find_by_id('type_de_piece_justificative_3', visible: false).find_by_id('delete', visible: false).value).to eq('true')
end
end
end
end

View file

@ -0,0 +1,79 @@
require 'spec_helper'
feature 'move down button type de champs', js: true do
let(:administrateur) { create(:administrateur) }
before do
login_as administrateur, scope: :administrateur
end
context 'when click on move down type de champs button' do
let!(:procedure) { create(:procedure, :with_type_de_champs) }
let!(:type_de_champs) { create(:type_de_champs, procedure: procedure, order_place: 2) }
before do
visit admin_procedure_path id: procedure.id
end
context 'when procedure have two type de champs' do
before do
page.click_on 'order_type_de_champs_0_down_procedure'
end
scenario 'it inverse the twice type de champs' do
expect(page.find_by_id('type_de_champs_0').find('input[class="order_place"]', visible: false).value).to eq('2');
expect(page.find_by_id('type_de_champs_1').find('input[class="order_place"]', visible: false).value).to eq('1');
end
end
context 'when procedure have two type de champs in database and 3 type de champs add on the page' do
before do
page.click_on 'add_type_de_champs_procedure'
page.click_on 'add_type_de_champs_procedure'
page.click_on 'add_type_de_champs_procedure'
end
context 'when to click on down_button type_de_champs_1' do
before do
page.click_on 'order_type_de_champs_1_down_procedure'
end
scenario 'type_de_champs_1 and type_de_champs_2 is reversed' do
expect(page.find_by_id('type_de_champs_0').find('input[class="order_place"]', visible: false).value).to eq('1');
expect(page.find_by_id('type_de_champs_2').find('input[class="order_place"]', visible: false).value).to eq('2');
expect(page.find_by_id('type_de_champs_1').find('input[class="order_place"]', visible: false).value).to eq('3');
expect(page.find_by_id('type_de_champs_3').find('input[class="order_place"]', visible: false).value).to eq('4');
expect(page.find_by_id('type_de_champs_4').find('input[class="order_place"]', visible: false).value).to eq('5');
end
context 'when to click on up_button type_de_champs_3' do
before do
page.click_on 'order_type_de_champs_3_down_procedure'
end
scenario 'type_de_champs_3 and type_de_champs_4 is reversed' do
expect(page.find_by_id('type_de_champs_0').find('input[class="order_place"]', visible: false).value).to eq('1');
expect(page.find_by_id('type_de_champs_2').find('input[class="order_place"]', visible: false).value).to eq('2');
expect(page.find_by_id('type_de_champs_1').find('input[class="order_place"]', visible: false).value).to eq('3');
expect(page.find_by_id('type_de_champs_4').find('input[class="order_place"]', visible: false).value).to eq('4');
expect(page.find_by_id('type_de_champs_3').find('input[class="order_place"]', visible: false).value).to eq('5');
end
context 'when to click on up_button type_de_champs_0' do
before do
page.click_on 'order_type_de_champs_0_down_procedure'
end
scenario 'type_de_champs_0 and type_de_champs_2 is reversed' do
expect(page.find_by_id('type_de_champs_2').find('input[class="order_place"]', visible: false).value).to eq('1');
expect(page.find_by_id('type_de_champs_0').find('input[class="order_place"]', visible: false).value).to eq('2');
expect(page.find_by_id('type_de_champs_1').find('input[class="order_place"]', visible: false).value).to eq('3');
expect(page.find_by_id('type_de_champs_4').find('input[class="order_place"]', visible: false).value).to eq('4');
expect(page.find_by_id('type_de_champs_3').find('input[class="order_place"]', visible: false).value).to eq('5');
end
end
end
end
end
end
end

View file

@ -0,0 +1,72 @@
require 'spec_helper'
feature 'move up and down button type de champs', js: true do
let(:administrateur) { create(:administrateur) }
before do
login_as administrateur, scope: :administrateur
end
context 'when click on move up and down type de champs button' do
let!(:procedure) { create(:procedure, :with_type_de_champs) }
let!(:type_de_champs) { create(:type_de_champs, procedure: procedure, order_place: 2) }
before do
visit admin_procedure_path id: procedure.id
end
context 'when procedure have two type de champs in database and 3 type de champs add on the page' do
before do
page.click_on 'add_type_de_champs_procedure'
page.click_on 'add_type_de_champs_procedure'
page.click_on 'add_type_de_champs_procedure'
end
#
context 'when to click on up_button type_de_champs_1 and down_button type_de_champs_0' do
before do
page.click_on 'order_type_de_champs_1_up_procedure'
page.click_on 'order_type_de_champs_0_down_procedure'
end
scenario 'type_de_champs_0 is at order place 3 and type_de_champs_1 is at order place 1 ' do
expect(page.find_by_id('type_de_champs_1').find('input[class="order_place"]', visible: false).value).to eq('1');
expect(page.find_by_id('type_de_champs_2').find('input[class="order_place"]', visible: false).value).to eq('2');
expect(page.find_by_id('type_de_champs_0').find('input[class="order_place"]', visible: false).value).to eq('3');
expect(page.find_by_id('type_de_champs_3').find('input[class="order_place"]', visible: false).value).to eq('4');
expect(page.find_by_id('type_de_champs_4').find('input[class="order_place"]', visible: false).value).to eq('5');
end
context 'when to click on down_button type_de_champs_3 and up_button type_de_champs_4' do
before do
page.click_on 'order_type_de_champs_3_down_procedure'
page.click_on 'order_type_de_champs_4_up_procedure'
end
scenario 'type_de_champs_2 and type_de_champs_3 is reversed' do
expect(page.find_by_id('type_de_champs_1').find('input[class="order_place"]', visible: false).value).to eq('1');
expect(page.find_by_id('type_de_champs_2').find('input[class="order_place"]', visible: false).value).to eq('2');
expect(page.find_by_id('type_de_champs_4').find('input[class="order_place"]', visible: false).value).to eq('3');
expect(page.find_by_id('type_de_champs_0').find('input[class="order_place"]', visible: false).value).to eq('4');
expect(page.find_by_id('type_de_champs_3').find('input[class="order_place"]', visible: false).value).to eq('5');
end
context 'when to click on up_button type_de_champs_2 and down_button type_de_champs_0 and up_button type_de_champs_4' do
before do
page.click_on 'order_type_de_champs_2_up_procedure'
page.click_on 'order_type_de_champs_0_down_procedure'
page.click_on 'order_type_de_champs_4_up_procedure'
end
scenario 'type_de_champs_2 and type_de_champs_4 is reversed' do
expect(page.find_by_id('type_de_champs_2').find('input[class="order_place"]', visible: false).value).to eq('1');
expect(page.find_by_id('type_de_champs_4').find('input[class="order_place"]', visible: false).value).to eq('2');
expect(page.find_by_id('type_de_champs_1').find('input[class="order_place"]', visible: false).value).to eq('3');
expect(page.find_by_id('type_de_champs_3').find('input[class="order_place"]', visible: false).value).to eq('4');
expect(page.find_by_id('type_de_champs_0').find('input[class="order_place"]', visible: false).value).to eq('5');
end
end
end
end
end
end
end

View file

@ -0,0 +1,80 @@
require 'spec_helper'
feature 'move up button type de champs', js: true do
let(:administrateur) { create(:administrateur) }
before do
login_as administrateur, scope: :administrateur
end
context 'when click on move up type de champs button' do
let!(:procedure) { create(:procedure, :with_type_de_champs) }
let!(:type_de_champs) { create(:type_de_champs, procedure: procedure, order_place: 2) }
before do
visit admin_procedure_path id: procedure.id
end
context 'when procedure have two type de champs' do
before do
page.click_on 'order_type_de_champs_1_up_procedure'
end
scenario 'it inverse the twice type de champs' do
expect(page.find_by_id('type_de_champs_0').find('input[class="order_place"]', visible: false).value).to eq('2');
expect(page.find_by_id('type_de_champs_1').find('input[class="order_place"]', visible: false).value).to eq('1');
end
end
context 'when procedure have two type de champs in database and 3 type de champs add on the page' do
before do
page.click_on 'add_type_de_champs_procedure'
page.click_on 'add_type_de_champs_procedure'
page.click_on 'add_type_de_champs_procedure'
end
context 'when to click on up_button type_de_champs_1' do
before do
page.click_on 'order_type_de_champs_1_up_procedure'
end
scenario 'type_de_champs_0 and type_de_champs_1 is reversed' do
expect(page.find_by_id('type_de_champs_1').find('input[class="order_place"]', visible: false).value).to eq('1');
expect(page.find_by_id('type_de_champs_0').find('input[class="order_place"]', visible: false).value).to eq('2');
expect(page.find_by_id('type_de_champs_2').find('input[class="order_place"]', visible: false).value).to eq('3');
expect(page.find_by_id('type_de_champs_3').find('input[class="order_place"]', visible: false).value).to eq('4');
expect(page.find_by_id('type_de_champs_4').find('input[class="order_place"]', visible: false).value).to eq('5');
end
context 'when to click on up_button type_de_champs_3' do
before do
page.click_on 'order_type_de_champs_3_up_procedure'
end
scenario 'type_de_champs_2 and type_de_champs_3 is reversed' do
expect(page.find_by_id('type_de_champs_1').find('input[class="order_place"]', visible: false).value).to eq('1');
expect(page.find_by_id('type_de_champs_0').find('input[class="order_place"]', visible: false).value).to eq('2');
expect(page.find_by_id('type_de_champs_3').find('input[class="order_place"]', visible: false).value).to eq('3');
expect(page.find_by_id('type_de_champs_2').find('input[class="order_place"]', visible: false).value).to eq('4');
expect(page.find_by_id('type_de_champs_4').find('input[class="order_place"]', visible: false).value).to eq('5');
end
context 'when to click on up_button type_de_champs_4' do
before do
page.click_on 'order_type_de_champs_4_up_procedure'
end
scenario 'type_de_champs_2 and type_de_champs_4 is reversed' do
expect(page.find_by_id('type_de_champs_1').find('input[class="order_place"]', visible: false).value).to eq('1');
expect(page.find_by_id('type_de_champs_0').find('input[class="order_place"]', visible: false).value).to eq('2');
expect(page.find_by_id('type_de_champs_3').find('input[class="order_place"]', visible: false).value).to eq('3');
expect(page.find_by_id('type_de_champs_4').find('input[class="order_place"]', visible: false).value).to eq('4');
expect(page.find_by_id('type_de_champs_2').find('input[class="order_place"]', visible: false).value).to eq('5');
end
end
end
end
end
end
end

View file

@ -2,7 +2,7 @@ require 'spec_helper'
feature 'on backoffice page' do
let(:procedure) { create(:procedure) }
let!(:dossier) { create(:dossier, :with_user, :with_entreprise, procedure: procedure, state: 'reply') }
let!(:dossier) { create(:dossier, :with_user, :with_entreprise, procedure: procedure, state: 'replied') }
before do
visit backoffice_path
end

View file

@ -1,19 +0,0 @@
require 'spec_helper'
feature 'On the description page' do
let!(:dossier) { create(:dossier, :with_entreprise, :with_procedure, :with_user) }
before do
visit users_dossier_description_path dossier
end
scenario 'date_previsionnelle field is present' do
expect(page).to have_css('#date_previsionnelle')
end
context 'when user clic on date_previsionnelle field', js: true do
before do
find_by_id('date_previsionnelle').click
end
scenario 'the datepicker popup is displayed' do
expect(page).to have_css('.datepicker-days')
end
end
end

View file

@ -4,6 +4,13 @@ feature 'user is on description page' do
let(:dossier) { create(:dossier, :with_entreprise, :with_procedure, :with_user) }
before do
visit users_dossier_description_path dossier
within('#new_user') do
page.find_by_id('user_email').set dossier.user.email
page.find_by_id('user_password').set dossier.user.password
page.click_on 'Se connecter'
end
end
it { expect(page).to have_css('#description_page') }
@ -11,9 +18,6 @@ feature 'user is on description page' do
before do
find_by_id('nom_projet').set 'mon nom'
find_by_id('description').set 'ma description'
find_by_id('montant_projet').set 10_000
find_by_id('montant_aide_demande').set 100
find_by_id('date_previsionnelle').set '10/10/2010'
end
context 'before submit' do
it 'dossier cerfa is empty' do

View file

@ -49,9 +49,6 @@ feature 'user path for dossier creation' do
before do
page.find_by_id('nom_projet').set 'Mon super projet'
page.find_by_id('description').set 'Ma super description'
page.find_by_id('montant_projet').set 10_000
page.find_by_id('montant_aide_demande').set 1_000
page.find_by_id('date_previsionnelle').set '09/09/2015'
page.click_on 'Soumettre mon dossier'
end
scenario 'user is on recap page' do

View file

@ -0,0 +1,18 @@
require 'spec_helper'
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) }
it { is_expected.to have_db_column(:reset_password_token) }
it { is_expected.to have_db_column(:reset_password_sent_at) }
it { is_expected.to have_db_column(:remember_created_at) }
it { is_expected.to have_db_column(:sign_in_count) }
it { is_expected.to have_db_column(:current_sign_in_at) }
it { is_expected.to have_db_column(:last_sign_in_at) }
it { is_expected.to have_db_column(:current_sign_in_ip) }
it { is_expected.to have_db_column(:last_sign_in_ip) }
it { is_expected.to have_db_column(:created_at) }
it { is_expected.to have_db_column(:updated_at) }
end
end

18
spec/models/champ_spec.rb Normal file
View file

@ -0,0 +1,18 @@
require 'spec_helper'
describe Champ do
describe 'database columns' do
it { is_expected.to have_db_column(:value) }
end
describe 'associations' do
it { is_expected.to belong_to(:dossier) }
it { is_expected.to belong_to(:type_de_champs) }
end
describe 'delegation' do
it { is_expected.to delegate_method(:libelle).to(:type_de_champs) }
it { is_expected.to delegate_method(:type_champs).to(:type_de_champs) }
it { is_expected.to delegate_method(:order_place).to(:type_de_champs) }
end
end

View file

@ -5,19 +5,18 @@ describe Dossier do
describe 'database columns' do
it { is_expected.to have_db_column(:description) }
it { is_expected.to have_db_column(:autorisation_donnees) }
it { is_expected.to have_db_column(:position_lat) }
it { is_expected.to have_db_column(:position_lon) }
it { is_expected.to have_db_column(:nom_projet) }
it { is_expected.to have_db_column(:montant_projet) }
it { is_expected.to have_db_column(:montant_aide_demande) }
it { is_expected.to have_db_column(:date_previsionnelle).of_type(:date) }
it { is_expected.to have_db_column(:created_at) }
it { is_expected.to have_db_column(:updated_at) }
it { is_expected.to have_db_column(:state) }
it { is_expected.to have_db_column(:procedure_id) }
it { is_expected.to have_db_column(:user_id) }
end
describe 'associations' do
it { is_expected.to belong_to(:procedure) }
it { is_expected.to have_many(:pieces_justificatives) }
it { is_expected.to have_many(:champs) }
it { is_expected.to have_many(:commentaires) }
it { is_expected.to have_one(:cerfa) }
it { is_expected.to have_one(:etablissement) }
@ -29,6 +28,7 @@ describe Dossier do
it { is_expected.to delegate_method(:siren).to(:entreprise) }
it { is_expected.to delegate_method(:siret).to(:etablissement) }
it { is_expected.to delegate_method(:types_de_piece_justificative).to(:procedure) }
it { is_expected.to delegate_method(:types_de_champs).to(:procedure) }
end
describe 'validation' do
@ -42,16 +42,6 @@ describe Dossier do
it { is_expected.not_to allow_value('').for(:description) }
it { is_expected.to allow_value('ma superbe description').for(:description) }
end
context 'montant_projet' do
it { is_expected.to allow_value(nil).for(:montant_projet) }
it { is_expected.not_to allow_value('').for(:montant_projet) }
it { is_expected.to allow_value(124324).for(:montant_projet) }
end
context 'montant_aide_demande' do
it { is_expected.to allow_value(nil).for(:montant_aide_demande) }
it { is_expected.not_to allow_value('').for(:montant_aide_demande) }
it { is_expected.to allow_value(124324).for(:montant_aide_demande) }
end
end
describe 'methods' do
@ -102,12 +92,27 @@ describe Dossier do
end
end
describe '#build_default_champs' do
context 'when dossier is linked to a procedure' do
let(:dossier) { create(:dossier, :with_procedure, user: user) }
it 'build all champs needed' do
expect(dossier.champs.count).to eq(1)
end
end
end
describe '#save' do
subject { create(:dossier, procedure_id: nil, user: user) }
let!(:procedure) { create(:procedure) }
context 'when is linked to a procedure' do
it 'creates default pieces justificatives' do
expect(subject).to receive(:build_default_pieces_justificatives)
subject.update_attributes(procedure_id: 1)
subject.update_attributes(procedure_id: procedure.id)
end
it 'creates default champs' do
expect(subject).to receive(:build_default_champs)
subject.update_attributes(procedure_id: procedure.id)
end
end
context 'when is not linked to a procedure' do
@ -115,14 +120,18 @@ describe Dossier do
expect(subject).not_to receive(:build_default_pieces_justificatives)
subject.update_attributes(description: 'plop')
end
it 'does not create default champs' do
expect(subject).not_to receive(:build_default_champs)
subject.update_attributes(description: 'plop')
end
end
end
#TODO revoir le nommage
describe '#next_step' do
let(:dossier) { create(:dossier, :with_user) }
let(:role) { 'user' }
let(:action) { 'propose' }
let(:action) { 'initiate' }
subject { dossier.next_step! role, action }
@ -156,17 +165,17 @@ describe Dossier do
it { is_expected.to eq('draft') }
end
context 'when he proposes a dossier' do
let(:action) { 'propose' }
context 'when he initiate a dossier' do
let(:action) { 'initiate' }
it { is_expected.to eq('proposed') }
it { is_expected.to eq('initiated') }
end
end
end
context 'when dossier is at state proposed' do
context 'when dossier is at state initiated' do
before do
dossier.proposed!
dossier.initiated!
end
context 'when user is connect' do
@ -175,13 +184,13 @@ describe Dossier do
context 'when is update dossier informations' do
let(:action) { 'update' }
it {is_expected.to eq('proposed')}
it {is_expected.to eq('initiated')}
end
context 'when is post a comment' do
let(:action) { 'comment' }
it {is_expected.to eq('proposed')}
it {is_expected.to eq('initiated')}
end
end
@ -191,20 +200,20 @@ describe Dossier do
context 'when is post a comment' do
let(:action) { 'comment' }
it { is_expected.to eq('reply')}
it { is_expected.to eq('replied')}
end
context 'when is confirmed the dossier' do
let(:action) { 'confirme' }
context 'when is validated the dossier' do
let(:action) { 'valid' }
it {is_expected.to eq('confirmed')}
it {is_expected.to eq('validated')}
end
end
end
context 'when dossier is at state reply' do
context 'when dossier is at state replied' do
before do
dossier.reply!
dossier.replied!
end
context 'when user is connect' do
@ -232,13 +241,13 @@ describe Dossier do
context 'when is post a comment' do
let(:action) { 'comment' }
it { is_expected.to eq('reply')}
it { is_expected.to eq('replied')}
end
context 'when is confirmed the dossier' do
let(:action) { 'confirme' }
context 'when is validated the dossier' do
let(:action) { 'valid' }
it {is_expected.to eq('confirmed')}
it {is_expected.to eq('validated')}
end
end
end
@ -270,20 +279,20 @@ describe Dossier do
context 'when is post a comment' do
let(:action) { 'comment' }
it { is_expected.to eq('reply')}
it { is_expected.to eq('replied')}
end
context 'when is confirmed the dossier' do
let(:action) { 'confirme' }
context 'when is validated the dossier' do
let(:action) { 'valid' }
it {is_expected.to eq('confirmed')}
it {is_expected.to eq('validated')}
end
end
end
context 'when dossier is at state confirmed' do
context 'when dossier is at state validated' do
before do
dossier.confirmed!
dossier.validated!
end
context 'when user is connect' do
@ -291,13 +300,13 @@ describe Dossier do
context 'when is post a comment' do
let(:action) { 'comment' }
it { is_expected.to eq('confirmed') }
it { is_expected.to eq('validated') }
end
context 'when is deposed the dossier' do
let(:action) { 'depose' }
context 'when is submitted the dossier' do
let(:action) { 'submit' }
it { is_expected.to eq('deposited') }
it { is_expected.to eq('submitted') }
end
end
@ -307,14 +316,14 @@ describe Dossier do
context 'when is post a comment' do
let(:action) { 'comment' }
it { is_expected.to eq('confirmed')}
it { is_expected.to eq('validated')}
end
end
end
context 'when dossier is at state deposited' do
context 'when dossier is at state submitted' do
before do
dossier.deposited!
dossier.submitted!
end
context 'when user is connect' do
@ -323,7 +332,7 @@ describe Dossier do
context 'when is post a comment' do
let(:action) { 'comment' }
it { is_expected.to eq('deposited') }
it { is_expected.to eq('submitted') }
end
end
@ -333,20 +342,20 @@ describe Dossier do
context 'when is post a comment' do
let(:action) { 'comment' }
it {is_expected.to eq('deposited')}
it {is_expected.to eq('submitted')}
end
context 'when is processed the dossier' do
let(:action) { 'process' }
context 'when is closed the dossier' do
let(:action) { 'close' }
it {is_expected.to eq('processed')}
it {is_expected.to eq('closed')}
end
end
end
context 'when dossier is at state processed' do
context 'when dossier is at state closed' do
before do
dossier.processed!
dossier.closed!
end
context 'when user is connect' do
@ -355,7 +364,7 @@ describe Dossier do
context 'when is post a comment' do
let(:action) { 'comment' }
it { is_expected.to eq('processed')}
it { is_expected.to eq('closed')}
end
end
@ -365,7 +374,7 @@ describe Dossier do
context 'when is post a comment' do
let(:action) { 'comment' }
it { is_expected.to eq('processed')}
it { is_expected.to eq('closed')}
end
end
end
@ -373,13 +382,13 @@ describe Dossier do
context 'gestionnaire backoffice methods' do
let!(:dossier1) { create(:dossier, :with_user, :with_procedure, state: 'draft')}
let!(:dossier2) { create(:dossier, :with_user, :with_procedure, state: 'proposed')}
let!(:dossier3) { create(:dossier, :with_user, :with_procedure, state: 'proposed')}
let!(:dossier4) { create(:dossier, :with_user, :with_procedure, state: 'reply')}
let!(:dossier2) { create(:dossier, :with_user, :with_procedure, state: 'initiated')}
let!(:dossier3) { create(:dossier, :with_user, :with_procedure, state: 'initiated')}
let!(:dossier4) { create(:dossier, :with_user, :with_procedure, state: 'replied')}
let!(:dossier5) { create(:dossier, :with_user, :with_procedure, state: 'updated')}
let!(:dossier6) { create(:dossier, :with_user, :with_procedure, state: 'confirmed')}
let!(:dossier7) { create(:dossier, :with_user, :with_procedure, state: 'deposited')}
let!(:dossier8) { create(:dossier, :with_user, :with_procedure, state: 'processed')}
let!(:dossier6) { create(:dossier, :with_user, :with_procedure, state: 'validated')}
let!(:dossier7) { create(:dossier, :with_user, :with_procedure, state: 'submitted')}
let!(:dossier8) { create(:dossier, :with_user, :with_procedure, state: 'closed')}
describe '#a_traiter' do
subject { described_class.a_traiter }

View file

@ -3,6 +3,7 @@ require 'spec_helper'
describe Procedure do
describe 'assocations' do
it { is_expected.to have_many(:types_de_piece_justificative) }
it { is_expected.to have_many(:types_de_champs) }
it { is_expected.to have_many(:dossiers) }
end
@ -28,8 +29,8 @@ describe Procedure do
end
context 'lien_demarche' do
it { is_expected.not_to allow_value(nil).for(:lien_demarche) }
it { is_expected.not_to allow_value('').for(:lien_demarche) }
it { is_expected.to allow_value(nil).for(:lien_demarche) }
it { is_expected.to allow_value('').for(:lien_demarche) }
it { is_expected.to allow_value('http://localhost').for(:lien_demarche) }
end
end

View file

@ -0,0 +1,45 @@
require 'spec_helper'
describe TypeDeChamps do
describe 'database columns' do
it { is_expected.to have_db_column(:libelle) }
it { is_expected.to have_db_column(:type_champs) }
it { is_expected.to have_db_column(:order_place) }
it { is_expected.to have_db_column(:description) }
end
describe 'associations' do
it { is_expected.to belong_to(:procedure) }
it { is_expected.to have_many(:champ) }
end
describe 'validation' do
context 'libelle' do
it { is_expected.not_to allow_value(nil).for(:libelle) }
it { is_expected.not_to allow_value('').for(:libelle) }
it { is_expected.to allow_value('Montant projet').for(:libelle) }
end
context 'type' do
it { is_expected.not_to allow_value(nil).for(:type_champs) }
it { is_expected.not_to allow_value('').for(:type_champs) }
it { is_expected.to allow_value('text').for(:type_champs) }
it { is_expected.to allow_value('textarea').for(:type_champs) }
it { is_expected.to allow_value('datetime').for(:type_champs) }
it { is_expected.to allow_value('number').for(:type_champs) }
end
context 'order_place' do
it { is_expected.not_to allow_value(nil).for(:order_place) }
it { is_expected.not_to allow_value('').for(:order_place) }
it { is_expected.to allow_value(1).for(:order_place) }
end
context 'description' do
it { is_expected.to allow_value(nil).for(:description) }
it { is_expected.to allow_value('').for(:description) }
it { is_expected.to allow_value('blabla').for(:description) }
end
end
end

View file

@ -0,0 +1,17 @@
require 'spec_helper'
RSpec.shared_examples 'not owner of dossier' do |controller, redirect|
let(:dossier_2) { create(:dossier, :with_user) }
before do
get controller, dossier_id: dossier_2.id
end
it 'redirect to home page' do
expect(response).to redirect_to(redirect || '/')
end
it 'show a flash message error' do
expect(flash[:alert]).to be_present
end
end

View file

@ -14,62 +14,62 @@ describe 'backoffice/dossiers/show.html.haml', type: :view do
assign(:commentaires, dossier.commentaires)
end
context 'sur la rendered admin du dossier' do
context 'on the dossier admin page' do
before do
render
end
it 'la section infos entreprise est présente' do
it 'enterprise informations are present' do
expect(rendered).to have_selector('#infos_entreprise')
end
it 'la section infos dossier est présente' do
it 'dossier informations are present' do
expect(rendered).to have_selector('#infos_dossier')
end
it 'le numéro de dossier est présent sur la rendered' do
it 'dossier number is present' do
expect(rendered).to have_selector('#dossier_id')
expect(rendered).to have_content(dossier_id)
end
context 'les liens de modifications sont non présent' do
it 'le lien vers carte' do
context 'edit link are present' do
it 'edit carto' do
expect(rendered).to_not have_selector('a[id=modif_carte]')
end
it 'le lien vers description' do
it 'edit description' do
expect(rendered).to_not have_selector('a[id=modif_description]')
end
it 'le bouton Editer mon dossier n\'est pas present' do
it 'Editer mon dossier button doesnt present' do
expect(rendered).to_not have_css('#maj_infos')
end
end
end
context 'gestion des etats du dossier' do
context 'when dossier have state proposed' do
context 'dossier state changements' do
context 'when dossier have state initiated' do
before do
dossier.proposed!
dossier.initiated!
render
end
it { expect(rendered).to have_content('Soumis') }
it 'button Valider le dossier est present' do
it 'button Valider le dossier is present' do
expect(rendered).to have_css('#action_button')
expect(rendered).to have_content('Valider le dossier')
end
end
context 'when dossier have state reply' do
context 'when dossier have state replied' do
before do
dossier.reply!
dossier.replied!
render
end
it { expect(rendered).to have_content('Répondu') }
it 'button Valider le dossier est present' do
it 'button Valider le dossier is present' do
expect(rendered).to have_css('#action_button')
expect(rendered).to have_content('Valider le dossier')
end
@ -83,102 +83,106 @@ describe 'backoffice/dossiers/show.html.haml', type: :view do
it { expect(rendered).to have_content('Mis à jour') }
it 'button Valider le dossier est present' do
it 'button Valider le dossier is present' do
expect(rendered).to have_css('#action_button')
expect(rendered).to have_content('Valider le dossier')
end
end
context 'when dossier have state confirmed' do
context 'when dossier have state validated' do
before do
dossier.confirmed!
dossier.validated!
render
end
it { expect(rendered).to have_content('Validé') }
it 'button Valider le dossier n\'est pas present' do
it 'button Valider le dossier is not present' do
expect(rendered).not_to have_css('#action_button')
expect(rendered).not_to have_content('Valider le dossier')
end
end
context 'when dossier have state deposited' do
context 'when dossier have state submitted' do
before do
dossier.deposited!
dossier.submitted!
render
end
it { expect(rendered).to have_content('Déposé') }
it 'button Valider le dossier n\'est pas present' do
expect(rendered).not_to have_css('#action_button')
it 'button Traiter le dossier is present' do
expect(rendered).to have_css('#action_button')
expect(rendered).to have_content('Traiter le dossier')
end
it 'button Valider le dossier is not present' do
expect(rendered).not_to have_content('Valider le dossier')
end
end
context 'when dossier have state processed' do
context 'when dossier have state closed' do
before do
dossier.processed!
dossier.closed!
render
end
it { expect(rendered).to have_content('Traité') }
it 'button Valider le dossier n\'est pas present' do
it 'button Valider le dossier is not present' do
expect(rendered).not_to have_css('#action_button')
expect(rendered).not_to have_content('Valider le dossier')
end
end
end
#TODO réactiver
# context 'la liste des pièces justificatives est présente' do
# context 'Attestation MSA' do
# let(:id_piece_justificative) { 93 }
#
# it 'la ligne de la pièce justificative est présente' do
# expect(rendered).to have_selector("tr[id=piece_justificative_#{id_piece_justificative}]")
# end
#
# it 'le bouton "Récupérer" est présent' do
# expect(rendered.find("tr[id=piece_justificative_#{id_piece_justificative}]")).to have_selector("a[href='']")
# expect(rendered.find("tr[id=piece_justificative_#{id_piece_justificative}]")).to have_content('Récupérer')
# end
# end
#
# context 'Attestation RDI' do
# let(:id_piece_justificative) { 103 }
#
# it 'la ligne de la pièce justificative est présente' do
# expect(rendered).to have_selector("tr[id=piece_justificative_#{id_piece_justificative}]")
# end
#
# it 'le libelle "Pièce manquante" est présent' do
# expect(rendered.find("tr[id=piece_justificative_#{id_piece_justificative}]")).to have_content('Pièce non fournie')
# end
# end
#
# context 'Devis' do
# let(:id_piece_justificative) { 388 }
# let(:content) { File.open('./spec/support/files/piece_justificative_388.pdf') }
#
# before do
# piece_justificative = dossier.pieces_justificatives.where(type_de_piece_justificative_id: 388).first
# piece_justificative.content = content
# piece_justificative.save!
# visit "/admin/dossiers/#{dossier_id}"
# end
#
# it 'la ligne de la pièce justificative est présente' do
# expect(rendered).to have_selector("tr[id=piece_justificative_#{id_piece_justificative}]")
# end
#
# it 'le libelle "Consulter" est présent' do
# expect(rendered.find("tr[id=piece_justificative_#{id_piece_justificative}] a")[:href]).to have_content('piece_justificative_388.pdf')
# expect(rendered.find("tr[id=piece_justificative_#{id_piece_justificative}]")).to have_content('Consulter')
# end
# end
# end
#
#TODO réactiver
# context 'la liste des pièces justificatives est présente' do
# context 'Attestation MSA' do
# let(:id_piece_justificative) { 93 }
#
# it 'la ligne de la pièce justificative est présente' do
# expect(rendered).to have_selector("tr[id=piece_justificative_#{id_piece_justificative}]")
# end
#
# it 'le bouton "Récupérer" est présent' do
# expect(rendered.find("tr[id=piece_justificative_#{id_piece_justificative}]")).to have_selector("a[href='']")
# expect(rendered.find("tr[id=piece_justificative_#{id_piece_justificative}]")).to have_content('Récupérer')
# end
# end
#
# context 'Attestation RDI' do
# let(:id_piece_justificative) { 103 }
#
# it 'la ligne de la pièce justificative est présente' do
# expect(rendered).to have_selector("tr[id=piece_justificative_#{id_piece_justificative}]")
# end
#
# it 'le libelle "Pièce manquante" est présent' do
# expect(rendered.find("tr[id=piece_justificative_#{id_piece_justificative}]")).to have_content('Pièce non fournie')
# end
# end
#
# context 'Devis' do
# let(:id_piece_justificative) { 388 }
# let(:content) { File.open('./spec/support/files/piece_justificative_388.pdf') }
#
# before do
# piece_justificative = dossier.pieces_justificatives.where(type_de_piece_justificative_id: 388).first
# piece_justificative.content = content
# piece_justificative.save!
# visit "/admin/dossiers/#{dossier_id}"
# end
#
# it 'la ligne de la pièce justificative est présente' do
# expect(rendered).to have_selector("tr[id=piece_justificative_#{id_piece_justificative}]")
# end
#
# it 'le libelle "Consulter" est présent' do
# expect(rendered.find("tr[id=piece_justificative_#{id_piece_justificative}] a")[:href]).to have_content('piece_justificative_388.pdf')
# expect(rendered.find("tr[id=piece_justificative_#{id_piece_justificative}]")).to have_content('Consulter')
# end
# end
# end
#
end

View file

@ -8,7 +8,7 @@ describe 'backoffice/index.html.haml', type: :view do
assign(:dossiers_en_attente, Dossier.en_attente.decorate)
assign(:dossiers_termine, Dossier.termine.decorate)
decorate_dossier.proposed!
decorate_dossier.initiated!
render
end
subject { rendered }

View file

@ -1,14 +1,22 @@
require 'spec_helper'
describe 'dossiers/_infos_dossier.html.haml', type: :view do
let(:dossier) { create(:dossier, :with_entreprise, :with_procedure) }
let(:maj_infos) { 'Mettre à jour les informations' }
let(:proposer) { 'Soumettre mon dossier' }
let(:dossier) { create(:dossier, :with_entreprise, :with_procedure, :with_user) }
before do
assign(:dossier, dossier.decorate)
assign(:commentaires, dossier.commentaires)
assign(:champs, dossier.ordered_champs)
assign(:procedure, dossier.procedure)
render
end
describe 'every champs are present on the page' do
let(:champs) { dossier.champs }
it { expect(rendered).to have_content(champs.first.libelle) }
it { expect(rendered).to have_content(champs.first.value) }
it { expect(rendered).to have_content(champs.last.libelle) }
it { expect(rendered).to have_content(champs.last.value) }
end
end

View file

@ -46,7 +46,7 @@ describe 'users/carte/show.html.haml', type: :view do
end
context 'si la page précédente est recapitularif' do
let(:state) { 'proposed' }
let(:state) { 'initiated' }
it 'le bouton "Etape suivante" n\'est pas présent' do
expect(rendered).to_not have_selector('#etape_suivante')

View file

@ -8,6 +8,7 @@ describe 'users/description/show.html.haml', type: :view do
before do
assign(:dossier, dossier)
assign(:procedure, dossier.procedure)
assign(:champs, dossier.ordered_champs)
end
context 'tous les attributs sont présents sur la page' do
@ -26,30 +27,6 @@ describe 'users/description/show.html.haml', type: :view do
expect(rendered).to have_selector('textarea[id=description][name=description]')
end
it 'Montant du projet' do
expect(rendered).to have_selector('input[id=montant_projet][name=montant_projet]')
end
it 'Montant du projet est de type number' do
expect(rendered).to have_selector('input[type=number][id=montant_projet]')
end
it 'Montant des aides du projet' do
expect(rendered).to have_selector('input[id=montant_aide_demande][name=montant_aide_demande]')
end
it 'Montant des aides du projet est de type number' do
expect(rendered).to have_selector('input[type=number][id=montant_aide_demande]')
end
it 'Date prévisionnelle du projet' do
expect(rendered).to have_selector('input[id=date_previsionnelle][name=date_previsionnelle]')
end
it 'Date prévisionnelle du projet est de type text avec un data-provide=datepicker' do
expect(rendered).to have_selector('input[type=text][id=date_previsionnelle][data-provide=datepicker]')
end
it 'Charger votre CERFA (PDF)' do
expect(rendered).to have_selector('input[type=file][name=cerfa_pdf][id=cerfa_pdf]')
end
@ -70,7 +47,7 @@ describe 'users/description/show.html.haml', type: :view do
context 'si la page précédente est recapitularif' do
before do
dossier.proposed!
dossier.initiated!
dossier.reload
render
end
@ -93,9 +70,6 @@ describe 'users/description/show.html.haml', type: :view do
create(:dossier, :with_procedure,
nom_projet: 'Projet de test',
description: 'Description de test',
montant_projet: 12_000,
montant_aide_demande: 3000,
date_previsionnelle: '20/01/2016',
user: user)
end
@ -103,7 +77,6 @@ describe 'users/description/show.html.haml', type: :view do
render
end
it 'Nom du projet' do
expect(rendered).to have_selector("input[id=nom_projet][value='#{dossier.nom_projet}']")
end
@ -111,17 +84,25 @@ describe 'users/description/show.html.haml', type: :view do
it 'Description du projet' do
expect(rendered).to have_content("#{dossier.description}")
end
end
it 'Montant du projet' do
expect(rendered).to have_selector("input[id=montant_projet][value='#{dossier.montant_projet}']")
context 'Champs' do
let(:champs) { dossier.champs }
before do
render
end
it 'Montant des aides du projet' do
expect(rendered).to have_selector("input[id=montant_aide_demande][value='#{dossier.montant_aide_demande}']")
describe 'first champs' do
subject { dossier.champs.first }
it { expect(rendered).to have_css(".type_champs-#{subject.type_champs}") }
it { expect(rendered).to have_css("#champs_#{subject.id}") }
end
it 'Date prévisionnelle du projet' do
expect(rendered).to have_selector("#date_previsionnelle", dossier.date_previsionnelle)
describe 'last champs' do
subject { dossier.champs.last }
it { expect(rendered).to have_css(".type_champs-#{subject.type_champs}") }
it { expect(rendered).to have_css("#champs_#{subject.id}") }
end
end
@ -140,7 +121,7 @@ describe 'users/description/show.html.haml', type: :view do
context 'la liste des pièces récupérées automatiquement est signaliée' do
it 'Attestation MSA' do
expect(rendered).to have_selector("#piece_justificative_#{all_type_pj_procedure_id[1]}","Nous l'avons récupéré pour vous.")
expect(rendered).to have_selector("#piece_justificative_#{all_type_pj_procedure_id[1]}", "Nous l'avons récupéré pour vous.")
end
end
end

View file

@ -55,18 +55,18 @@ describe 'users/recapitulatif/show.html.haml', type: :view do
end
end
context 'when dossier state is proposed' do
context 'when dossier state is initiated' do
before do
dossier.proposed!
dossier.initiated!
render
end
it { expect(rendered).to have_content('Soumis') }
end
context 'when dossier state is reply' do
context 'when dossier state is replied' do
before do
dossier.reply!
dossier.replied!
render
end
@ -83,9 +83,9 @@ describe 'users/recapitulatif/show.html.haml', type: :view do
it { expect(rendered).to have_content('Mis à jour') }
end
context 'when dossier state is confirmed' do
context 'when dossier state is validated' do
before do
dossier.confirmed!
dossier.validated!
render
end
@ -100,9 +100,9 @@ describe 'users/recapitulatif/show.html.haml', type: :view do
end
end
context 'when dossier state is deposited' do
context 'when dossier state is submitted' do
before do
dossier.deposited!
dossier.submitted!
render
end
@ -116,7 +116,7 @@ describe 'users/recapitulatif/show.html.haml', type: :view do
context 'when dossier state is traité' do
before do
dossier.processed!
dossier.closed!
render
end
it { expect(rendered).to have_content('Traité') }