From aa041784ddda68208dc76c63f84dc78dc8c16ac7 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Mon, 14 Nov 2022 11:44:07 +0000 Subject: [PATCH] Update routing to go back to location page (#988) --- app/controllers/locations_controller.rb | 6 +++++- app/helpers/check_answers_helper.rb | 2 +- spec/features/schemes_spec.rb | 4 ++-- spec/requests/locations_controller_spec.rb | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index 6cd40161f..7955ec944 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -98,7 +98,11 @@ class LocationsController < ApplicationController redirect_to(scheme_check_answers_path(@scheme, anchor: "locations")) end when "edit-name" - redirect_to(scheme_check_answers_path(@scheme, anchor: "locations")) + if @scheme.locations.count == @scheme.locations.active.count + redirect_to(scheme_location_path(@scheme, @location)) + else + redirect_to(scheme_check_answers_path(@scheme, anchor: "locations")) + end when "edit-local-authority" if params[:add_another_location] == "Yes" redirect_to(new_scheme_location_path(@location.scheme)) diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index 1583b3791..1d4a1a9aa 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -18,7 +18,7 @@ module CheckAnswersHelper def get_location_change_link_href_postcode(scheme, location) if location.confirmed? - scheme_location_edit_name_path(scheme_id: scheme.id, location_id: location.id) + scheme_location_path(scheme_id: scheme.id, id: location.id) else edit_scheme_location_path(scheme_id: scheme.id, id: location.id) end diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 48f386fa7..48ab31acc 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -801,9 +801,9 @@ RSpec.describe "Schemes scheme Features" do it "returns to locations check your answers page and shows the new name" do fill_in "location-name-field", with: "NewName" click_button "Save and continue" - expect(page).to have_content location.id + expect(page).to have_content location.postcode expect(page).to have_content "NewName" - expect(page.current_url.split("/").last).to eq("check-answers#locations") + expect(page).to have_current_path("/schemes/#{scheme.id}/locations/#{location.id}") end context "when I press the back button" do diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index feeae2b99..a666b6495 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -597,7 +597,7 @@ RSpec.describe LocationsController, type: :request do it "updates existing location for scheme with valid params and redirects to correct page" do follow_redirect! expect(response).to have_http_status(:ok) - expect(page).to have_content("Locations") + expect(page).to have_content("Test") end it "updates existing location for scheme with valid params" do @@ -736,7 +736,7 @@ RSpec.describe LocationsController, type: :request do it "updates existing location for scheme with valid params and redirects to correct page" do follow_redirect! expect(response).to have_http_status(:ok) - expect(page).to have_content("Locations") + expect(page).to have_content("Test") end it "updates existing location for scheme with valid params" do