From 83fba55b2996eeaeb5849827d14323a79c85d81c Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Mon, 20 Apr 2020 14:47:24 +0200 Subject: [PATCH] refactor instruction_instructeur_avis_url --- app/controllers/instructeurs/avis_controller.rb | 4 ++-- app/models/avis.rb | 4 ++++ app/views/instructeurs/avis/_header.html.haml | 2 +- spec/controllers/instructeurs/avis_controller_spec.rb | 6 +++--- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/controllers/instructeurs/avis_controller.rb b/app/controllers/instructeurs/avis_controller.rb index 578ae1505..c5750f325 100644 --- a/app/controllers/instructeurs/avis_controller.rb +++ b/app/controllers/instructeurs/avis_controller.rb @@ -37,7 +37,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 @@ -65,7 +65,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 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/instructeurs/avis/_header.html.haml b/app/views/instructeurs/avis/_header.html.haml index 8f0e601a8..c5208f982 100644 --- a/app/views/instructeurs/avis/_header.html.haml +++ b/app/views/instructeurs/avis/_header.html.haml @@ -6,5 +6,5 @@ %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('Avis', instruction_instructeur_avis_path(avis.procedure, avis), notification: avis.answer.blank?) = dynamic_tab_item('Messagerie', messagerie_instructeur_avis_path(avis)) diff --git a/spec/controllers/instructeurs/avis_controller_spec.rb b/spec/controllers/instructeurs/avis_controller_spec.rb index 581244e38..87e2ba701 100644 --- a/spec/controllers/instructeurs/avis_controller_spec.rb +++ b/spec/controllers/instructeurs/avis_controller_spec.rb @@ -64,7 +64,7 @@ describe Instructeurs::AvisController, type: :controller do 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.') @@ -84,7 +84,7 @@ describe Instructeurs::AvisController, type: :controller do 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.') @@ -178,7 +178,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