From ee82e7fa8abe95f95abe1b65b61bf908a49531ab Mon Sep 17 00:00:00 2001 From: Xavier J Date: Fri, 16 Dec 2016 17:15:13 +0100 Subject: [PATCH] Add ProcedureController tests --- .../dossiers/procedure_controller.rb | 4 +- .../dossiers/procedure_controller_spec.rb | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 spec/controllers/backoffice/dossiers/procedure_controller_spec.rb diff --git a/app/controllers/backoffice/dossiers/procedure_controller.rb b/app/controllers/backoffice/dossiers/procedure_controller.rb index 74b092f43..76b96bf66 100644 --- a/app/controllers/backoffice/dossiers/procedure_controller.rb +++ b/app/controllers/backoffice/dossiers/procedure_controller.rb @@ -7,14 +7,14 @@ class Backoffice::Dossiers::ProcedureController < Backoffice::DossiersListContro render 'backoffice/dossiers/index' rescue ActiveRecord::RecordNotFound - flash[:alert] = "Cette procédure n'existe pas ou vous n'y avez pas accès." + flash.alert = "Cette procédure n'existe pas ou vous n'y avez pas accès." redirect_to backoffice_dossiers_path end def filter super - redirect_to backoffice_dossiers_procedure_path(id: params[:id], liste: param_liste) + redirect_to backoffice_dossiers_procedure_path(id: params[:id]) end private diff --git a/spec/controllers/backoffice/dossiers/procedure_controller_spec.rb b/spec/controllers/backoffice/dossiers/procedure_controller_spec.rb new file mode 100644 index 000000000..7967e1010 --- /dev/null +++ b/spec/controllers/backoffice/dossiers/procedure_controller_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper' + +describe Backoffice::Dossiers::ProcedureController, type: :controller do + let(:gestionnaire) { create :gestionnaire } + let(:procedure) { create :procedure } + + before do + create :assign_to, gestionnaire: gestionnaire, procedure: procedure + sign_in gestionnaire + gestionnaire.build_default_preferences_list_dossier procedure.id + end + + describe 'GET #index' do + let(:procedure_id) { procedure.id } + + subject { get :index, params: {id: procedure_id} } + + it { expect(subject.status).to eq 200 } + + context 'when procedure id is not found' do + let(:procedure_id) { 100000 } + + before do + subject + end + + it { expect(response.status).to eq 302 } + it { is_expected.to redirect_to backoffice_dossiers_path } + it { expect(flash[:alert]).to be_present} + end + end + + describe 'GET #filter' do + subject { get :filter, params: {id: procedure.id, filter_input: {"entreprise.raison_sociale" => "plop"}} } + + it { is_expected.to redirect_to backoffice_dossiers_procedure_path(id: procedure.id) } + end +end \ No newline at end of file