Merge branch 'develop' of ssh://37.187.249.111:2200/opt/git/tps into develop

Conflicts:
	app/views/users/recapitulatif/show.html.haml
	spec/features/recapitulatif_page/_commentaires_flux_spec.rb
	spec/features/recapitulatif_page/show_page_spec.rb
This commit is contained in:
Xavier J 2015-09-24 10:56:12 +02:00
commit 8693f4194c
80 changed files with 1414 additions and 382 deletions

View file

@ -59,6 +59,8 @@ gem 'chartkick'
gem 'logstasher'
gem "font-awesome-rails"
group :test do
gem 'capybara'
gem 'factory_girl'

View file

@ -114,6 +114,8 @@ GEM
faraday (0.9.1)
multipart-post (>= 1.2, < 3)
ffi (1.9.6)
font-awesome-rails (4.4.0.0)
railties (>= 3.2, < 5.0)
globalid (0.3.5)
activesupport (>= 4.1.0)
haml (4.0.6)
@ -339,6 +341,7 @@ DEPENDENCIES
devise
draper
factory_girl
font-awesome-rails
haml-rails
jbuilder (~> 2.0)
jquery-rails
@ -372,3 +375,6 @@ DEPENDENCIES
unicorn
web-console (~> 2.0)
webmock
BUNDLED WITH
1.10.4

View file

@ -16,6 +16,7 @@
*= require_self
*= require bootstrap-datepicker3
*= require leaflet
*= require font-awesome
*/
@import "bootstrap-sprockets";
@import "bootstrap";

View file

@ -14,12 +14,8 @@ class Backoffice::DossiersController < ApplicationController
@dossier = @dossier.decorate
rescue ActiveRecord::RecordNotFound
redirect_start
flash.alert = t('errors.messages.dossier_not_found')
redirect_to url_for(controller: '/backoffice')
end
private
def redirect_start
redirect_to url_for(controller: '/start', action: :error_dossier)
end
end

View file

@ -4,7 +4,7 @@ class CarteController < ApplicationController
def show
@dossier = current_dossier
rescue ActiveRecord::RecordNotFound
redirect_to url_for(controller: :start, action: :error_dossier)
redirect_to url_for(controller: :siret, action: :error_dossier)
end
def save_ref_api_carto

View file

@ -1,69 +1,73 @@
class DossiersController < ApplicationController
def show
@dossier = Dossier.find(params[:id])
# def show
# @dossier = Dossier.find(params[:id])
@etablissement = @dossier.etablissement
@entreprise = @dossier.entreprise.decorate
rescue ActiveRecord::RecordNotFound
redirect_to url_for(controller: :start, action: :error_dossier)
end
def create
@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.find(params['procedure_id'])
@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
redirect_to url_for(controller: :start, action: :error_siret, procedure_id: params['procedure_id'])
rescue ActiveRecord::RecordNotFound
redirect_to url_for(controller: :start, action: :error_dossier)
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
# @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

@ -1,37 +0,0 @@
class StartController < ApplicationController
def index
get_procedure_infos
if @procedure.nil?
error_procedure
end
rescue ActiveRecord::RecordNotFound
error_procedure
end
def error_procedure
render :file => "#{Rails.root}/public/404_procedure_not_found.html", :status => 404
end
def error_siret
get_procedure_infos
flash.now.alert = 'Ce SIRET n\'est pas valide'
render 'index'
end
def error_login
flash.now.alert = 'Ce compte n\'existe pas'
render 'index'
end
def error_dossier
flash.now.alert = 'Ce dossier n\'existe pas'
render 'index'
end
private
def get_procedure_infos
@procedure = Procedure.find(params['procedure_id'])
end
end

View file

@ -0,0 +1,3 @@
class Users::CommentairesController < CommentairesController
end

View file

@ -0,0 +1,28 @@
class Users::ConfirmationsController < Devise::ConfirmationsController
# GET /resource/confirmation/new
# def new
# super
# end
# POST /resource/confirmation
# def create
# super
# end
# GET /resource/confirmation?confirmation_token=abcdef
# def show
# super
# end
# protected
# The path used after resending confirmation instructions.
# def after_resending_confirmation_instructions_path_for(resource_name)
# super(resource_name)
# end
# The path used after confirmation.
# def after_confirmation_path_for(resource_name, resource)
# super(resource_name, resource)
# end
end

View file

@ -1,4 +1,4 @@
class DescriptionController < ApplicationController
class Users::DescriptionController < ApplicationController
def show
@dossier = Dossier.find(params[:dossier_id])
@dossier = @dossier.decorate
@ -6,7 +6,8 @@ class DescriptionController < ApplicationController
@procedure = @dossier.procedure
rescue ActiveRecord::RecordNotFound
redirect_to url_for(controller: :start, action: :error_dossier)
flash.alert = t('errors.messages.dossier_not_found')
redirect_to url_for(controller: :siret)
end
def error

View file

@ -0,0 +1,79 @@
class Users::DossiersController < UsersController
before_action :authenticate_user!
def index
@dossiers = Dossier.all.decorate
end
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,28 @@
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
# You should configure your model like this:
# devise :omniauthable, omniauth_providers: [:twitter]
# You should also create an action method in this controller like this:
# def twitter
# end
# More info at:
# https://github.com/plataformatec/devise#omniauth
# GET|POST /resource/auth/twitter
# def passthru
# super
# end
# GET|POST /users/auth/twitter/callback
# def failure
# super
# end
# protected
# The path used when omniauth fails
# def after_omniauth_failure_path_for(scope)
# super(scope)
# end
end

View file

@ -0,0 +1,32 @@
class Users::PasswordsController < Devise::PasswordsController
# GET /resource/password/new
# def new
# super
# end
# POST /resource/password
# def create
# super
# end
# GET /resource/password/edit?reset_password_token=abcdef
# def edit
# super
# end
# PUT /resource/password
# def update
# super
# end
# protected
# def after_resetting_password_path_for(resource)
# super(resource)
# end
# The path used after sending reset password instructions
# def after_sending_reset_password_instructions_path_for(resource_name)
# super(resource_name)
# end
end

View file

