fix(avis_controller): procedure do not show revoked avis
This commit is contained in:
parent
dcae06ae84
commit
f500cb8dc7
2 changed files with 32 additions and 8 deletions
|
@ -18,8 +18,22 @@ module Experts
|
|||
|
||||
def procedure
|
||||
@procedure = current_expert.procedures.find_by(id: params[:procedure_id])
|
||||
redirect_to(expert_all_avis_path, flash: { alert: "Vous n’avez pas accès à cette démarche." }) and return unless @procedure
|
||||
expert_avis = current_expert.avis.includes(:dossier).not_hidden_by_administration.where(dossiers: { groupe_instructeur: GroupeInstructeur.where(procedure: @procedure.id) })
|
||||
|
||||
if @procedure.nil?
|
||||
redirect_to(expert_all_avis_path, flash: { alert: "Vous n’avez pas accès à cette démarche." }) and return
|
||||
end
|
||||
|
||||
expert_avis = current_expert
|
||||
.avis
|
||||
.not_revoked
|
||||
.includes(:dossier)
|
||||
.not_hidden_by_administration
|
||||
.where(dossiers: { groupe_instructeur: GroupeInstructeur.where(procedure: @procedure) })
|
||||
|
||||
if expert_avis.empty?
|
||||
redirect_to(expert_all_avis_path, flash: { alert: "Vous n’avez pas accès à cette démarche." }) and return
|
||||
end
|
||||
|
||||
@avis_a_donner = expert_avis.without_answer
|
||||
@avis_donnes = expert_avis.with_answer
|
||||
|
||||
|
|
|
@ -38,13 +38,23 @@ describe Experts::AvisController, type: :controller do
|
|||
describe '#procedure' do
|
||||
context 'without filter' do
|
||||
let!(:oldest_avis_without_answer) { create(:avis, dossier: dossier, claimant: claimant, experts_procedure: experts_procedure, created_at: 2.years.ago) }
|
||||
before { get :procedure, params: { procedure_id: procedure.id } }
|
||||
before { get :procedure, params: { procedure_id: procedure_to_show.id } }
|
||||
|
||||
it do
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(assigns(:avis_a_donner)).to match([avis_without_answer, oldest_avis_without_answer])
|
||||
expect(assigns(:avis_donnes)).to match([avis_with_answer])
|
||||
expect(assigns(:statut)).to eq('a-donner')
|
||||
context 'with legitimates avis' do
|
||||
let(:procedure_to_show) { procedure }
|
||||
|
||||
it do
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(assigns(:avis_a_donner)).to match([avis_without_answer, oldest_avis_without_answer])
|
||||
expect(assigns(:avis_donnes)).to match([avis_with_answer])
|
||||
expect(assigns(:statut)).to eq('a-donner')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a revoked avis' do
|
||||
let(:procedure_to_show) { revoked_procedure }
|
||||
|
||||
it { expect(response).to redirect_to expert_all_avis_path }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue