rename start controller into siret controller and change error handling

This commit is contained in:
Tanguy PATTE 2015-09-23 16:56:30 +02:00
parent ede01b024b
commit e0cb736542
20 changed files with 60 additions and 76 deletions

View file

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

View file

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

View file

@ -6,7 +6,8 @@ class DescriptionController < ApplicationController
@procedure = @dossier.procedure @procedure = @dossier.procedure
rescue ActiveRecord::RecordNotFound 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
def error def error

View file

@ -5,16 +5,18 @@ class DossiersController < ApplicationController
@etablissement = @dossier.etablissement @etablissement = @dossier.etablissement
@entreprise = @dossier.entreprise.decorate @entreprise = @dossier.entreprise.decorate
rescue ActiveRecord::RecordNotFound 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
def create def create
procedure = Procedure.find(params['procedure_id'])
@etablissement = Etablissement.new(SIADE::EtablissementAdapter.new(siret).to_params) @etablissement = Etablissement.new(SIADE::EtablissementAdapter.new(siret).to_params)
@entreprise = Entreprise.new(SIADE::EntrepriseAdapter.new(siren).to_params) @entreprise = Entreprise.new(SIADE::EntrepriseAdapter.new(siren).to_params)
@dossier = Dossier.create @dossier = Dossier.create
@dossier.draft! @dossier.draft!
@dossier.procedure = Procedure.find(params['procedure_id']) @dossier.procedure = procedure
@dossier.save @dossier.save
@entreprise.dossier = @dossier @entreprise.dossier = @dossier
@ -27,9 +29,11 @@ class DossiersController < ApplicationController
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 rescue RestClient::ResourceNotFound
redirect_to url_for(controller: :start, action: :error_siret, procedure_id: params['procedure_id']) flash.alert = t('errors.messages.invalid_siret')
redirect_to url_for(controller: :siret, procedure_id: params['procedure_id'])
rescue ActiveRecord::RecordNotFound 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
def update def update

View file

@ -11,6 +11,7 @@ class RecapitulatifController < ApplicationController
#TODO load user email #TODO load user email
@commentaire_email = 'user@email' @commentaire_email = 'user@email'
rescue ActiveRecord::RecordNotFound 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
end end

View file

@ -0,0 +1,13 @@
class SiretController < ApplicationController
before_action :authenticate_user!
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

@ -1,38 +0,0 @@
class StartController < ApplicationController
before_action :authenticate_user!
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

@ -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. 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 .row
= render partial: '/start/pro' = render partial: '/siret/pro'

View file

@ -78,5 +78,7 @@ fr:
not_saved: not_saved:
one: "1 erreur a empêché ce(tte) %{resource} d'être sauvegardé(e) :" 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) :" 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

@ -12,11 +12,11 @@ Rails.application.routes.draw do
# root 'welcome#index' # root 'welcome#index'
root 'users/dossiers#index' root 'users/dossiers#index'
get 'start' => 'start#index' get 'siret' => 'siret#index'
get 'start/index' # get 'start/index'
get 'start/error_siret' # get 'start/error_siret'
get 'start/error_login' # get 'start/error_login'
get 'start/error_dossier' # get 'start/error_dossier'
resources :dossiers do resources :dossiers do
get '/demande' => 'demandes#show' get '/demande' => 'demandes#show'

View file

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

View file

@ -13,7 +13,7 @@ describe DescriptionController, type: :controller do
it 'redirection vers start si mauvais dossier ID' do it 'redirection vers start si mauvais dossier ID' do
get :show, dossier_id: bad_dossier_id 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
end end

View file