@ -1,5 +1,6 @@
class RecapitulatifController < ApplicationController
class Users::RecapitulatifController < UsersController
def show
@dossier = Dossier.find(params[:dossier_id])
@dossier = @dossier.decorate
@procedure = @dossier.procedure
@ -12,6 +13,7 @@ class RecapitulatifController < ApplicationController
#TODO load user email
@commentaire_email = 'user@email'
rescue ActiveRecord::RecordNotFound
redirect_to url_for(controller: :start, action: :error_dossier)
flash.alert = t('errors.messages.dossier_not_found')
redirect_to url_for(controller: :siret)
end
end

View file

@ -0,0 +1,60 @@
class Users::RegistrationsController < Devise::RegistrationsController
# before_filter :configure_sign_up_params, only: [:create]
# before_filter :configure_account_update_params, only: [:update]
# GET /resource/sign_up
# def new
# super
# end
# POST /resource
# def create
# super
# end
# GET /resource/edit
# def edit
# super
# end
# PUT /resource
# def update
# super
# end
# DELETE /resource
# def destroy
# super
# end
# GET /resource/cancel
# Forces the session data which is usually expired after sign
# in to be expired now. This is useful if the user wants to
# cancel oauth signing in/up in the middle of the process,
# removing all OAuth session data.
# def cancel
# super
# end
# protected
# You can put the params you want to permit in the empty array.
# def configure_sign_up_params
# devise_parameter_sanitizer.for(:sign_up) << :attribute
# end
# You can put the params you want to permit in the empty array.
# def configure_account_update_params
# devise_parameter_sanitizer.for(:account_update) << :attribute
# end
# The path used after sign up.
# def after_sign_up_path_for(resource)
# super(resource)
# end
# The path used after sign up for inactive accounts.
# def after_inactive_sign_up_path_for(resource)
# super(resource)
# end
end

View file

@ -0,0 +1,25 @@
class Users::SessionsController < Devise::SessionsController
# before_filter :configure_sign_in_params, only: [:create]
# GET /resource/sign_in
# def new
# super
# end
# POST /resource/sign_in
# def create
# super
# end
# DELETE /resource/sign_out
# def destroy
# super
# end
# protected
# You can put the params you want to permit in the empty array.
# def configure_sign_in_params
# devise_parameter_sanitizer.for(:sign_in) << :attribute
# end
end

View file

@ -0,0 +1,11 @@
class Users::SiretController < UsersController
def index
@procedure = Procedure.find(params['procedure_id'])
rescue ActiveRecord::RecordNotFound
error_procedure
end
def error_procedure
render :file => "#{Rails.root}/public/404_procedure_not_found.html", :status => 404
end
end

View file

@ -0,0 +1,28 @@
class Users::UnlocksController < Devise::UnlocksController
# GET /resource/unlock/new
# def new
# super
# end
# POST /resource/unlock
# def create
# super
# end
# GET /resource/unlock?unlock_token=abcdef
# def show
# super
# end
# protected
# The path used after sending unlock password instructions
# def after_sending_unlock_instructions_path_for(resource)
# super(resource)
# end
# The path used after unlocking the resource
# def after_unlock_path_for(resource)
# super(resource)
# end
end

View file

@ -0,0 +1,3 @@
class UsersController < ApplicationController
before_action :authenticate_user!
end

View file

@ -12,6 +12,7 @@ class Dossier < ActiveRecord::Base
has_one :cerfa
has_many :pieces_justificatives
belongs_to :procedure
belongs_to :user
has_many :commentaires
delegate :siren, to: :entreprise

8
app/models/user.rb Normal file
View file

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

View file

@ -16,7 +16,7 @@
=render partial: '/dossiers/pieces_justificatives'
%br
= render partial: '/recapitulatif/commentaires_flux'
= render partial: '/users/recapitulatif/commentaires_flux'
%br
%br

View file

@ -0,0 +1,13 @@
.container#recap_info_entreprise
%h2 Récapitulatif de vos informations <em id="insee_infogreffe" class='small'>(récupérées auprès de l'INSEE et d'INFOGREFFE)</em>
%br
%div.row
= render partial: '/dossiers/infos_entreprise'
%br
= form_for @dossier, url: { controller: '/users/dossiers', action: :update } do |f|
%label{ style:'font-weight:normal' }
= f.check_box :autorisation_donnees
J'autorise les organismes publics à vérifier les informations de mon entreprise auprès des administrations concernées. Ces informations resteront strictement confidentielles.
%br
= f.submit 'Etape suivante', class: "btn btn btn-info", style: 'float:right', id: 'etape_suivante'

View file

@ -1,13 +1 @@
.container
%h2 Récapitulatif de vos informations <em id="insee_infogreffe" class='small'>(récupérées auprès de l'INSEE et d'INFOGREFFE)</em>
%br
%div.row
= render partial: 'infos_entreprise'
%br
= form_for @dossier do |f|
%label{ style:'font-weight:normal' }
= f.check_box :autorisation_donnees
J'autorise les organismes publics à vérifier les informations de mon entreprise auprès des administrations concernées. Ces informations resteront strictement confidentielles.
%br
= f.submit 'Etape suivante', class: "btn btn btn-info", style: 'float:right', id: 'etape_suivante'
= render partial: 'show'

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 user_signed_in?
%div.user{style: 'decorate:none; box-shadow:none; float:right; margin-top:8px'}
%i.fa.fa-user
= current_user.email
= link_to "Déconnexion", '/users/sign_out', method: :delete, :class => 'btn btn-md'
#flash_message.center
- if flash.notice

View file

@ -1,24 +0,0 @@
/ %p.lead{id: 'admin_section'}
/ %span{class:'text-info', style:'font-weight:bold'}
/ -if user_signed_in?
/ ='Vous êtes identifié comme une administration'
/ -else
/ ='Si vous êtes une administration, '
/ %p.lead
/ -if user_signed_in?
/ = form_tag(url_for({controller: 'admin/dossier', action: :index}), class: 'form-inline', method: 'GET') do
/ .form-group.form-group-lg
/ = text_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "N° de dossier", :id => "dossier_id", :name => "dossier_id"
/ %br
/ = submit_tag "Accéder", class: %w(btn btn-lg btn-success), style: 'margin-top:20px;', data: { disable_with: "Accéder", submit: true}
/ -else
/ = form_tag(url_for({controller: 'user/sessions', action: :create}), class: 'form-inline', method: 'POST') do
/ .form-group.form-group-lg
/ = text_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "Identifiant", :id => "user_email", :name => "user[email]"
/ %br
/ = password_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "Mot de passe", :id => "user_password", :name => "user[password]"
/ %br
/ = text_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "N° de dossier", :id => "dossier_id", :name => "dossier_id"
/ %br
/ = submit_tag "Accéder", class: %w(btn btn-lg btn-success), style: 'margin-top:20px;', data: { disable_with: "Accéder", submit: true}

