diff --git a/app/controllers/instructeurs/avis_controller.rb b/app/controllers/instructeurs/avis_controller.rb index e85e301f1..6382da31d 100644 --- a/app/controllers/instructeurs/avis_controller.rb +++ b/app/controllers/instructeurs/avis_controller.rb @@ -11,7 +11,13 @@ module Instructeurs DONNES_STATUS = 'donnes' def index - instructeur_avis = current_instructeur.avis.includes(dossier: [:procedure, :user]) + avis = current_instructeur.avis.includes(dossier: [groupe_instructeur: :procedure]) + @avis_by_procedure = avis.to_a.group_by(&:procedure) + end + + def procedure + @procedure = Procedure.find(params[:procedure_id]) + instructeur_avis = current_instructeur.avis.includes(:dossier).where(dossiers: { groupe_instructeur: GroupeInstructeur.where(procedure: @procedure.id) }) @avis_a_donner = instructeur_avis.without_answer @avis_donnes = instructeur_avis.with_answer @@ -37,7 +43,7 @@ module Instructeurs def update if @avis.update(avis_params) flash.notice = 'Votre réponse est enregistrée.' - redirect_to instruction_instructeur_avis_path(@avis) + redirect_to instruction_instructeur_avis_path(@avis.procedure, @avis) else flash.now.alert = @avis.errors.full_messages @new_avis = Avis.new @@ -54,7 +60,7 @@ module Instructeurs if @commentaire.save flash.notice = "Message envoyé" - redirect_to messagerie_instructeur_avis_path(avis) + redirect_to messagerie_instructeur_avis_path(avis.procedure, avis) else flash.alert = @commentaire.errors.full_messages render :messagerie @@ -65,7 +71,7 @@ module Instructeurs @new_avis = create_avis_from_params(avis.dossier, avis.confidentiel) if @new_avis.nil? - redirect_to instruction_instructeur_avis_path(avis) + redirect_to instruction_instructeur_avis_path(avis.procedure, avis) else set_avis_and_dossier render :instruction @@ -89,6 +95,8 @@ module Instructeurs end def create_instructeur + procedure_id = params[:procedure_id] + avis_id = params[:id] email = params[:email] password = params[:user][:password] @@ -99,10 +107,10 @@ module Instructeurs sign_in(user) Avis.link_avis_to_instructeur(user.instructeur) - redirect_to url_for(instructeur_avis_index_path) + redirect_to url_for(instructeur_all_avis_path) else flash[:alert] = user.errors.full_messages - redirect_to url_for(sign_up_instructeur_avis_path(params[:id], email)) + redirect_to url_for(sign_up_instructeur_avis_path(procedure_id, avis_id, email)) end end @@ -119,7 +127,7 @@ module Instructeurs if current_instructeur.present? # a instructeur is authenticated ... lets see if it can view the dossier - redirect_to instructeur_avis_url(avis) + redirect_to instructeur_avis_url(avis.procedure, avis) elsif avis.instructeur&.email == params[:email] # the avis instructeur has already signed up and it sould sign in diff --git a/app/controllers/instructeurs/procedures_controller.rb b/app/controllers/instructeurs/procedures_controller.rb index c5c7e948b..68e01c1b0 100644 --- a/app/controllers/instructeurs/procedures_controller.rb +++ b/app/controllers/instructeurs/procedures_controller.rb @@ -284,7 +284,7 @@ module Instructeurs def redirect_to_avis_if_needed if current_instructeur.procedures.count == 0 && current_instructeur.avis.count > 0 - redirect_to instructeur_avis_index_path + redirect_to instructeur_all_avis_path end end diff --git a/app/helpers/dossier_link_helper.rb b/app/helpers/dossier_link_helper.rb index 93c9d9c16..8c356e925 100644 --- a/app/helpers/dossier_link_helper.rb +++ b/app/helpers/dossier_link_helper.rb @@ -6,7 +6,7 @@ module DossierLinkHelper else avis = dossier.avis.find_by(instructeur: user) if avis.present? - instructeur_avis_path(avis) + instructeur_avis_path(avis.procedure, avis) end end elsif user.owns_or_invite?(dossier) diff --git a/app/helpers/etablissement_helper.rb b/app/helpers/etablissement_helper.rb index 15128ce0d..4b23ba030 100644 --- a/app/helpers/etablissement_helper.rb +++ b/app/helpers/etablissement_helper.rb @@ -1,6 +1,6 @@ module EtablissementHelper def pretty_currency(capital_social, unit: '€') - number_to_currency(capital_social, locale: :fr, unit: unit) + number_to_currency(capital_social, locale: :fr, unit: unit, precision: 0) end def pretty_currency_unit(unit) diff --git a/app/models/avis.rb b/app/models/avis.rb index bf468b96a..7deb2cd6e 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -52,6 +52,10 @@ class Avis < ApplicationRecord ] end + def procedure + dossier.procedure + end + private def try_to_assign_instructeur diff --git a/app/views/avis_mailer/avis_invitation.html.haml b/app/views/avis_mailer/avis_invitation.html.haml index c0f3f4272..31a4ca6d7 100644 --- a/app/views/avis_mailer/avis_invitation.html.haml +++ b/app/views/avis_mailer/avis_invitation.html.haml @@ -1,5 +1,5 @@ - content_for(:title, 'Invitation à donner votre avis') -- avis_link = @avis.instructeur.present? ? instructeur_avis_url(@avis) : sign_up_instructeur_avis_url(@avis.id, @avis.email) +- avis_link = @avis.instructeur.present? ? instructeur_avis_url(@avis.procedure, @avis) : sign_up_instructeur_avis_url(@avis.procedure, @avis.id, @avis.email) - content_for(:footer) do Merci de ne pas répondre à cet email. Donnez votre avis @@ -15,7 +15,7 @@ Vous avez été invité par %strong= @avis.claimant.email = "à donner votre avis sur le dossier nº #{@avis.dossier.id} de la démarche :" - %strong= @avis.dossier.procedure.libelle + %strong= @avis.procedure.libelle %p = "#{@avis.claimant.email} vous a écrit :" diff --git a/app/views/dossiers/show.pdf.prawn b/app/views/dossiers/show.pdf.prawn index 366dc6fc6..b2eed9c09 100644 --- a/app/views/dossiers/show.pdf.prawn +++ b/app/views/dossiers/show.pdf.prawn @@ -8,11 +8,17 @@ def format_in_2_lines(pdf, label, text) pdf.text "\n", size: 9 end +def render_box(pdf, text, x, width) + box = ::Prawn::Text::Box.new(text, { document: pdf, width: width, overflow: :expand, at: [x, pdf.cursor] }) + box.render + box.height +end + def format_in_2_columns(pdf, label, text) - pdf.text_box label, width: 200, height: 100, overflow: :expand, at: [0, pdf.cursor] - pdf.text_box ":", width: 10, height: 100, overflow: :expand, at: [100, pdf.cursor] - pdf.text_box text, width: 420, height: 100, overflow: :expand, at: [110, pdf.cursor] - pdf.text "\n" + h1 = render_box(pdf, label, 0, 100) + h2 = render_box(pdf, ':', 100, 10) + h3 = render_box(pdf, text, 110, pdf.bounds.width - 110) + pdf.move_down 5 + [h1,h2,h3].max end def add_title(pdf, title) @@ -47,33 +53,32 @@ def render_siret_info(pdf, etablissement) end def render_identite_etablissement(pdf, etablissement) - pdf.text " - SIRET : #{etablissement.siret}" - pdf.text " - SIRET du siège social: #{etablissement.entreprise.siret_siege_social}" - pdf.text " - Dénomination : #{raison_sociale_or_name(etablissement)}" - pdf.text " - Forme juridique : #{etablissement.entreprise_forme_juridique}" + format_in_2_columns(pdf, "SIRET", etablissement.siret) + format_in_2_columns(pdf, "SIRET du siège social", etablissement.entreprise.siret_siege_social) if etablissement.entreprise.siret_siege_social.present? + format_in_2_columns(pdf, "Dénomination", raison_sociale_or_name(etablissement)) + format_in_2_columns(pdf, "Forme juridique ", etablissement.entreprise_forme_juridique) if etablissement.entreprise_capital_social.present? - pdf.text " - Capital social : #{pretty_currency(etablissement.entreprise_capital_social)}" + format_in_2_columns(pdf, "Capital social ", pretty_currency(etablissement.entreprise_capital_social)) end - pdf.text " - Libellé NAF : #{etablissement.libelle_naf}" - pdf.text " - Code NAF : #{etablissement.naf}" - pdf.text " - Date de création : #{try_format_date(etablissement.entreprise.date_creation)}" + format_in_2_columns(pdf, "Libellé NAF ", etablissement.libelle_naf) + format_in_2_columns(pdf, "Code NAF ", etablissement.naf) + format_in_2_columns(pdf, "Date de création ", try_format_date(etablissement.entreprise.date_creation)) if @include_infos_administration - pdf.text " - Effectif mensuel #{try_format_mois_effectif(etablissement)} (URSSAF) : #{etablissement.entreprise_effectif_mensuel}" - pdf.text " - Effectif moyen annuel #{etablissement.entreprise_effectif_annuel_annee} (URSSAF) : #{etablissement.entreprise_effectif_annuel}" + format_in_2_columns(pdf, "Effectif mensuel #{try_format_mois_effectif(etablissement)} (URSSAF) ", etablissement.entreprise_effectif_mensuel) + format_in_2_columns(pdf, "Effectif moyen annuel #{etablissement.entreprise_effectif_annuel_annee} (URSSAF) ", etablissement.entreprise_effectif_annuel) end - pdf.text " - Effectif de l'organisation (INSEE) : #{effectif(etablissement)}" - pdf.text " - Code effectif : #{etablissement.entreprise.code_effectif_entreprise}" - pdf.text " - Numéro de TVA intracommunautaire : #{etablissement.entreprise.numero_tva_intracommunautaire}" - pdf.text " - Adresse : #{etablissement.adresse}" + format_in_2_columns(pdf, "Effectif (ISPF) ", effectif(etablissement)) + format_in_2_columns(pdf, "Code effectif ", etablissement.entreprise.code_effectif_entreprise) + format_in_2_columns(pdf, "Numéro de TVA intracommunautaire ", etablissement.entreprise.numero_tva_intracommunautaire) if etablissement.entreprise.numero_tva_intracommunautaire.present? + format_in_2_columns(pdf, "Adresse ", etablissement.adresse) if etablissement.association? - pdf.text " - Numéro RNA : #{etablissement.association_rna}" - pdf.text " - Titre : #{etablissement.association_titre}" - pdf.text " - Objet : #{etablissement.association_objet}" - pdf.text " - Date de création : #{try_format_date(etablissement.association_date_creation)}" - pdf.text " - Date de publication : #{try_format_date(etablissement.association_date_publication)}" - pdf.text " - Date de déclaration : #{try_format_date(etablissement.association_date_declaration)}" + format_in_2_columns(pdf, "Numéro RNA ", etablissement.association_rna) + format_in_2_columns(pdf, "Titre ", etablissement.association_titre) + format_in_2_columns(pdf, "Objet ", etablissement.association_objet) + format_in_2_columns(pdf, "Date de création ", try_format_date(etablissement.association_date_creation)) + format_in_2_columns(pdf, "Date de publication ", try_format_date(etablissement.association_date_publication)) + format_in_2_columns(pdf, "Date de déclaration ", try_format_date(etablissement.association_date_declaration)) end - pdf.text "\n" end def render_single_champ(pdf, champ) diff --git a/app/views/instructeurs/avis/_header.html.haml b/app/views/instructeurs/avis/_header.html.haml index f0bfcd50d..0d2ab24e6 100644 --- a/app/views/instructeurs/avis/_header.html.haml +++ b/app/views/instructeurs/avis/_header.html.haml @@ -1,10 +1,11 @@ .sub-header .container %ul.breadcrumbs - %li= link_to('Avis', instructeur_avis_index_path) - %li= "#{dossier.procedure.libelle}, dossier nº #{dossier.id}" + %li= link_to('Avis', instructeur_all_avis_path) + %li= link_to(dossier.procedure.libelle, procedure_instructeur_avis_index_path(avis.procedure)) + %li= link_to("Dossier nº #{dossier.id}", instructeur_avis_path(avis.procedure, avis)) %ul.tabs - = dynamic_tab_item('Demande', instructeur_avis_path(avis)) - = dynamic_tab_item('Avis', instruction_instructeur_avis_path(avis), notification: avis.answer.blank?) - = dynamic_tab_item('Messagerie', messagerie_instructeur_avis_path(avis)) + = dynamic_tab_item('Demande', instructeur_avis_path(avis.procedure, avis)) + = dynamic_tab_item('Avis', instruction_instructeur_avis_path(avis.procedure, avis), notification: avis.answer.blank?) + = dynamic_tab_item('Messagerie', messagerie_instructeur_avis_path(avis.procedure, avis)) diff --git a/app/views/instructeurs/avis/index.html.haml b/app/views/instructeurs/avis/index.html.haml index 329995b7d..7b8838a3e 100644 --- a/app/views/instructeurs/avis/index.html.haml +++ b/app/views/instructeurs/avis/index.html.haml @@ -1,39 +1,41 @@ -- avis_statut = (@statut == Instructeurs::AvisController::A_DONNER_STATUS) ? 'à donner' : 'rendus' -- content_for(:title, "Avis #{avis_statut}") - -.sub-header - .container.flex - .width-100 - %h1.tab-title Avis - %ul.tabs - = tab_item('avis à donner', - instructeur_avis_index_path(statut: Instructeurs::AvisController::A_DONNER_STATUS), - active: @statut == Instructeurs::AvisController::A_DONNER_STATUS, - badge: @avis_a_donner.count, - notification: @avis_a_donner.any?) - - = tab_item("avis #{'donné'.pluralize(@avis_donnes.count)}", - instructeur_avis_index_path(statut: Instructeurs::AvisController::DONNES_STATUS), - active: @statut == Instructeurs::AvisController::DONNES_STATUS, - badge: @avis_donnes.count) +- content_for(:title, "Avis") .container - - if @avis.present? - %table.table.dossiers-table.hoverable - %thead - %tr - %th.number-col Nº dossier - %th Demandeur - %th Démarche - %tbody - - @avis.each do |avis| - %tr - %td.number-col - = link_to(instructeur_avis_path(avis), class: 'cell-link') do - %span.icon.folder - #{avis.dossier.id} - %td= link_to(avis.dossier.user.email, instructeur_avis_path(avis), class: 'cell-link') - %td= link_to(avis.dossier.procedure.libelle, instructeur_avis_path(avis), class: 'cell-link') - = paginate(@avis) - - else - %h2.empty-text Aucun avis + %h1.page-title Avis + + %ul.procedure-list + - @avis_by_procedure.each do |p, procedure_avis| + %li.procedure-item.flex.align-start + = link_to(procedure_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(procedure_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(procedure_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 diff --git a/app/views/instructeurs/avis/instruction.html.haml b/app/views/instructeurs/avis/instruction.html.haml index c891620c1..1cefc6aea 100644 --- a/app/views/instructeurs/avis/instruction.html.haml +++ b/app/views/instructeurs/avis/instruction.html.haml @@ -15,7 +15,7 @@ = render partial: 'shared/attachment/show', locals: { attachment: @avis.introduction_file.attachment } %br/ - = form_for @avis, url: instructeur_avis_path(@avis), html: { class: 'form' } do |f| + = form_for @avis, url: instructeur_avis_path(@avis.procedure, @avis), html: { class: 'form' } do |f| = f.text_area :answer, rows: 3, placeholder: 'Votre avis', required: true = render 'shared/attachment/edit', { form: f, @@ -35,7 +35,7 @@ = f.submit 'Envoyer votre avis', class: 'button send' - if !@dossier.termine? - = render partial: "instructeurs/shared/avis/form", locals: { url: avis_instructeur_avis_path(@avis), linked_dossiers: @dossier.linked_dossiers_for(current_instructeur), must_be_confidentiel: @avis.confidentiel?, avis: @new_avis } + = render partial: "instructeurs/shared/avis/form", locals: { url: avis_instructeur_avis_path(@avis.procedure, @avis), linked_dossiers: @dossier.linked_dossiers_for(current_instructeur), must_be_confidentiel: @avis.confidentiel?, avis: @new_avis } - if @dossier.avis_for(current_instructeur).present? = render partial: 'instructeurs/shared/avis/list', locals: { avis: @dossier.avis_for(current_instructeur), avis_seen_at: nil } diff --git a/app/views/instructeurs/avis/procedure.html.haml b/app/views/instructeurs/avis/procedure.html.haml new file mode 100644 index 000000000..f38d6cde3 --- /dev/null +++ b/app/views/instructeurs/avis/procedure.html.haml @@ -0,0 +1,45 @@ +- avis_statut = (@statut == Instructeurs::AvisController::A_DONNER_STATUS) ? 'à donner' : 'rendus' +- content_for(:title, "Avis #{avis_statut}") + +#procedure-show + .sub-header + .container.flex + + .procedure-logo{ style: "background-image: url(#{@procedure.logo_url})", + role: 'img', 'aria-label': "logo de la démarche #{@procedure.libelle}" } + + .procedure-header + %h1= procedure_libelle @procedure + + %ul.tabs + = tab_item('avis à donner', + procedure_instructeur_avis_index_path(statut: Instructeurs::AvisController::A_DONNER_STATUS), + active: @statut == Instructeurs::AvisController::A_DONNER_STATUS, + badge: @avis_a_donner.count, + notification: @avis_a_donner.any?) + + = tab_item("avis #{'donné'.pluralize(@avis_donnes.count)}", + procedure_instructeur_avis_index_path(statut: Instructeurs::AvisController::DONNES_STATUS), + active: @statut == Instructeurs::AvisController::DONNES_STATUS, + badge: @avis_donnes.count) + +.container + - if @avis.present? + %table.table.dossiers-table.hoverable + %thead + %tr + %th.number-col Nº dossier + %th Demandeur + %th Démarche + %tbody + - @avis.each do |avis| + %tr + %td.number-col + = link_to(instructeur_avis_path(avis.procedure, avis), class: 'cell-link') do + %span.icon.folder + #{avis.dossier.id} + %td= link_to(avis.dossier.user.email, instructeur_avis_path(avis.procedure, avis), class: 'cell-link') + %td= link_to(avis.procedure.libelle, instructeur_avis_path(avis.procedure, avis), class: 'cell-link') + = paginate(@avis) + - else + %h2.empty-text Aucun avis diff --git a/app/views/layouts/_new_header.haml b/app/views/layouts/_new_header.haml index 02cd3e321..c97277397 100644 --- a/app/views/layouts/_new_header.haml +++ b/app/views/layouts/_new_header.haml @@ -29,10 +29,10 @@ %ul.header-tabs - if current_instructeur.procedures.count > 0 %li - = active_link_to "Démarches", instructeur_procedures_path, active: :inclusive, class: 'tab-link' + = active_link_to "Démarches", instructeur_procedures_path, active: /^((?!avis).)*$/, class: 'tab-link' - if current_instructeur.avis.count > 0 %li - = active_link_to instructeur_avis_index_path, active: :inclusive, class: 'tab-link' do + = active_link_to instructeur_all_avis_path, active: /avis/, class: 'tab-link' do Avis - avis_counter = current_instructeur.avis.without_answer.count - if avis_counter > 0 diff --git a/app/views/root/_footer.html.haml b/app/views/root/_footer.html.haml index 8c9248971..49f29d593 100644 --- a/app/views/root/_footer.html.haml +++ b/app/views/root/_footer.html.haml @@ -12,9 +12,9 @@ = link_to "beta.gouv.fr", "https://beta.gouv.fr", title: "le site de Beta.gouv.fr" %li = link_to "https://numerique.gouv.fr/", title: "DINUM", 'aria-label': 'DINUM' do - %span.footer-logo.footer-logo-dinum{ role: 'img' } + %span.footer-logo.footer-logo-dinum{ role: 'img', 'aria-label': 'Logo DINUM' } = link_to "https://beta.gouv.fr", title: "le site de Beta.gouv.fr", 'aria-label': 'beta.gouv.fr' do - %span.footer-logo.footer-logo-beta-gouv-fr{ role: 'img' } + %span.footer-logo.footer-logo-beta-gouv-fr{ role: 'img', 'aria-label': 'Logo beta.gouv.fr' } %span.footer-logo.footer-logo-france{ role: 'img', 'aria-label': 'République Française' } %li.footer-column diff --git a/config/routes.rb b/config/routes.rb index cecce951f..67801ac80 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -300,6 +300,13 @@ Rails.application.routes.draw do # scope module: 'instructeurs', as: 'instructeur' do + get 'avis', to: 'avis#index', as: 'all_avis' + + # this redirections are ephemeral, to ensure that emails sent to experts before are still valid + # TODO : they will be removed in September, 2020 + get 'avis/:id', to: redirect('/procedures/old/avis/%{id}') + get 'avis/:id/sign_up/email/:email', to: redirect("/procedures/old/avis/%{id}/sign_up/email/%{email}"), constraints: { email: /.*/ } + resources :procedures, only: [:index, :show], param: :procedure_id do member do resources :groupes, only: [:index, :show], controller: 'groupe_instructeurs' do @@ -309,6 +316,20 @@ Rails.application.routes.draw do end end + resources :avis, only: [:show, :update] do + get '', action: 'procedure', on: :collection, as: :procedure + member do + get 'instruction' + get 'messagerie' + post 'commentaire' => 'avis#create_commentaire' + post 'avis' => 'avis#create_avis' + get 'bilans_bdf' + + get 'sign_up/email/:email' => 'avis#sign_up', constraints: { email: /.*/ }, as: 'sign_up' + post 'sign_up/email/:email' => 'avis#create_instructeur', constraints: { email: /.*/ } + end + end + patch 'update_displayed_fields' get 'update_sort/:table/:column' => 'procedures#update_sort', as: 'update_sort' post 'add_filter' @@ -347,18 +368,6 @@ Rails.application.routes.draw do end end end - resources :avis, only: [:index, :show, :update] do - member do - get 'instruction' - get 'messagerie' - post 'commentaire' => 'avis#create_commentaire' - post 'avis' => 'avis#create_avis' - get 'bilans_bdf' - - get 'sign_up/email/:email' => 'avis#sign_up', constraints: { email: /.*/ }, as: 'sign_up' - post 'sign_up/email/:email' => 'avis#create_instructeur', constraints: { email: /.*/ } - end - end get "recherche" => "recherche#index" end diff --git a/spec/controllers/instructeurs/avis_controller_spec.rb b/spec/controllers/instructeurs/avis_controller_spec.rb index c4d4462cb..811bc060e 100644 --- a/spec/controllers/instructeurs/avis_controller_spec.rb +++ b/spec/controllers/instructeurs/avis_controller_spec.rb @@ -4,7 +4,8 @@ describe Instructeurs::AvisController, type: :controller do let(:claimant) { create(:instructeur) } let(:instructeur) { create(:instructeur) } - let(:procedure) { create(:procedure, :published, instructeurs: [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') } @@ -14,20 +15,28 @@ describe Instructeurs::AvisController, type: :controller do describe '#index' do before { get :index } + 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 '#procedure' do + before { get :procedure, params: { procedure_id: procedure.id } } + it { expect(response).to have_http_status(:success) } it { expect(assigns(:avis_a_donner)).to match([avis_without_answer]) } it { expect(assigns(:avis_donnes)).to match([avis_with_answer]) } it { expect(assigns(:statut)).to eq('a-donner') } context 'with a statut equal to donnes' do - before { get :index, params: { statut: 'donnes' } } + before { get :procedure, params: { statut: 'donnes', procedure_id: procedure.id } } it { expect(assigns(:statut)).to eq('donnes') } end end describe '#show' do - before { get :show, params: { id: avis_without_answer.id } } + before { get :show, params: { id: avis_without_answer.id, procedure_id: procedure.id } } it { expect(response).to have_http_status(:success) } it { expect(assigns(:avis)).to eq(avis_without_answer) } @@ -35,7 +44,7 @@ describe Instructeurs::AvisController, type: :controller do end describe '#instruction' do - before { get :instruction, params: { id: avis_without_answer.id } } + before { get :instruction, params: { id: avis_without_answer.id, procedure_id: procedure.id } } it { expect(response).to have_http_status(:success) } it { expect(assigns(:avis)).to eq(avis_without_answer) } @@ -43,7 +52,7 @@ describe Instructeurs::AvisController, type: :controller do end describe '#messagerie' do - before { get :messagerie, params: { id: avis_without_answer.id } } + before { get :messagerie, params: { id: avis_without_answer.id, procedure_id: procedure.id } } it { expect(response).to have_http_status(:success) } it { expect(assigns(:avis)).to eq(avis_without_answer) } @@ -51,7 +60,7 @@ describe Instructeurs::AvisController, type: :controller do end describe '#bilans_bdf' do - before { get :bilans_bdf, params: { id: avis_without_answer.id } } + before { get :bilans_bdf, params: { id: avis_without_answer.id, procedure_id: procedure.id } } it { expect(response).to redirect_to(instructeur_avis_path(avis_without_answer)) } end @@ -59,12 +68,12 @@ describe Instructeurs::AvisController, type: :controller do describe '#update' do describe 'without attachment' do before do - patch :update, params: { id: avis_without_answer.id, avis: { answer: 'answer' } } + patch :update, params: { id: avis_without_answer.id, procedure_id: procedure.id, avis: { answer: 'answer' } } avis_without_answer.reload end it 'should be ok' do - expect(response).to redirect_to(instruction_instructeur_avis_path(avis_without_answer)) + expect(response).to redirect_to(instruction_instructeur_avis_path(avis_without_answer.procedure, avis_without_answer)) expect(avis_without_answer.answer).to eq('answer') expect(avis_without_answer.piece_justificative_file).to_not be_attached expect(flash.notice).to eq('Votre réponse est enregistrée.') @@ -78,13 +87,13 @@ describe Instructeurs::AvisController, type: :controller do before do expect(ClamavService).to receive(:safe_file?).and_return(true) perform_enqueued_jobs do - post :update, params: { id: avis_without_answer.id, avis: { answer: 'answer', piece_justificative_file: file } } + post :update, params: { id: avis_without_answer.id, procedure_id: procedure.id, avis: { answer: 'answer', piece_justificative_file: file } } end avis_without_answer.reload end it 'should be ok' do - expect(response).to redirect_to(instruction_instructeur_avis_path(avis_without_answer)) + expect(response).to redirect_to(instruction_instructeur_avis_path(avis_without_answer.procedure, avis_without_answer)) expect(avis_without_answer.answer).to eq('answer') expect(avis_without_answer.piece_justificative_file).to be_attached expect(flash.notice).to eq('Votre réponse est enregistrée.') @@ -96,7 +105,7 @@ describe Instructeurs::AvisController, type: :controller do let(:file) { nil } let(:scan_result) { true } - subject { post :create_commentaire, params: { id: avis_without_answer.id, commentaire: { body: 'commentaire body', piece_jointe: file } } } + subject { post :create_commentaire, params: { id: avis_without_answer.id, procedure_id: procedure.id, commentaire: { body: 'commentaire body', piece_jointe: file } } } before do allow(ClamavService).to receive(:safe_file?).and_return(scan_result) @@ -105,7 +114,7 @@ describe Instructeurs::AvisController, type: :controller do it do subject - expect(response).to redirect_to(messagerie_instructeur_avis_path(avis_without_answer)) + expect(response).to redirect_to(messagerie_instructeur_avis_path(avis_without_answer.procedure, avis_without_answer)) expect(dossier.commentaires.map(&:body)).to match(['commentaire body']) end @@ -131,7 +140,7 @@ describe Instructeurs::AvisController, type: :controller do before do @introduction_file = Rack::Test::UploadedFile.new("./spec/fixtures/files/piece_justificative_0.pdf", 'application/pdf') - post :create_avis, params: { id: previous_avis.id, avis: { emails: emails, introduction: intro, confidentiel: asked_confidentiel, invite_linked_dossiers: invite_linked_dossiers, introduction_file: @introduction_file } } + post :create_avis, params: { id: previous_avis.id, procedure_id: procedure.id, avis: { emails: emails, introduction: intro, confidentiel: asked_confidentiel, invite_linked_dossiers: invite_linked_dossiers, introduction_file: @introduction_file } } created_avis.reload end @@ -178,7 +187,7 @@ describe Instructeurs::AvisController, type: :controller do it { expect(created_avis.introduction).to eq(intro) } it { expect(created_avis.dossier).to eq(previous_avis.dossier) } it { expect(created_avis.claimant).to eq(instructeur) } - it { expect(response).to redirect_to(instruction_instructeur_avis_path(previous_avis)) } + it { expect(response).to redirect_to(instruction_instructeur_avis_path(previous_avis.procedure, previous_avis)) } end context 'when the user asked for a confidentiel avis' do @@ -255,6 +264,7 @@ describe Instructeurs::AvisController, type: :controller do describe '#sign_up' do let(:invited_email) { 'invited@avis.com' } let(:dossier) { create(:dossier) } + let(:procedure) { dossier.procedure } let!(:avis) { create(:avis, email: invited_email, dossier: dossier) } let(:invitations_email) { true } @@ -263,7 +273,7 @@ describe Instructeurs::AvisController, type: :controller do expect(Avis).to receive(:avis_exists_and_email_belongs_to_avis?) .with(avis.id.to_s, invited_email) .and_return(invitations_email) - get :sign_up, params: { id: avis.id, email: invited_email } + get :sign_up, params: { id: avis.id, procedure_id: procedure.id, email: invited_email } end context 'when the email belongs to the invitation' do @@ -286,15 +296,15 @@ describe Instructeurs::AvisController, type: :controller do context 'when the instructeur is authenticated' do before do sign_in(instructeur.user) - get :sign_up, params: { id: avis.id, email: invited_email } + get :sign_up, params: { id: avis.id, procedure_id: procedure.id, email: invited_email } end - it { is_expected.to redirect_to instructeur_avis_url(avis) } + it { is_expected.to redirect_to instructeur_avis_url(avis.procedure, avis) } end context 'when the instructeur is not authenticated' do before do - get :sign_up, params: { id: avis.id, email: invited_email } + get :sign_up, params: { id: avis.id, procedure_id: procedure.id, email: invited_email } end it { is_expected.to redirect_to new_user_session_url } @@ -307,11 +317,11 @@ describe Instructeurs::AvisController, type: :controller do before do sign_in(instructeur.user) - get :sign_up, params: { id: avis.id, email: invited_email } + get :sign_up, params: { id: avis.id, procedure_id: procedure.id, email: invited_email } end # redirected to dossier but then the instructeur gonna be banished ! - it { is_expected.to redirect_to instructeur_avis_url(avis) } + it { is_expected.to redirect_to instructeur_avis_url(avis.procedure, avis) } end end @@ -320,6 +330,7 @@ describe Instructeurs::AvisController, type: :controller do let!(:existing_user) { create(:user, email: existing_user_mail) } let(:invited_email) { 'invited@avis.com' } let(:dossier) { create(:dossier) } + let(:procedure) { dossier.procedure } let!(:avis) { create(:avis, email: invited_email, dossier: dossier) } let(:avis_id) { avis.id } let(:password) { 'démarches-simplifiées-pwd' } @@ -334,6 +345,7 @@ describe Instructeurs::AvisController, type: :controller do post :create_instructeur, params: { id: avis_id, + procedure_id: procedure.id, email: invited_email, user: { password: password @@ -355,7 +367,7 @@ describe Instructeurs::AvisController, type: :controller do it { expect(Avis).to have_received(:link_avis_to_instructeur) } it { expect(subject.current_instructeur).to eq(created_instructeur) } - it { is_expected.to redirect_to instructeur_avis_index_path } + it { is_expected.to redirect_to instructeur_all_avis_path } it 'creates a corresponding user account for the email' do user = User.find_by(email: invited_email) @@ -375,7 +387,7 @@ describe Instructeurs::AvisController, type: :controller do let(:password) { '' } it { expect(created_instructeur).to be_nil } - it { is_expected.to redirect_to sign_up_instructeur_avis_path(avis_id, invited_email) } + it { is_expected.to redirect_to sign_up_instructeur_avis_path(procedure.id, avis_id, invited_email) } it { expect(flash.alert).to eq(['Le mot de passe doit être rempli']) } end end diff --git a/spec/controllers/instructeurs/procedures_controller_spec.rb b/spec/controllers/instructeurs/procedures_controller_spec.rb index 9b91ed178..f48b9df44 100644 --- a/spec/controllers/instructeurs/procedures_controller_spec.rb +++ b/spec/controllers/instructeurs/procedures_controller_spec.rb @@ -76,7 +76,7 @@ describe Instructeurs::ProceduresController, type: :controller do end it "redirects avis" do - expect(@controller).to have_received(:redirect_to).with(instructeur_avis_index_path) + expect(@controller).to have_received(:redirect_to).with(instructeur_all_avis_path) end end end diff --git a/spec/features/accessibilite/wcag_usager_spec.rb b/spec/features/accessibilite/wcag_usager_spec.rb index 30064e805..d54afe7ee 100644 --- a/spec/features/accessibilite/wcag_usager_spec.rb +++ b/spec/features/accessibilite/wcag_usager_spec.rb @@ -6,12 +6,12 @@ feature 'wcag rules for usager', js: true do context 'pages without the need to be logged in' do scenario 'homepage' do visit root_path - expect(page).to be_accessible.excluding ".footer-logo" + expect(page).to be_accessible end scenario 'sign_up page' do visit new_user_registration_path - expect(page).to be_accessible.excluding ".footer-logo" + expect(page).to be_accessible end scenario 'account confirmation page' do @@ -28,12 +28,12 @@ feature 'wcag rules for usager', js: true do scenario 'sign_in page' do visit new_user_session_path - expect(page).to be_accessible.excluding ".footer-logo", '#user_email' + expect(page).to be_accessible.excluding '#user_email' end scenario 'contact page' do visit contact_path - expect(page).to be_accessible.excluding ".footer-logo" + expect(page).to be_accessible end scenario 'commencer page' do diff --git a/spec/features/instructeurs/expert_spec.rb b/spec/features/instructeurs/expert_spec.rb index aa3ebf0b8..c8700e5d3 100644 --- a/spec/features/instructeurs/expert_spec.rb +++ b/spec/features/instructeurs/expert_spec.rb @@ -42,7 +42,7 @@ feature 'Inviting an expert:' do invitation_email = open_email('expert2@exemple.fr') avis = Avis.find_by(email: 'expert2@exemple.fr', dossier: dossier) - sign_up_link = sign_up_instructeur_avis_path(avis.id, avis.email) + sign_up_link = sign_up_instructeur_avis_path(avis.dossier.procedure, avis, avis.email) expect(invitation_email.body).to include(sign_up_link) end @@ -71,14 +71,14 @@ feature 'Inviting an expert:' do let(:avis_email) { 'not-signed-up-expert@exemple.fr' } scenario 'I can sign up' do - visit sign_up_instructeur_avis_path(avis.id, avis_email) + visit sign_up_instructeur_avis_path(avis.dossier.procedure, avis, avis_email) expect(page).to have_field('Email', with: avis_email, disabled: true) 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 @@ -86,13 +86,13 @@ feature 'Inviting an expert:' do let(:avis_email) { expert.email } scenario 'I can sign in' do - visit sign_up_instructeur_avis_path(avis.id, avis_email) + visit sign_up_instructeur_avis_path(avis.dossier.procedure, avis, avis_email) 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 diff --git a/spec/features/instructeurs/instruction_spec.rb b/spec/features/instructeurs/instruction_spec.rb index 017942f90..2b03cfa8c 100644 --- a/spec/features/instructeurs/instruction_spec.rb +++ b/spec/features/instructeurs/instruction_spec.rb @@ -159,12 +159,6 @@ feature 'Instructing a dossier:' do click_on 'Demander un avis' end - def test_mail(to, content) - mail = ActionMailer::Base.deliveries.last - expect(mail.to).to match([to]) - expect(mail.body.parts.map(&:to_s)).to all(include(content)) - end - def test_statut_bar(a_suivre: 0, suivi: 0, traite: 0, tous_les_dossiers: 0, archive: 0) texts = [ "à suivre #{a_suivre}", @@ -177,13 +171,6 @@ feature 'Instructing a dossier:' do texts.each { |text| expect(page).to have_text(text) } end - def avis_sign_up(avis, email) - visit sign_up_instructeur_avis_path(avis, email) - fill_in 'user_password', with: 'démarches-simplifiées-pwd' - click_on 'Créer un compte' - expect(page).to have_current_path(instructeur_avis_index_path) - end - def dossier_present?(id, statut) within(:css, '.dossiers-table') do expect(page).to have_text(id) diff --git a/spec/helpers/dossier_link_helper_spec.rb b/spec/helpers/dossier_link_helper_spec.rb index 7b43b37ec..c8f04fab1 100644 --- a/spec/helpers/dossier_link_helper_spec.rb +++ b/spec/helpers/dossier_link_helper_spec.rb @@ -29,7 +29,7 @@ describe DossierLinkHelper do let(:instructeur) { create(:instructeur) } let!(:avis) { create(:avis, dossier: dossier, instructeur: instructeur) } - it { expect(helper.dossier_linked_path(instructeur, dossier)).to eq(instructeur_avis_path(avis)) } + it { expect(helper.dossier_linked_path(instructeur, dossier)).to eq(instructeur_avis_path(avis.dossier.procedure, avis)) } end context "when access as user" do diff --git a/spec/helpers/etablissement_helper_spec.rb b/spec/helpers/etablissement_helper_spec.rb index 94632791e..6573797e8 100644 --- a/spec/helpers/etablissement_helper_spec.rb +++ b/spec/helpers/etablissement_helper_spec.rb @@ -49,13 +49,13 @@ RSpec.describe EtablissementHelper, type: :helper do describe '#pretty_currency' do subject { pretty_currency(etablissement.entreprise_capital_social) } - it { is_expected.to eq('123 000,00 €') } + it { is_expected.to eq('123 000 €') } end describe '#pretty_currency with special unit' do subject { pretty_currency(12345, unit: 'k€') } - it { is_expected.to eq('12 345,00 k€') } + it { is_expected.to eq('12 345 k€') } end describe '#pretty_date_exercice' do subject { pretty_date_exercice("201908") } diff --git a/spec/mailers/avis_mailer_spec.rb b/spec/mailers/avis_mailer_spec.rb index ff9f5bd7d..163e77205 100644 --- a/spec/mailers/avis_mailer_spec.rb +++ b/spec/mailers/avis_mailer_spec.rb @@ -7,7 +7,7 @@ RSpec.describe AvisMailer, type: :mailer do it { expect(subject.subject).to eq("Donnez votre avis sur le dossier nº #{avis.dossier.id} (#{avis.dossier.procedure.libelle})") } it { expect(subject.body).to have_text("Vous avez été invité par\r\n#{avis.claimant.email}\r\nà donner votre avis sur le dossier nº #{avis.dossier.id} de la démarche :\r\n#{avis.dossier.procedure.libelle}") } it { expect(subject.body).to include(avis.introduction) } - it { expect(subject.body).to include(instructeur_avis_url(avis)) } + it { expect(subject.body).to include(instructeur_avis_url(avis.dossier.procedure.id, avis)) } context 'when the recipient is not already registered' do before do @@ -15,7 +15,7 @@ RSpec.describe AvisMailer, type: :mailer do avis.instructeur = nil end - it { expect(subject.body).to include(sign_up_instructeur_avis_url(avis.id, avis.email)) } + it { expect(subject.body).to include(sign_up_instructeur_avis_url(avis.dossier.procedure.id, avis.id, avis.email)) } end end end