display all avis for an expert
This commit is contained in:
parent
29e2d3d7eb
commit
63dd71aed4
4 changed files with 65 additions and 9 deletions
|
@ -10,6 +10,11 @@ module Instructeurs
|
|||
A_DONNER_STATUS = 'a-donner'
|
||||
DONNES_STATUS = 'donnes'
|
||||
|
||||
def all
|
||||
avis = current_instructeur.avis.includes(dossier: [groupe_instructeur: :procedure])
|
||||
@avis_by_procedure = avis.to_a.group_by(&:procedure)
|
||||
end
|
||||
|
||||
def index
|
||||
@procedure = Procedure.find(params[:procedure_id])
|
||||
instructeur_avis = current_instructeur.avis.includes(:dossier).where(dossiers: { groupe_instructeur: GroupeInstructeur.where(procedure: @procedure.id) })
|
||||
|
|
41
app/views/instructeurs/avis/all.html.haml
Normal file
41
app/views/instructeurs/avis/all.html.haml
Normal file
|
@ -0,0 +1,41 @@
|
|||
- content_for(:title, "Avis")
|
||||
|
||||
.container
|
||||
%h1.page-title Avis
|
||||
|
||||
%ul.procedure-list
|
||||
- @avis_by_procedure.each do |p, procedure_avis|
|
||||
%li.procedure-item.flex.align-start
|
||||
= link_to(instructeur_avis_index_path(p)) do
|
||||
.flex
|
||||
|
||||
.procedure-logo{ style: "background-image: url(#{p.logo_url})" }
|
||||
|
||||
.procedure-details
|
||||
%p.procedure-title
|
||||
= procedure_libelle p
|
||||
%ul.procedure-stats.flex
|
||||
%li
|
||||
%object
|
||||
= link_to(instructeur_avis_index_path(p, statut: Instructeurs::AvisController::A_DONNER_STATUS)) do
|
||||
- without_answer_count = procedure_avis.select { |a| a.answer.nil? }.size
|
||||
- if without_answer_count > 0
|
||||
%span.notifications{ 'aria-label': "notifications" }
|
||||
.stats-number
|
||||
= without_answer_count
|
||||
.stats-legend
|
||||
avis à donner
|
||||
%li
|
||||
%object
|
||||
= link_to(instructeur_avis_index_path(p, statut: Instructeurs::AvisController::DONNES_STATUS)) do
|
||||
- with_answer_count = procedure_avis.select { |a| a.answer.present? }.size
|
||||
.stats-number= with_answer_count
|
||||
.stats-legend
|
||||
= pluralize(with_answer_count, "avis donné")
|
||||
|
||||
- if p.close?
|
||||
.procedure-status
|
||||
%span.label Close
|
||||
- elsif p.depubliee?
|
||||
.procedure-status
|
||||
%span.label Dépubliée
|
|
@ -5,12 +5,21 @@ describe Instructeurs::AvisController, type: :controller do
|
|||
let(:claimant) { create(:instructeur) }
|
||||
let(:instructeur) { create(:instructeur) }
|
||||
let(:procedure) { create(:procedure, :published, instructeurs: [claimant]) }
|
||||
let(:another_procedure) { create(:procedure, :published, instructeurs: [claimant]) }
|
||||
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
||||
let!(:avis_without_answer) { Avis.create(dossier: dossier, claimant: claimant, instructeur: instructeur) }
|
||||
let!(:avis_with_answer) { Avis.create(dossier: dossier, claimant: claimant, instructeur: instructeur, answer: 'yop') }
|
||||
|
||||
before { sign_in(instructeur.user) }
|
||||
|
||||
describe '#all' do
|
||||
before { get :all }
|
||||
|
||||
it { expect(response).to have_http_status(:success) }
|
||||
it { expect(assigns(:avis_by_procedure).flatten).to include(procedure) }
|
||||
it { expect(assigns(:avis_by_procedure).flatten).not_to include(another_procedure) }
|
||||
end
|
||||
|
||||
describe '#index' do
|
||||
before { get :index, params: { procedure_id: procedure.id } }
|
||||
|
||||
|
|
|
@ -77,8 +77,8 @@ feature 'Inviting an expert:' do
|
|||
fill_in 'Mot de passe', with: 'This is a very complicated password !'
|
||||
click_on 'Créer un compte'
|
||||
|
||||
expect(page).to have_current_path(instructeur_avis_index_path)
|
||||
expect(page).to have_text('avis à donner 1')
|
||||
expect(page).to have_current_path(instructeur_all_avis_path)
|
||||
expect(page).to have_text('1 avis à donner')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -91,8 +91,8 @@ feature 'Inviting an expert:' do
|
|||
expect(page).to have_current_path(new_user_session_path)
|
||||
sign_in_with(expert.email, expert_password)
|
||||
|
||||
expect(page).to have_current_path(instructeur_avis_index_path)
|
||||
expect(page).to have_text('avis à donner 1')
|
||||
expect(page).to have_current_path(instructeur_all_avis_path)
|
||||
expect(page).to have_text('1 avis à donner')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -100,10 +100,11 @@ feature 'Inviting an expert:' do
|
|||
avis # create avis
|
||||
login_as expert.user, scope: :user
|
||||
|
||||
visit instructeur_avis_index_path
|
||||
expect(page).to have_text('avis à donner 1')
|
||||
expect(page).to have_text('avis donnés 0')
|
||||
visit instructeur_all_avis_path
|
||||
expect(page).to have_text('1 avis à donner')
|
||||
expect(page).to have_text('0 avis donnés')
|
||||
|
||||
click_on '1 avis à donner'
|
||||
click_on avis.dossier.user.email
|
||||
|
||||
within('.tabs') { click_on 'Avis' }
|
||||
|
@ -119,8 +120,8 @@ feature 'Inviting an expert:' do
|
|||
expect(page).to have_content('RIB.pdf')
|
||||
|
||||
within('.new-header') { click_on 'Avis' }
|
||||
expect(page).to have_text('avis à donner 0')
|
||||
expect(page).to have_text('avis donné 1')
|
||||
expect(page).to have_text('0 avis à donner')
|
||||
expect(page).to have_text('1 avis donné')
|
||||
end
|
||||
|
||||
# TODO
|
||||
|
|
Loading…
Reference in a new issue