From ec303b7fa63bf7429226cd49e3fd755ddaaaa881 Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 17 Mar 2023 16:37:05 +0000 Subject: [PATCH] Set local authority before validation --- app/models/location.rb | 2 +- spec/features/schemes_helpers.rb | 6 ++++-- spec/features/schemes_spec.rb | 6 ++++-- spec/requests/locations_controller_spec.rb | 4 ++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/models/location.rb b/app/models/location.rb index c33caee4e..48689ef71 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -14,7 +14,7 @@ class Location < ApplicationRecord has_paper_trail - before_save :lookup_postcode!, if: :postcode_changed? + before_validation :lookup_postcode!, if: :postcode_changed? auto_strip_attributes :name diff --git a/spec/features/schemes_helpers.rb b/spec/features/schemes_helpers.rb index 4ce1063c1..d5e5a8e22 100644 --- a/spec/features/schemes_helpers.rb +++ b/spec/features/schemes_helpers.rb @@ -64,7 +64,8 @@ module SchemesHelpers click_button "Add a location" fill_in with: "AA11AA" click_button "Save and continue" - fill_in with: "Adur" + select "Adur" + click_button "Save and continue" fill_in with: "Some name" click_button "Save and continue" fill_in with: 5 @@ -84,7 +85,8 @@ module SchemesHelpers click_button "Add a location" fill_in with: "AA12AA" click_button "Save and continue" - fill_in with: "Adur" + select "Adur" + click_button "Save and continue" fill_in with: "Other name" click_button "Save and continue" fill_in with: 2 diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index fefa3ea56..15487fc53 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -284,7 +284,8 @@ RSpec.describe "Schemes scheme Features" do before do fill_in with: "AA12AA" click_button "Save and continue" - fill_in with: "Adur" + select "Adur" + click_button "Save and continue" fill_in with: location_name click_button "Save and continue" fill_in with: 1 @@ -904,7 +905,8 @@ RSpec.describe "Schemes scheme Features" do before do fill_in with: "AA12AA" click_button "Save and continue" - fill_in with: "Adur" + select "Adur" + click_button "Save and continue" fill_in with: location_name click_button "Save and continue" fill_in with: 1 diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index 3b75339ff..154d18735 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -417,7 +417,7 @@ RSpec.describe LocationsController, type: :request do it "redirects correctly when postcodes.io does return a local authority" do follow_redirect! - expect(page).to have_content("What is the name of this location?") + expect(page).to have_content("What is the local authority") end end @@ -478,7 +478,7 @@ RSpec.describe LocationsController, type: :request do it "redirects correctly when postcodes.io does return a local authority" do follow_redirect! - expect(page).to have_content("What is the name of this location?") + expect(page).to have_content("What is the local authority") end end