From dd09a38bbbfe403aa5065cd16ddb74cbebbf931c Mon Sep 17 00:00:00 2001 From: Xavier J Date: Fri, 27 Nov 2015 10:39:05 +0100 Subject: [PATCH] User can begin a new dossier with a procedure archived Administrateur can see archived procedure --- .../admin/procedures_controller.rb | 6 ++--- app/controllers/users/procedure_controller.rb | 2 +- app/controllers/users/siret_controller.rb | 12 +++------- app/views/demo/index.html.haml | 2 +- .../admin/procedures_controller_spec.rb | 4 ++-- .../users/procedure_controller_spec.rb | 22 ++++++++++++------- .../users/siret_controller_spec.rb | 4 ++-- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 13923211d..0c16e2466 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -1,12 +1,12 @@ class Admin::ProceduresController < AdminController def index - @procedures = current_administrateur.procedures + @procedures = current_administrateur.procedures.where(archived: false) @procedures = @procedures.paginate(:page => params[:page], :per_page => 12) end def show - @procedure = Procedure.find(params[:id]) + @procedure = current_administrateur.procedures.find(params[:id]) @types_de_champ = @procedure.types_de_champ.order(:order_place) @types_de_piece_justificative = @procedure.types_de_piece_justificative.order(:libelle) @@ -33,7 +33,7 @@ class Admin::ProceduresController < AdminController def update - @procedure = Procedure.find(params[:id]) + @procedure = current_administrateur.procedures.find(params[:id]) unless @procedure.update_attributes(create_procedure_params) flash.now.alert = @procedure.errors.full_messages.join('
').html_safe diff --git a/app/controllers/users/procedure_controller.rb b/app/controllers/users/procedure_controller.rb index cdc12bf45..ed9b4b1ef 100644 --- a/app/controllers/users/procedure_controller.rb +++ b/app/controllers/users/procedure_controller.rb @@ -1,6 +1,6 @@ class Users::ProcedureController < UsersController def index - @procedure = Procedure.find(params[:procedure_id]) + @procedure = Procedure.where(archived: false).find(params[:procedure_id]) @siret = params[:siret] || current_user.siret rescue ActiveRecord::RecordNotFound error_procedure diff --git a/app/controllers/users/siret_controller.rb b/app/controllers/users/siret_controller.rb index 3385ac061..f6894565c 100644 --- a/app/controllers/users/siret_controller.rb +++ b/app/controllers/users/siret_controller.rb @@ -1,15 +1,9 @@ class Users::SiretController < UsersController def index - @procedure = Procedure.find(params['procedure_id']) @siret = params[:siret] || current_user.siret - redirect_to(users_path(procedure_id: @procedure, siret: @siret)) - - rescue ActiveRecord::RecordNotFound - error_procedure - end - - def error_procedure - render :file => "#{Rails.root}/public/404_procedure_not_found.html", :status => 404 + redirect_to(users_path(procedure_id: params['procedure_id'], siret: @siret)) + rescue ActionController::UrlGenerationError + redirect_to(new_user_session_path) end end diff --git a/app/views/demo/index.html.haml b/app/views/demo/index.html.haml index fc7e53f90..82b027fd3 100644 --- a/app/views/demo/index.html.haml +++ b/app/views/demo/index.html.haml @@ -6,7 +6,7 @@ %td %th Titre %th Description - - Procedure.all.each do |procedure| + - Procedure.all.where(archived: false).each do |procedure| %tr %td.col-md-1.col-lg-1 %td.col-md-4.col-lg-4 diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index d0493a55a..54195ee71 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -35,7 +35,7 @@ describe Admin::ProceduresController, type: :controller do end describe 'GET #show' do - let(:procedure) { create(:procedure, :with_type_de_champ, :with_two_type_de_piece_justificative) } + let(:procedure) { create(:procedure, :with_type_de_champ, :with_two_type_de_piece_justificative, administrateur: admin) } let(:procedure_id) { procedure.id } subject { get :show, id: procedure_id } @@ -115,7 +115,7 @@ describe Admin::ProceduresController, type: :controller do end describe 'PUT #update' do - let!(:procedure) { create(:procedure, :with_type_de_champ, :with_two_type_de_piece_justificative) } + let!(:procedure) { create(:procedure, :with_type_de_champ, :with_two_type_de_piece_justificative, administrateur: admin) } context 'when administrateur is not connected' do before do diff --git a/spec/controllers/users/procedure_controller_spec.rb b/spec/controllers/users/procedure_controller_spec.rb index 82d51b6f7..c8192fe7b 100644 --- a/spec/controllers/users/procedure_controller_spec.rb +++ b/spec/controllers/users/procedure_controller_spec.rb @@ -1,30 +1,36 @@ require 'spec_helper' describe Users::ProcedureController, type: :controller do - let!(:procedure) { create(:procedure) } + let(:procedure) { create(:procedure) } + let(:procedure_id) { procedure.id } describe 'GET #index' do - before do - get :index, procedure_id: procedure - end + + subject { get :index, procedure_id: procedure_id } 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) } + it { is_expected.to have_http_status(:success) } context 'when procedure_id is not valid' do - let(:procedure) { '' } + let(:procedure_id) { 0 } + it { is_expected.to have_http_status(404) } + end + + context 'when procedure is archived' do + let(:procedure) { create(:procedure, archived: 'true') } + 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) } + it { is_expected.to have_http_status(302) } end end end diff --git a/spec/controllers/users/siret_controller_spec.rb b/spec/controllers/users/siret_controller_spec.rb index 2b5baec2f..e3bf7cf9d 100644 --- a/spec/controllers/users/siret_controller_spec.rb +++ b/spec/controllers/users/siret_controller_spec.rb @@ -26,11 +26,11 @@ describe Users::SiretController, type: :controller do context 'when procedure_id is not valid' do let(:procedure) { '' } - it { is_expected.to have_http_status(404) } + it { is_expected.to have_http_status(302) } end context 'when params procedure_id is not present' do subject { get :index } - it { is_expected.to have_http_status(404) } + it { is_expected.to redirect_to new_user_session_path } end end context 'when user is not logged' do