View file

@ -0,0 +1,16 @@
<h2>Resend confirmation instructions</h2>
<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="actions">
<%= f.submit "Resend confirmation instructions" %>
</div>
<% end %>
<%= render "users/shared/links" %>

View file

@ -0,0 +1,10 @@
%h1 Vos dossiers :
%table.table
%thead
%th Nom du Projet
%th Mise à jour
- @dossiers.each do |dossier|
%tr
%td= dossier.nom_projet
%td= dossier.last_update

View file

@ -0,0 +1 @@
= render partial: '/dossiers/show'

View file

@ -0,0 +1,5 @@
<p>Welcome <%= @email %>!</p>
<p>You can confirm your account email through the link below:</p>
<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>

View file

@ -0,0 +1,8 @@
<p>Hello <%= @resource.email %>!</p>
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>

View file

@ -0,0 +1,7 @@
<p>Hello <%= @resource.email %>!</p>
<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>
<p>Click the link below to unlock your account:</p>
<p><%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %></p>

View file

@ -0,0 +1,22 @@
<h2>Change your password</h2>
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %>
<%= devise_error_messages! %>
<%= f.hidden_field :reset_password_token %>
<div class="field">
<%= f.label :password, "New password" %><br />
<%= f.password_field :password, autofocus: true, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation, "Confirm new password" %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Change my password" %>
</div>
<% end %>
<%= render "users/shared/links" %>

View file

@ -0,0 +1,16 @@
<h2>Forgot your password?</h2>
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="actions">
<%= f.submit "Send me reset password instructions" %>
</div>
<% end %>
<%= render "users/shared/links" %>

View file

@ -0,0 +1,25 @@
%div.row#recap_dossier
%div.col-md-2.col-lg-2
%h2
='Récapitulatif'
%div.col-md-8.col-lg-8
%div.col-md-2.col-lg-2
%h2#dossier_id{:class => 'text-info', :style => 'text-align:right; margin-bottom:15px'}
= "Dossier n°#{@dossier.id}"
-#%h3{:class => 'text-success', :style => 'text-align:right'}
-# = @dossier.state_fr
- unless gestionnaire_signed_in?
%button#action_button.btn.btn-success
= 'Soumettre mon dossier'
%div{style: 'text-align:center'}
-if (request.referer != nil) && (request.referer.include?'/description') && !(request.referer.include?'back_url=recapitulatif')
%h3.text-success Félicitation, votre demande a bien été enregistrée.
%br
= render partial: '/dossiers/infos_dossier'
%br
= render partial: 'commentaires_flux'

View file

@ -0,0 +1,29 @@
<<<<<<< HEAD:app/views/recapitulatif/show.html.haml
%div.row
%div.col-md-2.col-lg-2
%h2
='Récapitulatif'
=======
%h2#recap_dossier Récapitulatif
>>>>>>> 6eeac88c95dce079195f596e05a7e652fd9720c9:app/views/users/recapitulatif/show.html.haml
%div.col-md-8.col-lg-8
%div.col-md-2.col-lg-2
%h2#dossier_id{:class => 'text-info', :style => 'text-align:right; margin-bottom:15px'}
= "Dossier n°#{@dossier.id}"
-#%h3{:class => 'text-success', :style => 'text-align:right'}
-# = @dossier.state_fr
- unless gestionnaire_signed_in?
%button#action_button.btn.btn-success
= 'Soumettre mon dossier'
%div{style: 'text-align:center'}
-if (request.referer != nil) && (request.referer.include?'/description') && !(request.referer.include?'back_url=recapitulatif')
%h3.text-success Félicitation, votre demande a bien été enregistrée.
%br
= render partial: '/dossiers/infos_dossier'
%br
= render partial: 'commentaires_flux'

View file

@ -0,0 +1,24 @@
%h2
='Récapitulatif'
%div{style: 'text-align:center'}
-if request.referer != nil
-if (request.referer.include?'/description') && !(request.referer.include?'back_url=recapitulatif')
%h4.text-success Félicitation, votre demande a bien été enregistrée.
%h3{style: 'text-align:center; line-height:1.5em'}
='Votre dossier est le '
%br
%span{id: 'dossier_id', style: 'font-weight:bold;', class: 'text-success'}
="n°#{@dossier.id}"
-else
%h2#dossier_id{:class => 'text-info', :style => 'text-align:right'}
= "Dossier n°#{@dossier.id}"
-else
%h2#dossier_id{:class => 'text-info', :style => 'text-align:right'}
= "Dossier n°#{@dossier.id}"
= render partial: '/dossiers/infos_dossier'
%br
= render partial: 'commentaires_flux'

View file

@ -0,0 +1,23 @@
%h2#recap_dossier Récapitulatif
%div{style: 'text-align:center'}
-if request.referer != nil
-if (request.referer.include?'/description') && !(request.referer.include?'back_url=recapitulatif')
%h4.text-success Félicitation, votre demande a bien été enregistrée.
%h3{style: 'text-align:center; line-height:1.5em'}
='Votre dossier est le '
%br
%span{id: 'dossier_id', style: 'font-weight:bold;', class: 'text-success'}
="n°#{@dossier.id}"
-else
%h2#dossier_id{:class => 'text-info', :style => 'text-align:right'}
= "Dossier n°#{@dossier.id}"
-else
%h2#dossier_id{:class => 'text-info', :style => 'text-align:right'}
= "Dossier n°#{@dossier.id}"
= render partial: '/dossiers/infos_dossier'
%br
= render partial: 'commentaires_flux'

View file

@ -0,0 +1,39 @@
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
<% end %>
<div class="field">
<%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Update" %>
</div>
<% end %>
<h3>Cancel my account</h3>
<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p>
<%= link_to "Back", :back %>

View file

@ -0,0 +1,29 @@
<h2>Sign up</h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="field">
<%= f.label :password %>
<% if @validatable %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Sign up" %>
</div>
<% end %>
<%= render "users/shared/links" %>

View file

@ -0,0 +1,19 @@
%h2#login_user Connexion
= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f|
.field
= f.label :email
%br
= f.email_field :email, autofocus: true
.field
= f.label :password
%br
= f.password_field :password, autocomplete: "off"
%br
/ - if devise_mapping.rememberable?
/ .field
/ = f.check_box :remember_me
/ = f.label :remember_me
.actions
= f.submit "Se connecter"
= render "users/shared/links"

