From 1977961b609e67e617926bc9f5e2332e35604a75 Mon Sep 17 00:00:00 2001 From: Jonathan Young Date: Thu, 7 Sep 2023 14:08:05 +0100 Subject: [PATCH] Update update_status failed render paths Updates the page to be rendered based on the attempted status update (i.e. if a denial failed, render the deny page) --- .../annual_leave_requests_controller.rb | 3 ++- .../annual_leave_requests_controller_spec.rb | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/controllers/annual_leave_requests_controller.rb b/app/controllers/annual_leave_requests_controller.rb index 6617af6..72e3211 100644 --- a/app/controllers/annual_leave_requests_controller.rb +++ b/app/controllers/annual_leave_requests_controller.rb @@ -40,7 +40,8 @@ def update_status helpers.send_approved_request_email(@annual_leave_request) redirect_to_status_update_confirmation_page else - render "approve" + render "approve" if annual_leave_request_params[:status] == "approved" + render "deny" if annual_leave_request_params[:status] == "denied" end end diff --git a/spec/controllers/annual_leave_requests_controller_spec.rb b/spec/controllers/annual_leave_requests_controller_spec.rb index 8766192..7db8a4b 100644 --- a/spec/controllers/annual_leave_requests_controller_spec.rb +++ b/spec/controllers/annual_leave_requests_controller_spec.rb @@ -52,17 +52,30 @@ sign_in line_manager end - it "renders the approve page if status update is unsuccessful" do + it "renders the approve page if a status update to 'approved' is unsuccessful" do patch :update_status, params: { annual_leave_request_id: leave_request.id, annual_leave_request: { confirm_approval: "unconfirmed", + status: "approved", }, } expect(response).to render_template(:approve) end + it "renders the deny page if a status update to 'denied' is unsuccessful" do + patch :update_status, params: { + annual_leave_request_id: leave_request.id, + annual_leave_request: { + denial_reason: "", + status: "denied", + }, + } + + expect(response).to render_template(:deny) + end + it "sends an email to the line report when status is updated to approved" do approved_request_email_hash = { email_address: user.email,