@ -2,6 +2,7 @@ require 'spec_helper'
describe DossiersController, type: :controller do describe DossiersController, type: :controller do
let(:dossier) { create(:dossier, :with_entreprise, :with_procedure) } let(:dossier) { create(:dossier, :with_entreprise, :with_procedure) }
let(:procedure) { create(:procedure) }
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }
let(:siret_not_found) { 999_999_999_999 } let(:siret_not_found) { 999_999_999_999 }
@ -15,9 +16,9 @@ describe DossiersController, type: :controller do
expect(response).to have_http_status(:success) expect(response).to have_http_status(:success)
end end
it 'redirection vers start si mauvais dossier ID' do it 'redirection vers siret si mauvais dossier ID' do
get :show, id: siret_not_found get :show, id: siret_not_found
expect(response).to redirect_to('/start/error_dossier') expect(response).to redirect_to('/siret')
end end
end end
@ -36,16 +37,16 @@ describe DossiersController, type: :controller do
describe 'professionnel fills form' do describe 'professionnel fills form' do
context 'when pro_dossier_id is empty' do context 'when pro_dossier_id is empty' do
context 'with valid siret ' do context 'with valid siret ' do
before do
post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last subject { post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last }
end
it 'create a dossier' do it 'create a dossier' do
expect { post :create, siret: siret, pro_dossier_id: '' }.to change { Dossier.count }.by(1) expect { subject }.to change { Dossier.count }.by(1)
end end
it 'creates entreprise' do it 'creates entreprise' do
expect { post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last }.to change { Entreprise.count }.by(1) expect { subject }.to change { Entreprise.count }.by(1)
end end
it 'links entreprise to dossier' do it 'links entreprise to dossier' do
@ -53,35 +54,39 @@ describe DossiersController, type: :controller do
end end
it 'creates etablissement for dossier' do it 'creates etablissement for dossier' do
expect { post :create, siret: siret, pro_dossier_id: '', procedure_id: Procedure.last }.to change { Etablissement.count }.by(1) expect { subject }.to change { Etablissement.count }.by(1)
end end
it 'links etablissement to dossier' do it 'links etablissement to dossier' do
subject
expect(Etablissement.last.dossier).to eq(Dossier.last) expect(Etablissement.last.dossier).to eq(Dossier.last)
end end
it 'links etablissement to entreprise' do it 'links etablissement to entreprise' do
subject
expect(Etablissement.last.entreprise).to eq(Entreprise.last) expect(Etablissement.last.entreprise).to eq(Entreprise.last)
end end
it 'links procedure to dossier' do it 'links procedure to dossier' do
subject
expect(Dossier.last.procedure).to eq(Procedure.last) expect(Dossier.last.procedure).to eq(Procedure.last)
end end
it 'state of dossier is draft' do it 'state of dossier is draft' do
subject
expect(Dossier.last.state).to eq('draft') expect(Dossier.last.state).to eq('draft')
end end
end end
context 'with non existant siret' do context 'with non existant siret' do
let(:siret_not_found) { '11111111111111' } let(:siret_not_found) { '11111111111111' }
subject { post :create, siret: siret_not_found, pro_dossier_id: '' } subject { post :create, siret: siret_not_found, pro_dossier_id: '', procedure_id: procedure.id }
it 'does not create new dossier' do it 'does not create new dossier' do
expect { subject }.not_to change { Dossier.count } expect { subject }.not_to change { Dossier.count }
end end
it 'redirects to show' do it 'redirects to show' do
expect(subject).to redirect_to(controller: :start, action: :error_siret) expect(subject).to redirect_to(controller: :siret, procedure_id: procedure.id)
end end
end end
end end

View file

@ -11,9 +11,9 @@ RSpec.describe RecapitulatifController, type: :controller do
expect(response).to have_http_status(:success) expect(response).to have_http_status(:success)
end end
it 'redirection vers start si mauvais dossier ID' do it 'redirection vers siret si mauvais dossier ID' do
get :show, dossier_id: bad_dossier_id get :show, dossier_id: bad_dossier_id
expect(response).to redirect_to('/start/error_dossier') expect(response).to redirect_to('/siret')
end end
end end
end end

View file

@ -1,6 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe StartController, type: :controller do describe SiretController, type: :controller do
let!(:procedure) { create(:procedure) } let!(:procedure) { create(:procedure) }
describe 'GET #index' do describe 'GET #index' do

View file

@ -1,13 +1,13 @@
require 'spec_helper' require 'spec_helper'
feature 'user arrive on start page' do feature 'user arrive on siret page' do
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:siret) { '42149333900020' } let(:siret) { '42149333900020' }
let(:siren) { siret[0...9] } let(:siren) { siret[0...9] }
context 'when user is not logged in' do context 'when user is not logged in' do
before do before do
visit start_path(procedure_id: procedure.id) visit siret_path(procedure_id: procedure.id)
end end
scenario 'he is redirected to login page' do scenario 'he is redirected to login page' do
expect(page).to have_css('#login_user') expect(page).to have_css('#login_user')
@ -18,7 +18,7 @@ feature 'user arrive on start page' do
page.find_by_id('user_password').set user.password page.find_by_id('user_password').set user.password
page.click_on 'Se connecter' page.click_on 'Se connecter'
end end
scenario 'he is redirected to start page to enter a siret' do scenario 'he is redirected to siret page to enter a siret' do
expect(page).to have_css('#pro_section') expect(page).to have_css('#pro_section')
end end
context 'when enter a siret' do context 'when enter a siret' do

View file

@ -1,6 +1,6 @@
require 'spec_helper' require 'spec_helper'
describe 'start/index.html.haml', type: :view do describe 'siret/index.html.haml', type: :view do
let(:procedure) { create(:procedure, libelle: 'Demande de subvention') } let(:procedure) { create(:procedure, libelle: 'Demande de subvention') }
before do before do
assign(:procedure, procedure) assign(:procedure, procedure)