move controller into users folder
This commit is contained in:
parent
4f3b35fe41
commit
5772b99d42
33 changed files with 460 additions and 250 deletions
|
@ -1,73 +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
|
||||
flash.alert = t('errors.messages.dossier_not_found')
|
||||
redirect_to url_for(controller: :siret)
|
||||
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!
|
||||
# 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
|
||||
# @dossier.procedure = procedure
|
||||
# @dossier.save
|
||||
|
||||
@entreprise.dossier = @dossier
|
||||
@entreprise.save
|
||||
# @entreprise.dossier = @dossier
|
||||
# @entreprise.save
|
||||
|
||||
@etablissement.dossier = @dossier
|
||||
@etablissement.entreprise = @entreprise
|
||||
@etablissement.save
|
||||
# @etablissement.dossier = @dossier
|
||||
# @etablissement.entreprise = @entreprise
|
||||
# @etablissement.save
|
||||
|
||||
redirect_to url_for(controller: :dossiers, action: :show, id: @dossier.id)
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
# private
|
||||
|
||||
def update_params
|
||||
params.require(:dossier).permit(:autorisation_donnees)
|
||||
end
|
||||
# def update_params
|
||||
# params.require(:dossier).permit(:autorisation_donnees)
|
||||
# end
|
||||
|
||||
def dossier_id_is_present?
|
||||
@dossier_id != ''
|
||||
end
|
||||
# def dossier_id_is_present?
|
||||
# @dossier_id != ''
|
||||
# end
|
||||
|
||||
def checked_autorisation_donnees?
|
||||
update_params[:autorisation_donnees] == '1'
|
||||
end
|
||||
# def checked_autorisation_donnees?
|
||||
# update_params[:autorisation_donnees] == '1'
|
||||
# end
|
||||
|
||||
def siret
|
||||
params[:siret]
|
||||
end
|
||||
# def siret
|
||||
# params[:siret]
|
||||
# end
|
||||
|
||||
def siren
|
||||
siret[0..8]
|
||||
end
|
||||
# def siren
|
||||
# siret[0..8]
|
||||
# end
|
||||
end
|
||||
|
|
3
app/controllers/users/commentaires_controller.rb
Normal file
3
app/controllers/users/commentaires_controller.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class Users::CommentairesController < CommentairesController
|
||||
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
class DescriptionController < ApplicationController
|
||||
class Users::DescriptionController < ApplicationController
|
||||
def show
|
||||
@dossier = Dossier.find(params[:dossier_id])
|
||||
@dossier = @dossier.decorate
|
|
@ -1,6 +1,79 @@
|
|||
class Users::DossiersController < ApplicationController
|
||||
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
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class RecapitulatifController < ApplicationController
|
||||
class Users::RecapitulatifController < UsersController
|
||||
def show
|
||||
|
||||
@dossier = Dossier.find(params[:dossier_id])
|
||||
@dossier = @dossier.decorate
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
class SiretController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
class Users::SiretController < UsersController
|
||||
def index
|
||||
@procedure = Procedure.find(params['procedure_id'])
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
|
@ -9,5 +8,4 @@ class SiretController < ApplicationController
|
|||
def error_procedure
|
||||
render :file => "#{Rails.root}/public/404_procedure_not_found.html", :status => 404
|
||||
end
|
||||
|
||||
end
|
3
app/controllers/users_controller.rb
Normal file
3
app/controllers/users_controller.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class UsersController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
end
|
|
@ -44,7 +44,7 @@
|
|||
= render partial: '/carte/carte_sources_JS_backend'
|
||||
%br
|
||||
|
||||
= render partial: '/recapitulatif/commentaires_flux'
|
||||
= render partial: '/users/recapitulatif/commentaires_flux'
|
||||
%br
|
||||
%br
|
||||
|
||||
|
|
13
app/views/dossiers/_show.html.haml
Normal file
13
app/views/dossiers/_show.html.haml
Normal 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: :create } 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'
|
|
@ -1,13 +1 @@
|
|||
.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: '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'
|
|
@ -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}
|
1
app/views/users/dossiers/show.html.haml
Normal file
1
app/views/users/dossiers/show.html.haml
Normal file
|
@ -0,0 +1 @@
|
|||
= render partial: '/dossiers/show'
|
|
@ -5,5 +5,5 @@
|
|||
Site de démonstration d’un service public de saisie d’un projet ou de dépôt d’une démarche administrative, auprès d’un ou plusieurs organismes publics, simplifié des informations déjà connues des administrations, grâce à la fourniture du numéro SIRET.
|
||||
|
||||
.row
|
||||
= render partial: '/siret/pro'
|
||||
= render partial: 'pro'
|
||||
|
|
@ -12,27 +12,39 @@ Rails.application.routes.draw do
|
|||
# root 'welcome#index'
|
||||
root 'users/dossiers#index'
|
||||
|
||||
get 'siret' => 'siret#index'
|
||||
namespace :users do
|
||||
get 'siret' => 'siret#index'
|
||||
resources :dossiers do
|
||||
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
|
||||
|
||||
|
||||
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'
|
||||
|
||||
post '/commentaire' => 'commentaires#create'
|
||||
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'
|
||||
|
||||
namespace :backoffice do
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 }
|
||||
|
@ -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
|
||||
|
|
|
@ -1,124 +1,124 @@
|
|||
require 'spec_helper'
|
||||
|
||||
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(: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 siret si mauvais dossier ID' do
|
||||
get :show, id: siret_not_found
|
||||
expect(response).to redirect_to('/siret')
|
||||
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
|
||||
# describe 'professionnel fills form' do
|
||||
# context 'when pro_dossier_id is empty' do
|
||||
# context 'with valid siret ' do
|
||||
|
||||
subject { post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last }
|
||||
# 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 '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 '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 '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 '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 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 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 '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
|
||||
# it 'state of dossier is draft' do
|
||||
# subject
|
||||
# expect(Dossier.last.state).to eq('draft')
|
||||
# end
|
||||
# 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
|
||||
# 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 'redirects to show' do
|
||||
expect(subject).to redirect_to(controller: :siret, procedure_id: procedure.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
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
|
||||
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
|
||||
# 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 'update dossier' do
|
||||
dossier.reload
|
||||
expect(dossier.autorisation_donnees).to be_truthy
|
||||
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
|
||||
# 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
|
||||
# it "doesn't update dossier autorisation_donnees" do
|
||||
# dossier.reload
|
||||
# expect(dossier.autorisation_donnees).to be_falsy
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
|
|
@ -14,4 +14,135 @@ describe Users::DossiersController, type: :controller do
|
|||
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
|
|
@ -1,11 +1,14 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe RecapitulatifController, type: :controller do
|
||||
let(:dossier) { create(:dossier) }
|
||||
describe Users::RecapitulatifController, type: :controller do
|
||||
let(:dossier) { create(:dossier, :with_user) }
|
||||
|
||||
let(:bad_dossier_id) { Dossier.count + 10 }
|
||||
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)
|
||||
|
@ -13,7 +16,7 @@ RSpec.describe 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('/siret')
|
||||
expect(response).to redirect_to('/users/siret')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe SiretController, type: :controller do
|
||||
describe Users::SiretController, type: :controller do
|
||||
let!(:procedure) { create(:procedure) }
|
||||
|
||||
describe 'GET #index' do
|
|
@ -16,5 +16,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
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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') }
|
||||
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature '_Commentaires_Flux Recapitulatif#Show Page' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:dossier) { create(:dossier, :with_user) }
|
||||
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
|
||||
visit "/dossiers/#{dossier_id}/recapitulatif"
|
||||
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_selector('span[id=email_contact]')
|
||||
expect(page).to have_css('#email_contact')
|
||||
end
|
||||
|
||||
scenario 'la date du commentaire est présent' do
|
||||
|
@ -21,13 +22,13 @@ feature '_Commentaires_Flux Recapitulatif#Show Page' do
|
|||
end
|
||||
|
||||
scenario 'le corps du commentaire est présent' do
|
||||
expect(page).to have_selector('div[class=description][id=body]')
|
||||
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='/dossiers/#{dossier_id}/commentaire'][method=post]")
|
||||
expect(page).to have_selector("form[action='/users/dossiers/#{dossier_id}/commentaire'][method=post]")
|
||||
end
|
||||
|
||||
scenario 'Champs de texte' do
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature 'Recapitulatif#Show Page' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:dossier) { create(:dossier, :with_user) }
|
||||
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
|
||||
|
|
|
@ -7,7 +7,7 @@ feature 'user arrive on siret page' do
|
|||
let(:siren) { siret[0...9] }
|
||||
context 'when user is not logged in' do
|
||||
before do
|
||||
visit siret_path(procedure_id: procedure.id)
|
||||
visit users_siret_path(procedure_id: procedure.id)
|
||||
end
|
||||
scenario 'he is redirected to login page' do
|
||||
expect(page).to have_css('#login_user')
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'siret/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 'siret/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
|
Loading…
Reference in a new issue