From ed368973376348b620439e3a0440cfe1f13218ec Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Tue, 28 Mar 2017 13:17:58 +0200 Subject: [PATCH] DossiersController: add get procedure libelle --- app/controllers/users/dossiers_controller.rb | 7 ++++++ config/routes.rb | 2 ++ .../users/dossiers_controller_spec.rb | 24 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index fe4421dab..4eade942c 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -154,6 +154,13 @@ class Users::DossiersController < UsersController redirect_to url_for users_dossiers_path end + def procedure_libelle + dossier = Dossier.find(params[:dossier_id]) + render json: { procedureLibelle: dossier.procedure.libelle } + rescue ActiveRecord::RecordNotFound + render json: {}, status: 404 + end + private def check_siret diff --git a/config/routes.rb b/config/routes.rb index 5811b4890..216951ace 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -94,6 +94,8 @@ Rails.application.routes.draw do post '/siret_informations' => 'dossiers#siret_informations' put '/change_siret' => 'dossiers#change_siret' + + get 'procedure_libelle' => 'dossiers#procedure_libelle' end resource :dossiers end diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 6d77ce488..601b243bc 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -554,4 +554,28 @@ describe Users::DossiersController, type: :controller do end end + describe 'Get #procedure_libelle' do + let!(:dossier) { create(:dossier, procedure: procedure) } + + context 'when user is connected' do + before { sign_in user } + + context 'when the dossier exist' do + before { get :procedure_libelle, params: { dossier_id: dossier.id } } + it 'returns the procedure name' do + expect(JSON.parse(response.body)).to eq('procedureLibelle' => procedure.libelle) + end + end + + context 'when the dossier does not exist' do + before { get :procedure_libelle, params: { dossier_id: 666 } } + it { expect(response.code).to eq('404') } + end + end + + context 'when user is not connected' do + before { get :procedure_libelle, params: { dossier_id: dossier.id } } + it { expect(response.code).to eq('302') } + end + end end