View file

@ -0,0 +1,25 @@
<%- if controller_name != 'sessions' %>
<%= link_to "Log in", new_session_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
<%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br />
<% end -%>
<% end -%>

View file

@ -5,5 +5,5 @@
Site de démonstration dun service public de saisie dun projet ou de dépôt dune démarche administrative, auprès dun ou plusieurs organismes publics, simplifié des informations déjà connues des administrations, grâce à la fourniture du numéro SIRET.
.row
= render partial: '/start/pro'
= render partial: 'pro'

View file

@ -0,0 +1,16 @@
<h2>Resend unlock instructions</h2>
<%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="actions">
<%= f.submit "Resend unlock instructions" %>
</div>
<% end %>
<%= render "users/shared/links" %>

View file

@ -78,5 +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"
invalid_siret: "Le siret est incorrect"

View file

@ -1,33 +1,48 @@
Rails.application.routes.draw do
devise_for :users, controllers: {
sessions: 'users/sessions'
}
devise_for :gestionnaires, controllers: {
sessions: 'gestionnaires/sessions'
}, skip: [:password, :registrations]
root 'start#index'
get 'start/index'
get 'start/error_siret'
get 'start/error_login'
get 'start/error_dossier'
# root 'welcome#index'
root 'users/dossiers#index'
namespace :users do
get 'siret' => 'siret#index'
resources :dossiers do
get '/demande' => 'demandes#show'
post '/demande' => 'demandes#update'
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'
get '/recapitulatif' => 'recapitulatif#show'
get '/demande' => 'demandes#show'
post '/demande' => 'demandes#update'
post '/commentaire' => 'commentaires#create'
end
resource :dossiers
end
# 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
get 'backoffice' => 'backoffice#index'

View file

@ -0,0 +1,42 @@
class CreateUsers < ActiveRecord::Migration
def change
create_table(:users) 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 :users, :email, unique: true
add_index :users, :reset_password_token, unique: true
# add_index :users, :confirmation_token, unique: true
# add_index :users, :unlock_token, unique: true
end
end

View file

@ -0,0 +1,6 @@
class AddUserToDossier < ActiveRecord::Migration
def change
add_reference :dossiers, :user, index: true
add_foreign_key :dossiers, :users
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150922141000) do
ActiveRecord::Schema.define(version: 20150923101000) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -47,9 +47,11 @@ ActiveRecord::Schema.define(version: 20150922141000) do
t.datetime "created_at"
t.datetime "updated_at"
t.string "state"
t.integer "user_id"
end
add_index "dossiers", ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree
add_index "dossiers", ["user_id"], name: "index_dossiers_on_user_id", using: :btree
create_table "entreprises", force: :cascade do |t|
t.string "siren"
@ -130,6 +132,25 @@ ActiveRecord::Schema.define(version: 20150922141000) do
t.integer "procedure_id"
end
create_table "users", 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 "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
add_foreign_key "cerfas", "dossiers"
add_foreign_key "commentaires", "dossiers"
add_foreign_key "dossiers", "users"
end

View file

@ -19,7 +19,7 @@ describe Backoffice::DossiersController, type: :controller do
it "le numéro de dossier n'existe pas" do
get :show, id: bad_dossier_id
expect(response).to redirect_to('/start/error_dossier')
expect(response).to redirect_to('/backoffice')
end
end

View file

@ -1,6 +1,6 @@
require 'spec_helper'
describe CommentairesController, type: :controller do
describe Users::CommentairesController, type: :controller do
let(:dossier) { create(:dossier) }
let(:dossier_id) { dossier.id }
let(:email_commentaire) { 'test@test.com' }
@ -10,7 +10,7 @@ describe CommentairesController, type: :controller do
context 'création correct d\'un commentaire' do
it 'depuis la page récapitulatif' do
post :create, dossier_id: dossier_id, email_commentaire: email_commentaire, texte_commentaire: texte_commentaire
expect(response).to redirect_to("/dossiers/#{dossier_id}/recapitulatif")
expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif")
end
end
end

View file

@ -1,6 +1,6 @@
require 'spec_helper'
describe DescriptionController, type: :controller do
describe Users::DescriptionController, type: :controller do
let(:dossier) { create(:dossier, :with_procedure) }
let(:dossier_id) { dossier.id }
let(:bad_dossier_id) { Dossier.count + 10 }
@ -13,7 +13,7 @@ describe 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: :start, action: :error_dossier)
expect(response).to redirect_to(controller: :siret)
end
end
@ -37,7 +37,7 @@ describe DescriptionController, type: :controller do
# TODO separer en deux tests : check donnees et check redirect
it 'Premier enregistrement des données' 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
expect(response).to redirect_to("/dossiers/#{dossier_id}/recapitulatif")
expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif")
end
# TODO changer les valeurs des champs et check in bdd
@ -63,7 +63,7 @@ describe DescriptionController, type: :controller do
end
it 'Redirection vers la page récapitulatif' do
expect(response).to redirect_to("/dossiers/#{dossier_id}/recapitulatif")
expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif")
end
end
end

View file

@ -1,119 +1,124 @@
require 'spec_helper'
RSpec.describe DossiersController, type: :controller do
let(:dossier) { create(:dossier, :with_entreprise, :with_procedure) }
let(:dossier_id) { dossier.id }
let(:siret_not_found) { 999_999_999_999 }
describe DossiersController, type: :controller do
# let(:dossier) { create(:dossier, :with_entreprise, :with_procedure) }
# let(:procedure) { create(:procedure) }
# let(:dossier_id) { dossier.id }
# let(:siret_not_found) { 999_999_999_999 }
let(:siren) { dossier.siren }
let(:siret) { dossier.siret }
let(:bad_siret) { 1 }
# let(:siren) { dossier.siren }
# let(:siret) { dossier.siret }
# let(:bad_siret) { 1 }
describe 'GET #show' do
it 'returns http success with dossier_id valid' do
get :show, id: dossier_id
expect(response).to have_http_status(:success)
end
# describe 'GET #show' do
# it 'returns http success with dossier_id valid' do
# get :show, id: dossier_id
# expect(response).to have_http_status(:success)
# end
it 'redirection vers start si mauvais dossier ID' do
get :show, id: siret_not_found
expect(response).to redirect_to('/start/error_dossier')
end
end
# it 'redirection vers siret si mauvais dossier ID' do
# get :show, id: siret_not_found
# expect(response).to redirect_to('/siret')
# end
# end
describe 'POST #create' do
before do
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret_not_found}?token=#{SIADETOKEN}")
.to_return(status: 404, body: 'fake body')
# describe 'POST #create' do
# before do
# stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret_not_found}?token=#{SIADETOKEN}")
# .to_return(status: 404, body: 'fake body')
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/etablissement.json'))
# stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret}?token=#{SIADETOKEN}")
# .to_return(status: 200, body: File.read('spec/support/files/etablissement.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
end
# stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}")
# .to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
# end
describe 'professionnel fills form' do
context 'when pro_dossier_id is empty' do
context 'with valid siret ' do
before do
post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last
end
# describe 'professionnel fills form' do
# context 'when pro_dossier_id is empty' do
# context 'with valid siret ' do
it 'create a dossier' do
expect { post :create, siret: siret, pro_dossier_id: '' }.to change { Dossier.count }.by(1)
end
# subject { post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last }
it 'creates entreprise' do
expect { post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last }.to change { Entreprise.count }.by(1)
end
it 'links entreprise to dossier' do
expect(Entreprise.last.dossier).to eq(Dossier.last)
end
# it 'create a dossier' do
# expect { subject }.to change { Dossier.count }.by(1)
# end
it 'creates etablissement for dossier' do
expect { post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last }.to change { Etablissement.count }.by(1)
end
# it 'creates entreprise' do
# expect { subject }.to change { Entreprise.count }.by(1)
# end
it 'links etablissement to dossier' do
expect(Etablissement.last.dossier).to eq(Dossier.last)
end
# it 'links entreprise to dossier' do
# expect(Entreprise.last.dossier).to eq(Dossier.last)
# end
it 'links etablissement to entreprise' do
expect(Etablissement.last.entreprise).to eq(Entreprise.last)
end
# it 'creates etablissement for dossier' do
# expect { subject }.to change { Etablissement.count }.by(1)
# end
it 'links procedure to dossier' do
expect(Dossier.last.procedure).to eq(Procedure.last)
end
# it 'links etablissement to dossier' do
# subject
# expect(Etablissement.last.dossier).to eq(Dossier.last)
# end
it 'state of dossier is draft' do
expect(Dossier.last.state).to eq('draft')
end
end
# it 'links etablissement to entreprise' do
# subject
# expect(Etablissement.last.entreprise).to eq(Entreprise.last)
# end
context 'with non existant siret' do
let(:siret_not_found) { '11111111111111' }
subject { post :create, siret: siret_not_found, pro_dossier_id: '' }
it 'does not create new dossier' do
expect { subject }.not_to change { Dossier.count }
end
# it 'links procedure to dossier' do
# subject
# expect(Dossier.last.procedure).to eq(Procedure.last)
# end
it 'redirects to show' do
expect(subject).to redirect_to(controller: :start, action: :error_siret)
end
end
end
end
end
# it 'state of dossier is draft' do
# subject
# expect(Dossier.last.state).to eq('draft')
# end
# end
describe 'PUT #update' do
before do
put :update, id: dossier_id, dossier: { autorisation_donnees: autorisation_donnees }
end
context 'when Checkbox is checked' do
let(:autorisation_donnees) { '1' }
it 'redirects to demande' do
expect(response).to redirect_to(controller: :description, action: :show, dossier_id: dossier.id)
end
# context 'with non existant siret' do
# let(:siret_not_found) { '11111111111111' }
# subject { post :create, siret: siret_not_found, pro_dossier_id: '', procedure_id: procedure.id }
# it 'does not create new dossier' do
# expect { subject }.not_to change { Dossier.count }
# end
it 'update dossier' do
dossier.reload
expect(dossier.autorisation_donnees).to be_truthy
end
end
# it 'redirects to show' do
# expect(subject).to redirect_to(controller: :siret, procedure_id: procedure.id)
# end
# end
# end
# end
# end
context 'when Checkbox is not checked' do
let(:autorisation_donnees) { '0' }
it 'uses flash alert to display message' do
expect(flash[:alert]).to have_content('Les conditions sont obligatoires.')
end
# describe 'PUT #update' do
# before do
# put :update, id: dossier_id, dossier: { autorisation_donnees: autorisation_donnees }
# end
# context 'when Checkbox is checked' do
# let(:autorisation_donnees) { '1' }
# it 'redirects to demande' do
# expect(response).to redirect_to(controller: :description, action: :show, dossier_id: dossier.id)
# end
it "doesn't update dossier autorisation_donnees" do
dossier.reload
expect(dossier.autorisation_donnees).to be_falsy
end
end
end
# it 'update dossier' do
# dossier.reload
# expect(dossier.autorisation_donnees).to be_truthy
# end
# end
# context 'when Checkbox is not checked' do
# let(:autorisation_donnees) { '0' }
# it 'uses flash alert to display message' do
# expect(flash[:alert]).to have_content('Les conditions sont obligatoires.')
# end
# it "doesn't update dossier autorisation_donnees" do
# dossier.reload
# expect(dossier.autorisation_donnees).to be_falsy
# end
# end
# end
end

View file

@ -1,19 +0,0 @@
require 'spec_helper'
RSpec.describe RecapitulatifController, type: :controller do
let(:dossier) { create(:dossier) }
let(:bad_dossier_id) { Dossier.count + 10 }
describe 'GET #show' do
it 'returns http success' do
get :show, dossier_id: dossier.id
expect(response).to have_http_status(:success)
end
it 'redirection vers start si mauvais dossier ID' do
get :show, dossier_id: bad_dossier_id
expect(response).to redirect_to('/start/error_dossier')
end
end
end

View file

@ -1,77 +0,0 @@
require 'spec_helper'
RSpec.describe StartController, type: :controller do
let!(:procedure) { create(:procedure) }
describe 'GET #index' do
before do
get :index, procedure_id: procedure
end
context 'when params procedure_id is present' do
context 'when procedure_id is valid' do
it { expect(response).to have_http_status(:success) }
end
context 'when procedure_id is not valid' do
let(:procedure) { '' }
it { expect(response).to have_http_status(404) }
end
end
context 'when params procedure_id is not present' do
before do
get :index
end
it { expect(response).to have_http_status(404) }
end
end
describe 'GET #index with bad SIRET' do
before do
get :error_siret, procedure_id: procedure
end
it 'returns http success and flash alert is present' do
expect(response).to have_http_status(:success)
end
it 'la flash alert est présente' do
expect(flash[:alert]).to be_present
end
it 'la flash alert a un libellé correct' do
expect(flash[:alert]).to have_content('Ce SIRET n\'est pas valide')
end
end
describe 'GET #index with bad LOGIN' do
before do
get :error_login
end
it 'returns http success and flash alert is present' do
expect(response).to have_http_status(:success)
end
it 'la flash alert est présente' do
expect(flash[:alert]).to be_present
end
it 'la flash alert a un libellé correct' do
expect(flash[:alert]).to have_content('Ce compte n\'existe pas')
end
end
describe 'GET #index with bad DOSSIER' do
before do
get :error_dossier
end
it 'returns http success and flash alert is present' do
expect(response).to have_http_status(:success)
end
it 'la flash alert est présente' do
expect(flash[:alert]).to be_present
end
it 'la flash alert a un libellé correct' do
expect(flash[:alert]).to have_content('Ce dossier n\'existe pas')
end
end
end

View file

@ -0,0 +1,148 @@
require 'spec_helper'
describe Users::DossiersController, type: :controller do
describe '.index' do
subject { get :index }
context 'when user is not logged in' do
it { is_expected.to redirect_to('/users/sign_in') }
end
context 'when user is logged in' do
before do
sign_in create(:user)
end
it { is_expected.to render_template('users/dossiers/index') }
it { is_expected.to have_http_status(:success) }
end
end
let(:dossier) { create(:dossier, :with_entreprise, :with_procedure) }
let(:procedure) { create(:procedure) }
let(:dossier_id) { dossier.id }
let(:siret_not_found) { 999_999_999_999 }
let(:siren) { dossier.siren }
let(:siret) { dossier.siret }
let(:bad_siret) { 1 }
describe 'GET #show' do
before do
sign_in create(:user)
end
it 'returns http success with dossier_id valid' do
get :show, id: dossier_id
expect(response).to have_http_status(:success)
end
it 'redirection vers siret si mauvais dossier ID' do
get :show, id: siret_not_found
expect(response).to redirect_to('/users/siret')
end
end
describe 'POST #create' do
before do
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret_not_found}?token=#{SIADETOKEN}")
.to_return(status: 404, body: 'fake body')
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/etablissement.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
end
describe 'professionnel fills form' do
context 'when pro_dossier_id is empty' do
context 'with valid siret ' do
before do
sign_in create(:user)
end
subject { post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last }
it 'create a dossier' do
expect { subject }.to change { Dossier.count }.by(1)
end
it 'creates entreprise' do
expect { subject }.to change { Entreprise.count }.by(1)
end
it 'links entreprise to dossier' do
expect(Entreprise.last.dossier).to eq(Dossier.last)
end
it 'creates etablissement for dossier' do
expect { subject }.to change { Etablissement.count }.by(1)
end
it 'links etablissement to dossier' do
subject
expect(Etablissement.last.dossier).to eq(Dossier.last)
end
it 'links etablissement to entreprise' do
subject
expect(Etablissement.last.entreprise).to eq(Entreprise.last)
end
it 'links procedure to dossier' do
subject
expect(Dossier.last.procedure).to eq(Procedure.last)
end
it 'state of dossier is draft' do
subject
expect(Dossier.last.state).to eq('draft')
end
end
context 'with non existant siret' do
before do
sign_in create(:user)
end
let(:siret_not_found) { '11111111111111' }
subject { post :create, siret: siret_not_found, pro_dossier_id: '', procedure_id: procedure.id }
it 'does not create new dossier' do
expect { subject }.not_to change { Dossier.count }
end
it 'redirects to show' do
expect(subject).to redirect_to(controller: :siret, procedure_id: procedure.id)
end
end
end
end
end
describe 'PUT #update' do
before do
sign_in create(:user)
put :update, id: dossier_id, dossier: { autorisation_donnees: autorisation_donnees }
end
context 'when Checkbox is checked' do
let(:autorisation_donnees) { '1' }
it 'redirects to demande' do
expect(response).to redirect_to(controller: :description, action: :show, dossier_id: dossier.id)
end
it 'update dossier' do
dossier.reload
expect(dossier.autorisation_donnees).to be_truthy
end
end
context 'when Checkbox is not checked' do
let(:autorisation_donnees) { '0' }
it 'uses flash alert to display message' do
expect(flash[:alert]).to have_content('Les conditions sont obligatoires.')
end
it "doesn't update dossier autorisation_donnees" do
dossier.reload
expect(dossier.autorisation_donnees).to be_falsy
end
end
end
end

View file

@ -0,0 +1,22 @@
require 'spec_helper'
describe Users::RecapitulatifController, type: :controller do
let(:dossier) { create(:dossier, :with_user) }
let(:bad_dossier_id) { Dossier.count + 100000 }
describe 'GET #show' do
before do
sign_in dossier.user
end
it 'returns http success' do
get :show, dossier_id: dossier.id
expect(response).to have_http_status(:success)
end
it 'redirection vers siret si mauvais dossier ID' do
get :show, dossier_id: bad_dossier_id
expect(response).to redirect_to('/users/siret')
end
end
end

View file

@ -0,0 +1,82 @@
require 'spec_helper'
describe Users::SiretController, type: :controller do
let!(:procedure) { create(:procedure) }
describe 'GET #index' do
before do
get :index, procedure_id: procedure
end
context 'when params procedure_id is present' do
context 'when procedure_id is valid' do
context 'when user is logged in' do
before do
sign_in create(:user)
end
subject { get :index, procedure_id: procedure }
it { expect(subject).to have_http_status(:success) }
context 'when procedure_id is not valid' do
let(:procedure) { '' }
it { is_expected.to have_http_status(404) }
end
context 'when params procedure_id is not present' do
subject { get :index }
it { is_expected.to have_http_status(404) }
end
end
context 'when user is not logged' do
it { expect(response).to have_http_status(302) }
end
end
end
end
# describe 'GET #index with bad SIRET' do
# before do
# get :error_siret, procedure_id: procedure
# end
# it 'returns http success and flash alert is present' do
# expect(response).to have_http_status(:success)
# end
# it 'la flash alert est présente' do
# expect(flash[:alert]).to be_present
# end
# it 'la flash alert a un libellé correct' do
# expect(flash[:alert]).to have_content('Ce SIRET n\'est pas valide')
# end
# end
# describe 'GET #index with bad LOGIN' do
# before do
# get :error_login
# end
# it 'returns http success and flash alert is present' do
# expect(response).to have_http_status(:success)
# end
# it 'la flash alert est présente' do
# expect(flash[:alert]).to be_present
# end
# it 'la flash alert a un libellé correct' do
# expect(flash[:alert]).to have_content('Ce compte n\'existe pas')
# end
# end
# describe 'GET #index with bad DOSSIER' do
# before do
# get :error_dossier
# end
# it 'returns http success and flash alert is present' do
# expect(response).to have_http_status(:success)
# end
# it 'la flash alert est présente' do
# expect(flash[:alert]).to be_present
# end
# it 'la flash alert a un libellé correct' do
# expect(flash[:alert]).to have_content('Ce dossier n\'existe pas')
# end
# end
end

View file

@ -17,5 +17,11 @@ FactoryGirl.define do
dossier.procedure = procedure
end
end
trait :with_user do
after(:build) do |dossier, _evaluator|
dossier.user = create(:user)
end
end
end
end

7
spec/factories/user.rb Normal file
View file

@ -0,0 +1,7 @@
FactoryGirl.define do
sequence(:user_email) { |n| "plop#{n}@plop.com" }
factory :user do
email { generate(:user_email) }
password 'password'
end
end

View file

@ -3,7 +3,7 @@ require 'spec_helper'
feature 'On the description page' do
let!(:dossier) { create(:dossier, :with_entreprise, :with_procedure) }
before do
visit dossier_description_path dossier
visit users_dossier_description_path dossier
end
scenario 'date_previsionnelle field is present' do
expect(page).to have_css('#date_previsionnelle')

View file

@ -5,12 +5,12 @@ feature 'Description#Show Page' do
let(:dossier_id) { dossier.id }
before do
visit "/dossiers/#{dossier_id}/description"
visit users_dossier_description_path(dossier_id: dossier_id)
end
context 'tous les attributs sont présents sur la page' do
scenario 'Le formulaire envoie vers /dossiers/:dossier_id/description en #POST' do
expect(page).to have_selector("form[action='/dossiers/#{dossier_id}/description'][method=post]")
scenario 'Le formulaire envoie vers /users/dossiers/:dossier_id/description en #POST' do
expect(page).to have_selector("form[action='/users/dossiers/#{dossier_id}/description'][method=post]")
end
scenario 'Nom du projet' do
@ -62,7 +62,7 @@ feature 'Description#Show Page' do
context 'si la page précédente est recapitularif' do
before do
visit "/dossiers/#{dossier_id}/description?back_url=recapitulatif"
visit "/users/dossiers/#{dossier_id}/description?back_url=recapitulatif"
end
scenario 'le bouton "Terminer" n\'est pas présent' do

View file

@ -3,7 +3,7 @@ require 'spec_helper'
feature 'user is on description page' do
let(:dossier) { create(:dossier, :with_entreprise, :with_procedure) }
before do
visit dossier_description_path dossier
visit users_dossier_description_path dossier
end
it { expect(page).to have_css('#description_page') }

View file

@ -0,0 +1,38 @@
require 'spec_helper'
feature '_Commentaires_Flux Recapitulatif#Show Page' do
let(:dossier) { create(:dossier, :with_user, :with_procedure) }
let(:dossier_id) { dossier.id }
let(:email_commentaire) { 'mon_mail_de_commentaire@test.com' }
let!(:commentaire) { create(:commentaire, dossier: dossier, email: email_commentaire, body: 'ma super description') }
let(:body) { 'Commentaire de test' }
before do
login_as(dossier.user, scope: :user)
visit "/users/dossiers/#{dossier_id}/recapitulatif"
end
context 'Affichage du flux de commentaire' do
scenario 'l\'email du contact est présent' do
expect(page).to have_css('#email_contact')
end
scenario 'la date du commentaire est présent' do
expect(page).to have_selector('span[id=created_at]')
end
scenario 'le corps du commentaire est présent' do
expect(page).to have_css('.description#body')
end
end
context 'Affichage du formulaire de commentaire' do
scenario 'Le formulaire envoie vers /dossiers/:dossier_id/commentaire en #POST' do
expect(page).to have_selector("form[action='/users/dossiers/#{dossier_id}/commentaire'][method=post]")
end
scenario 'Champs de texte' do
expect(page).to have_selector('textarea[id=texte_commentaire][name=texte_commentaire]')
end
end
end

View file

@ -1,12 +1,13 @@
require 'spec_helper'
feature 'Recapitulatif#Show Page' do
let(:dossier) { create(:dossier, :with_procedure) }
let(:dossier) { create(:dossier, :with_user, :with_procedure) }
let(:dossier_id) { dossier.id }
before do
Capybara.current_session.driver.header('Referer', '/description')
visit "/dossiers/#{dossier_id}/recapitulatif"
login_as(dossier.user, :scope => :user)
visit "/users/dossiers/#{dossier_id}/recapitulatif"
end
context 'sur la page recapitulative' do
@ -42,14 +43,14 @@ feature 'Recapitulatif#Show Page' do
scenario 'N\'est pas affiché quand l\'on vient d\'une autre la page que description' do
Capybara.current_session.driver.header('Referer', '/')
visit "/dossiers/#{dossier_id}/recapitulatif"
visit "/users/dossiers/#{dossier_id}/recapitulatif"
expect(page).to_not have_content('Félicitation')
end
scenario 'N\'est pas affiché quand l\'on vient de la page description en modification' do
Capybara.current_session.driver.header('Referer', '/description?back_url=recapitulatif')
visit "/dossiers/#{dossier_id}/recapitulatif"
visit "/users/dossiers/#{dossier_id}/recapitulatif"
expect(page).to_not have_content('Félicitation')
end

View file

@ -0,0 +1,63 @@
require 'spec_helper'
feature 'user path for dossier creation' do
let(:user) { create(:user) }
let(:procedure) { create(:procedure) }
let(:siret) { '53272417600013' }
let(:siren) { siret[0...9] }
context 'user arrives on siret page' do
before do
visit users_siret_path(procedure_id: procedure.id)
end
scenario 'he is redirected on login page' do
expect(page).to have_css('#login_user')
end
context 'user sign_in' do
before do
page.find_by_id('user_email').set user.email
page.find_by_id('user_password').set user.password
page.click_on 'Se connecter'
end
scenario 'redirects to siret page' do
expect(page).to have_css('#siret')
end
context 'sets siret' do
before do
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret}?token=#{SIADETOKEN}")
.to_return(body: File.read('spec/support/files/etablissement.json', status: 200))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
page.find_by_id('siret').set siret
page.click_on 'Commencer'
end
scenario 'user is on page recap info entreprise' do
expect(page).to have_css('#recap_info_entreprise')
end
context 'when validating info entreprise recap page' do
before do
page.check('dossier_autorisation_donnees')
page.click_on 'Etape suivante'
end
scenario 'user is on description page' do
expect(page).to have_css('#description_page')
end
context 'user fill and validate description page' 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 'Terminer la procédure'
end
scenario 'user is on recap page' do
expect(page).to have_css('#recap_dossier')
end
end
end
end
end
end
end

View file

@ -0,0 +1,16 @@
require 'spec_helper'
feature 'user access to the list of his dossier' do
let(:user) { create(:user) }
let!(:dossier1) { create(:dossier) }
before do
visit root_path
page.find_by_id('user_email').set user.email
page.find_by_id('user_password').set user.password
page.click_on 'Se connecter'
end
scenario 'the list of dossier is displayed' do
expect(page).to have_content(dossier1.nom_projet)
end
end

View file

@ -0,0 +1,39 @@
require 'spec_helper'
feature 'user arrive on siret page' do
let(:procedure) { create(:procedure) }
let(:user) { create(:user) }
let(:siret) { '42149333900020' }
let(:siren) { siret[0...9] }
context 'when user is not logged in' do
before do
visit users_siret_path(procedure_id: procedure.id)
end
scenario 'he is redirected to login page' do
expect(page).to have_css('#login_user')
end
context 'when he enter login information' do
before do
page.find_by_id('user_email').set user.email
page.find_by_id('user_password').set user.password
page.click_on 'Se connecter'
end
scenario 'he is redirected to siret page to enter a siret' do
expect(page).to have_css('#pro_section')
end
context 'when enter a siret' do
before do
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/etablissement.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
page.find_by_id('siret').set siret
page.click_on 'Commencer'
end
scenario 'he is redirected to recap info entreprise page' do
expect(page).to have_css('#recap_info_entreprise')
end
end
end
end
end

View file

@ -21,6 +21,7 @@ describe Dossier do
it { is_expected.to have_one(:cerfa) }
it { is_expected.to have_one(:etablissement) }
it { is_expected.to have_one(:entreprise) }
it { is_expected.to belong_to(:user) }
end
describe 'delegation' do

21
spec/models/user_spec.rb Normal file
View file

@ -0,0 +1,21 @@
require 'rails_helper'
describe User, type: :model do
describe 'database columns' 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
describe 'associations' do
it { is_expected.to have_many(:dossiers) }
end
end

View file

@ -14,20 +14,20 @@ describe 'dossiers/show.html.haml', type: :view do
expect(rendered).to have_css('#dossier_autorisation_donnees')
end
context 'sur la page d\'information d\'un SIRET' do
it 'Le formulaire envoie vers /dossiers/:dossier_id en #POST' do
expect(rendered).to have_selector("form[action='/dossiers/#{dossier.id}'][method=post]")
context "sur la page d'information d'un SIRET" do
it 'Le formulaire envoie vers /users/dossiers/:dossier_id en #POST' do
expect(rendered).to have_selector("form[action='/users/dossiers'][method=post]")
end
it 'la checkbox d\'information est présente' do
it "la checkbox d'information est présente" do
expect(rendered).to have_css('#dossier_autorisation_donnees')
end
it 'le texte d\'information des droits est correct' do
it "le texte d'information des droits est correct" do
expect(rendered).to have_content("J'autorise les organismes publics à vérifier les informations de mon entreprise auprès des administrations concernées. Ces informations resteront strictement confidentielles.")
end
it 'les informations de l\'entreprise sont présents' do
it "les informations de l'entreprise sont présents" do
expect(rendered).to have_content('Siret')
end

View file

@ -0,0 +1,16 @@
require 'spec_helper'
describe 'users/dossiers/index.html.haml', type: :view do
describe 'list dossiers' do
let(:dossier1) { create(:dossier).decorate }
let(:dossier2) { create(:dossier).decorate }
before do
assign(:dossiers, [dossier1, dossier2])
render
end
subject { rendered }
it { expect(subject).to have_content(dossier1.nom_projet) }
end
end

View file

@ -1,7 +1,7 @@
require 'spec_helper'
describe 'recapitulatif/_commentaires_flux.html.haml', type: :view do
let(:dossier) { create(:dossier) }
describe 'users/recapitulatif/_commentaires_flux.html.haml', type: :view do
let(:dossier) { create(:dossier, :with_procedure) }
let(:dossier_id) { dossier.id }
let(:email_commentaire) { 'mon_mail_de_commentaire@test.com' }
let!(:commentaire) { create(:commentaire, dossier: dossier, email: email_commentaire, body: 'ma super description') }
@ -29,7 +29,7 @@ describe 'recapitulatif/_commentaires_flux.html.haml', type: :view do
context 'Affichage du formulaire de commentaire' do
it 'Le formulaire envoie vers /dossiers/:dossier_id/commentaire en #POST' do
expect(rendered).to have_selector("form[action='/dossiers/#{dossier_id}/commentaire'][method=post]")
expect(rendered).to have_selector("form[action='/users/dossiers/#{dossier_id}/commentaire'][method=post]")
end
it 'Champs de texte' do

View file

@ -1,6 +1,6 @@
require 'spec_helper'
describe 'start/index.html.haml', type: :view do
describe 'users/siret/index.html.haml', type: :view do
let(:procedure) { create(:procedure, libelle: 'Demande de subvention') }
before do
assign(:procedure, procedure)
@ -13,7 +13,7 @@ describe 'start/index.html.haml', type: :view do
context 'dans la section professionnel' do
it 'le formulaire envoie vers /dossiers en #POST' do
expect(rendered).to have_selector("form[action='/dossiers'][method=post]")
expect(rendered).to have_selector("form[action='/users/dossiers'][method=post]")
end
it 'le champs "Numéro SIRET" est présent' do