diff --git a/app/helpers/tab_nav_helper.rb b/app/helpers/tab_nav_helper.rb index 7af63aeb1..6e482b7ff 100644 --- a/app/helpers/tab_nav_helper.rb +++ b/app/helpers/tab_nav_helper.rb @@ -1,5 +1,4 @@ module TabNavHelper - using RefinementTest include GovukLinkHelper def user_cell(user) @@ -8,7 +7,7 @@ module TabNavHelper end def location_cell(location, link) - link_text = location.postcode.formatted_postcode + link_text = location.postcode [govuk_link_to(link_text, link, method: :patch), "Location #{location.name}"].join("\n") end diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 843e26be6..a37836116 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -56,7 +56,7 @@ class CaseLog < ApplicationRecord scope :filter_by_id, ->(id) { where(id:) } scope :filter_by_tenant_code, ->(tenant_code) { where("tenancycode ILIKE ?", "%#{tenant_code}%") } scope :filter_by_propcode, ->(propcode) { where("propcode ILIKE ?", "%#{propcode}%") } - scope :filter_by_postcode, ->(postcode_full) { where("postcode_full ILIKE ?", "%#{postcode_full.gsub(/\s+/, '')}%") } + scope :filter_by_postcode, ->(postcode_full) { where("postcode_full ILIKE ?", "%#{UKPostcode.parse(postcode_full)}%") } scope :search_by, lambda { |param| filter_by_id(param) .or(filter_by_tenant_code(param)) @@ -117,6 +117,22 @@ class CaseLog < ApplicationRecord end end + def postcode_full=(postcode) + if postcode + super UKPostcode.parse(postcode).to_s + else + super nil + end + end + + def ppostcode_full=(postcode) + if postcode + super UKPostcode.parse(postcode).to_s + else + super nil + end + end + def completed? status == "completed" end diff --git a/app/models/form/setup/questions/location_id.rb b/app/models/form/setup/questions/location_id.rb index 79a3c2d18..cc8e1daf6 100644 --- a/app/models/form/setup/questions/location_id.rb +++ b/app/models/form/setup/questions/location_id.rb @@ -1,6 +1,4 @@ class Form::Setup::Questions::LocationId < ::Form::Question - using RefinementTest - def initialize(_id, hsh, page) super("location_id", hsh, page) @check_answer_label = "Location" @@ -20,7 +18,7 @@ class Form::Setup::Questions::LocationId < ::Form::Question return answer_opts unless ActiveRecord::Base.connected? Location.select(:id, :postcode, :name).where("startdate <= ? or startdate IS NULL", Time.zone.today).each_with_object(answer_opts) do |location, hsh| - hsh[location.id.to_s] = { "value" => location.postcode.formatted_postcode, "hint" => location.name } + hsh[location.id.to_s] = { "value" => location.postcode, "hint" => location.name } hsh end end diff --git a/app/models/location.rb b/app/models/location.rb index c21917b70..b0670d589 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -7,7 +7,7 @@ class Location < ApplicationRecord attr_accessor :add_another_location - scope :search_by_postcode, ->(postcode) { where("postcode ILIKE ?", "%#{postcode.gsub(/\s+/, '')}%") } + scope :search_by_postcode, ->(postcode) { where("postcode ILIKE ?", "%#{UKPostcode.parse(postcode)}%") } scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") } scope :search_by, ->(param) { search_by_name(param).or(search_by_postcode(param)) } @@ -41,6 +41,14 @@ class Location < ApplicationRecord ] end + def postcode=(postcode) + if postcode + super UKPostcode.parse(postcode).to_s + else + super nil + end + end + private PIO = PostcodeService.new diff --git a/app/models/scheme.rb b/app/models/scheme.rb index 5ac48b310..bf9111d9b 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -6,7 +6,7 @@ class Scheme < ApplicationRecord scope :filter_by_id, ->(id) { where(id: (id.start_with?("S") ? id[1..] : id)) } scope :search_by_service_name, ->(name) { where("service_name ILIKE ?", "%#{name}%") } - scope :search_by_postcode, ->(postcode) { joins("LEFT JOIN locations ON locations.scheme_id = schemes.id").where("locations.postcode ILIKE ?", "%#{postcode.delete(' ')}%") } + scope :search_by_postcode, ->(postcode) { joins("LEFT JOIN locations ON locations.scheme_id = schemes.id").where("locations.postcode ILIKE ?", "%#{UKPostcode.parse(postcode)}%") } scope :search_by, ->(param) { search_by_postcode(param).or(search_by_service_name(param)).or(filter_by_id(param)).distinct } validate :validate_confirmed diff --git a/app/services/imports/case_logs_import_service.rb b/app/services/imports/case_logs_import_service.rb index 814acfb43..96811487f 100644 --- a/app/services/imports/case_logs_import_service.rb +++ b/app/services/imports/case_logs_import_service.rb @@ -442,10 +442,10 @@ module Imports def compose_postcode(xml_doc, outcode, incode) outcode_value = string_or_nil(xml_doc, outcode) incode_value = string_or_nil(xml_doc, incode) - if outcode_value.nil? || incode_value.nil? || !"#{outcode_value}#{incode_value}".match(POSTCODE_REGEXP) + if outcode_value.nil? || incode_value.nil? || !"#{outcode_value} #{incode_value}".match(POSTCODE_REGEXP) nil else - "#{outcode_value}#{incode_value}" + "#{outcode_value} #{incode_value}" end end diff --git a/app/services/refinement_test.rb b/app/services/refinement_test.rb deleted file mode 100644 index fd59a853c..000000000 --- a/app/services/refinement_test.rb +++ /dev/null @@ -1,17 +0,0 @@ -module RefinementTest - refine String do - def formatted_postcode - postcode = upcase.gsub(/\s+/, "") - case postcode.length - when 5 - postcode.insert(2, " ") - when 6 - postcode.insert(3, " ") - when 7 - postcode.insert(4, " ") - else - self - end - end - end -end diff --git a/spec/features/form/conditional_questions_spec.rb b/spec/features/form/conditional_questions_spec.rb index 9b5c01a20..f8b5aafed 100644 --- a/spec/features/form/conditional_questions_spec.rb +++ b/spec/features/form/conditional_questions_spec.rb @@ -40,7 +40,7 @@ RSpec.describe "Form Conditional Questions" do it "is displayed correctly" do case_log.update!(postcode_known: 1, postcode_full: "NW1 6RT") visit("/logs/#{id}/property-postcode") - expect(page).to have_field("case-log-postcode-full-field", with: "NW16RT") + expect(page).to have_field("case-log-postcode-full-field", with: "NW1 6RT") end end end diff --git a/spec/features/schemes_helpers.rb b/spec/features/schemes_helpers.rb index 5db3917fa..f903a3de0 100644 --- a/spec/features/schemes_helpers.rb +++ b/spec/features/schemes_helpers.rb @@ -68,7 +68,7 @@ module SchemesHelpers end def fill_in_and_save_second_location - fill_in "Postcode", with: "XX1 1XX" + fill_in "Postcode", with: "AA1 2AA" fill_in "Location name (optional)", with: "Other name" fill_in "Total number of units at this location", with: 2 choose "Self-contained house" diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 7ad8ac832..bd088f70b 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -1,8 +1,6 @@ require "rails_helper" require_relative "schemes_helpers" -using RefinementTest - RSpec.describe "Schemes scheme Features" do include SchemesHelpers context "when viewing list of schemes" do @@ -205,7 +203,7 @@ RSpec.describe "Schemes scheme Features" do it "shows details of those locations" do locations.each do |location| expect(page).to have_content(location.id) - expect(page).to have_content(location.postcode.formatted_postcode) + expect(page).to have_content(location.postcode) expect(page).to have_content(location.units) expect(page).to have_content(location.type_of_unit) expect(page).to have_content(location.startdate&.to_formatted_s(:govuk_date)) @@ -495,7 +493,7 @@ RSpec.describe "Schemes scheme Features" do it "displays information about newly created location" do click_link "Add a location" fill_in_and_save_second_location - expect(page).to have_content "XX1 1XX" + expect(page).to have_content "AA1 2AA" expect(page).to have_content "Other name" expect(page).to have_content "Self-contained house" end @@ -509,13 +507,13 @@ RSpec.describe "Schemes scheme Features" do end it "displays changed location" do - click_link "XX1 1XX" - fill_in "Postcode", with: "ZZ1 1ZZ" + click_link "AA1 2AA" + fill_in "Postcode", with: "AA1 3AA" choose "location-mobility-type-wheelchair-user-standard-field" click_button "Save and continue" expect(page).to have_content "Locations" expect(page).to have_content "#{scheme.locations.count} location" - expect(page).to have_content "ZZ1 1ZZ" + expect(page).to have_content "AA1 3AA" end end @@ -725,7 +723,7 @@ RSpec.describe "Schemes scheme Features" do context "when I click to change location name" do before do - click_link(location.postcode.formatted_postcode) + click_link(location.postcode) end it "shows available fields to edit" do diff --git a/spec/fixtures/exports/general_needs_log.csv b/spec/fixtures/exports/general_needs_log.csv index e38480513..8a2dd1764 100644 --- a/spec/fixtures/exports/general_needs_log.csv +++ b/spec/fixtures/exports/general_needs_log.csv @@ -1,2 +1,2 @@ status,tenancycode,age1,sex1,ethnic,national,prevten,ecstat1,hhmemb,age2,sex2,ecstat2,age3,sex3,ecstat3,age4,sex4,ecstat4,age5,sex5,ecstat5,age6,sex6,ecstat6,age7,sex7,ecstat7,age8,sex8,ecstat8,homeless,underoccupation_benefitcap,leftreg,reservist,illness,preg_occ,startertenancy,tenancylength,tenancy,ppostcode_full,rsnvac,unittype_gn,beds,offered,wchair,earnings,incfreq,benefits,period,layear,waityear,postcode_full,reasonpref,cbl,chr,cap,reasonother,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,illness_type_1,illness_type_2,illness_type_3,illness_type_4,illness_type_8,illness_type_5,illness_type_6,illness_type_7,illness_type_9,illness_type_10,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,tenancyother,irproduct_other,reason,propcode,la,prevloc,hb,hbrentshortfall,mrcdate,incref,startdate,armedforces,unitletas,builtype,voiddate,renttype,needstype,lettype,totchild,totelder,totadult,nocharge,referral,brent,scharge,pscharge,supcharg,tcharge,tshortfall,chcharge,ppcodenk,has_benefits,renewal,wrent,wscharge,wpschrge,wsupchrg,wtcharge,wtshortfall,refused,housingneeds,wchchrg,newprop,relat2,relat3,relat4,relat5,relat6,relat7,relat8,lar,irproduct,joint,sheltered,hhtype,new_old,vacdays,form,owningorgid,owningorgname,hcnum,maningorgid,maningorgname,manhcnum,createddate,uploaddate -2,BZ737,35,F,2,4,6,0,2,32,M,6,,,,,,,,,,,,,,,,,,,1,0,1,0,1,2,1,5,1,SE26RT,6,7,3,2,1,68,1,1,2,2,1,NW15TY,1,1,1,2,,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,,,4,123,E09000003,E07000105,6,1,2020-05-05 10:36:49 UTC,0,2022-02-02 10:36:49 UTC,1,2,1,2019-11-03 00:00:00 UTC,2,1,7,0,0,2,0,2,200.0,50.0,40.0,35.0,325.0,12.0,,1,1,0,100.0,25.0,20.0,17.5,162.5,6.0,0,1,,2,P,,,,,,,,,,,4,2,638,{id},{owning_org_id},DLUHC,1234,{managing_org_id},DLUHC,1234,2022-02-08 16:52:15 UTC,2022-02-08 16:52:15 UTC +2,BZ737,35,F,2,4,6,0,2,32,M,6,,,,,,,,,,,,,,,,,,,1,0,1,0,1,2,1,5,1,SE2 6RT,6,7,3,2,1,68,1,1,2,2,1,NW1 5TY,1,1,1,2,,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,,,4,123,E09000003,E07000105,6,1,2020-05-05 10:36:49 UTC,0,2022-02-02 10:36:49 UTC,1,2,1,2019-11-03 00:00:00 UTC,2,1,7,0,0,2,0,2,200.0,50.0,40.0,35.0,325.0,12.0,,1,1,0,100.0,25.0,20.0,17.5,162.5,6.0,0,1,,2,P,,,,,,,,,,,4,2,638,{id},{owning_org_id},DLUHC,1234,{managing_org_id},DLUHC,1234,2022-02-08 16:52:15 UTC,2022-02-08 16:52:15 UTC diff --git a/spec/fixtures/exports/general_needs_log.xml b/spec/fixtures/exports/general_needs_log.xml index b7d969c41..642b6ac6a 100644 --- a/spec/fixtures/exports/general_needs_log.xml +++ b/spec/fixtures/exports/general_needs_log.xml @@ -40,7 +40,7 @@ 1 5 1 - SE26RT + SE2 6RT 6 7 3 @@ -52,7 +52,7 @@ 2 2 1 - NW15TY + NW1 5TY 1 1 1 diff --git a/spec/fixtures/exports/supported_housing_logs.xml b/spec/fixtures/exports/supported_housing_logs.xml index 849216392..b04a86b0c 100644 --- a/spec/fixtures/exports/supported_housing_logs.xml +++ b/spec/fixtures/exports/supported_housing_logs.xml @@ -40,7 +40,7 @@ 1 1 - LE51QP + LE5 1QP 6 2 @@ -51,7 +51,7 @@ 2 2 1 - SW1A2AA + SW1A 2AA 1 1 1 diff --git a/spec/fixtures/files/case_logs_download.csv b/spec/fixtures/files/case_logs_download.csv index e55978624..9af96e3df 100644 --- a/spec/fixtures/files/case_logs_download.csv +++ b/spec/fixtures/files/case_logs_download.csv @@ -1,2 +1,2 @@ id,status,created_at,updated_at,tenancycode,age1,sex1,ethnic,national,prevten,ecstat1,hhmemb,age2,sex2,ecstat2,age3,sex3,ecstat3,age4,sex4,ecstat4,age5,sex5,ecstat5,age6,sex6,ecstat6,age7,sex7,ecstat7,age8,sex8,ecstat8,homeless,underoccupation_benefitcap,leftreg,reservist,illness,preg_occ,startertenancy,tenancylength,tenancy,ppostcode_full,rsnvac,unittype_gn,beds,offered,wchair,earnings,incfreq,benefits,period,layear,waityear,postcode_full,reasonpref,cbl,chr,cap,reasonother,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,illness_type_1,illness_type_2,illness_type_3,illness_type_4,illness_type_8,illness_type_5,illness_type_6,illness_type_7,illness_type_9,illness_type_10,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,tenancyother,net_income_value_check,property_owner_organisation,property_manager_organisation,sale_or_letting,irproduct_other,purchaser_code,reason,propcode,majorrepairs,la,prevloc,hb,hbrentshortfall,property_relet,mrcdate,incref,sale_completion_date,startdate,armedforces,first_time_property_let_as_social_housing,unitletas,builtype,voiddate,owning_organisation_id,managing_organisation_id,renttype,needstype,lettype,postcode_known,is_la_inferred,totchild,totelder,totadult,net_income_known,nocharge,is_carehome,household_charge,referral,brent,scharge,pscharge,supcharg,tcharge,tshortfall,chcharge,declaration,ppcodenk,previous_la_known,is_previous_la_inferred,age1_known,age2_known,age3_known,age4_known,age5_known,age6_known,age7_known,age8_known,ethnic_group,ethnic_other,letting_allocation_unknown,details_known_2,details_known_3,details_known_4,details_known_5,details_known_6,details_known_7,details_known_8,rent_type,has_benefits,renewal,wrent,wscharge,wpschrge,wsupchrg,wtcharge,wtshortfall,refused,housingneeds,wchchrg,newprop,relat2,relat3,relat4,relat5,relat6,relat7,relat8,rent_value_check,old_form_id,lar,irproduct,old_id,joint,created_by_id,illness_type_0,retirement_value_check,tshortfall_known,sheltered,pregnancy_value_check,hhtype,new_old,vacdays,scheme_id,location_id,unittype_sh -{id},in_progress,2022-02-08 16:52:15 +0000,2022-02-08 16:52:15 +0000,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Westminster,,,,,,,,,,,,,,DLUHC,{owning_org_id},,Supported housing,,,false,0,0,0,,0,,,,,,,,,,,,,,false,,,,,,,,,,,,,,,,,,,,0,,,,,,,,0,,,,,,,,,,,,,,,,,Danny Rojas,,,,,,9,,,{scheme_id},SE11TE,6 +{id},in_progress,2022-02-08 16:52:15 +0000,2022-02-08 16:52:15 +0000,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Westminster,,,,,,,,,,,,,,DLUHC,{owning_org_id},,Supported housing,,,false,0,0,0,,0,,,,,,,,,,,,,,false,,,,,,,,,,,,,,,,,,,,0,,,,,,,,0,,,,,,,,,,,,,,,,,Danny Rojas,,,,,,9,,,{scheme_id},SE1 1TE,6 diff --git a/spec/helpers/tab_nav_helper_spec.rb b/spec/helpers/tab_nav_helper_spec.rb index bc82629a9..aa93b839d 100644 --- a/spec/helpers/tab_nav_helper_spec.rb +++ b/spec/helpers/tab_nav_helper_spec.rb @@ -1,7 +1,5 @@ require "rails_helper" -using RefinementTest - RSpec.describe TabNavHelper do let(:organisation) { FactoryBot.create(:organisation) } let(:user) { FactoryBot.build(:user, organisation:) } @@ -25,7 +23,7 @@ RSpec.describe TabNavHelper do describe "#location_cell" do it "returns the location link to the postcode with optional name" do link = "/schemes/#{location.scheme.id}/locations/#{location.id}/edit" - expected_html = "#{location.postcode.formatted_postcode}\nLocation #{location.name}" + expected_html = "#{location.postcode}\nLocation #{location.name}" expect(location_cell(location, link)).to match(expected_html) end end diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 9ffb03eae..3d7fc30ca 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -1113,14 +1113,14 @@ RSpec.describe CaseLog do def check_postcode_fields(postcode_field) record_from_db = ActiveRecord::Base.connection.execute("select #{postcode_field} from case_logs where id=#{address_case_log.id}").to_a[0] - expect(address_case_log[postcode_field]).to eq("M11AE") - expect(record_from_db[postcode_field]).to eq("M11AE") + expect(address_case_log[postcode_field]).to eq("M1 1AE") + expect(record_from_db[postcode_field]).to eq("M1 1AE") end def check_previous_postcode_fields(postcode_field) record_from_db = ActiveRecord::Base.connection.execute("select #{postcode_field} from case_logs where id=#{address_case_log.id}").to_a[0] - expect(address_case_log[postcode_field]).to eq("M11AE") - expect(record_from_db[postcode_field]).to eq("M11AE") + expect(address_case_log[postcode_field]).to eq("M1 1AE") + expect(record_from_db[postcode_field]).to eq("M1 1AE") end context "when saving addresses" do @@ -1205,7 +1205,7 @@ RSpec.describe CaseLog do address_case_log.update!({ postcode_known: 1, postcode_full: "M1 1AD" }) record_from_db = ActiveRecord::Base.connection.execute("select la, postcode_full from case_logs where id=#{address_case_log.id}").to_a[0] - expect(record_from_db["postcode_full"]).to eq("M11AD") + expect(record_from_db["postcode_full"]).to eq("M1 1AD") expect(address_case_log.la).to eq("E08000003") expect(record_from_db["la"]).to eq("E08000003") end @@ -1295,7 +1295,7 @@ RSpec.describe CaseLog do address_case_log.update!({ ppcodenk: 0, ppostcode_full: "M1 1AD" }) record_from_db = ActiveRecord::Base.connection.execute("select prevloc, ppostcode_full from case_logs where id=#{address_case_log.id}").to_a[0] - expect(record_from_db["ppostcode_full"]).to eq("M11AD") + expect(record_from_db["ppostcode_full"]).to eq("M1 1AD") expect(address_case_log.prevloc).to eq("E08000003") expect(record_from_db["prevloc"]).to eq("E08000003") end @@ -1717,7 +1717,7 @@ RSpec.describe CaseLog do it "correctly infers and saves postcode" do record_from_db = ActiveRecord::Base.connection.execute("SELECT postcode_full from case_logs WHERE id=#{supported_housing_case_log.id}").to_a[0] expect(record_from_db["postcode_full"]).to be_nil - expect(supported_housing_case_log.postcode_full).to eq("M11AE") + expect(supported_housing_case_log.postcode_full).to eq("M1 1AE") end it "unittype_sh method returns the type_of_unit of the location" do diff --git a/spec/models/location_spec.rb b/spec/models/location_spec.rb index 9cebd09ef..8ffa37ab6 100644 --- a/spec/models/location_spec.rb +++ b/spec/models/location_spec.rb @@ -58,8 +58,8 @@ RSpec.describe Location, type: :model do describe "scopes" do before do - FactoryBot.create(:location, name: "ABC", postcode: "NW18RR") - FactoryBot.create(:location, name: "XYZ", postcode: "SE16HJ") + FactoryBot.create(:location, name: "ABC", postcode: "NW1 8RR") + FactoryBot.create(:location, name: "XYZ", postcode: "SE1 6HJ") end context "when searching by name" do diff --git a/spec/requests/case_logs_controller_spec.rb b/spec/requests/case_logs_controller_spec.rb index eef4744d4..b509e723f 100644 --- a/spec/requests/case_logs_controller_spec.rb +++ b/spec/requests/case_logs_controller_spec.rb @@ -30,7 +30,7 @@ RSpec.describe CaseLogsController, type: :request do let(:age1) { 35 } let(:offered) { 12 } let(:period) { 2 } - let(:postcode_full) { "SE116TY" } + let(:postcode_full) { "SE11 6TY" } let(:in_progress) { "in_progress" } let(:completed) { "completed" } @@ -792,7 +792,7 @@ RSpec.describe CaseLogsController, type: :request do it "downloads logs matching both csv and filter logs" do get "/logs?status[]=completed&search=#{postcode}", headers:, params: {} csv = CSV.parse(response.body) - expect(csv.count).to eq(2) + expect(csv.count).to eq(1) end end end @@ -831,7 +831,7 @@ RSpec.describe CaseLogsController, type: :request do it "updates the case log with the given fields and keeps original values where none are passed" do case_log.reload expect(case_log.tenancycode).to eq("New Value") - expect(case_log.postcode_full).to eq("M11AE") + expect(case_log.postcode_full).to eq("M1 1AE") end context "with an invalid case log id" do @@ -889,7 +889,7 @@ RSpec.describe CaseLogsController, type: :request do it "updates the case log with the given fields and keeps original values where none are passed" do case_log.reload expect(case_log.tenancycode).to eq("New Value") - expect(case_log.postcode_full).to eq("SW1A2AA") + expect(case_log.postcode_full).to eq("SW1A 2AA") end context "with an invalid case log id" do diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index a989f4a5b..e4b1f88f0 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -1,7 +1,5 @@ require "rails_helper" -using RefinementTest - RSpec.describe LocationsController, type: :request do let(:page) { Capybara::Node::Simple.new(response.body) } let(:user) { FactoryBot.create(:user, :support) } @@ -110,7 +108,7 @@ RSpec.describe LocationsController, type: :request do it "creates a new location for scheme with valid params" do expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id) expect(Location.last.name).to eq("Test") - expect(Location.last.postcode).to eq("ZZ11ZZ") + expect(Location.last.postcode).to eq("ZZ1 1ZZ") expect(Location.last.units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.startdate).to eq(startdate) @@ -121,7 +119,7 @@ RSpec.describe LocationsController, type: :request do let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "zz1 1zz", mobility_type: "N" } } } it "creates a new location for scheme with postcode " do - expect(Location.last.postcode).to eq("ZZ11ZZ") + expect(Location.last.postcode).to eq("ZZ1 1ZZ") end end @@ -288,7 +286,7 @@ RSpec.describe LocationsController, type: :request do it "creates a new location for scheme with valid params" do expect(Location.last.name).to eq("Test") - expect(Location.last.postcode).to eq("ZZ11ZZ") + expect(Location.last.postcode).to eq("ZZ1 1ZZ") expect(Location.last.units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") end @@ -297,7 +295,7 @@ RSpec.describe LocationsController, type: :request do let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "zz1 1zz", mobility_type: "N" } } } it "creates a new location for scheme with postcode " do - expect(Location.last.postcode).to eq("ZZ11ZZ") + expect(Location.last.postcode).to eq("ZZ1 1ZZ") end end @@ -528,7 +526,7 @@ RSpec.describe LocationsController, type: :request do it "updates existing location for scheme with valid params" do expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id) expect(Location.last.name).to eq("Test") - expect(Location.last.postcode).to eq("ZZ11ZZ") + expect(Location.last.postcode).to eq("ZZ1 1ZZ") expect(Location.last.units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.startdate).to eq(startdate) @@ -552,7 +550,7 @@ RSpec.describe LocationsController, type: :request do let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "zz1 1zz", page: "edit" } } } it "updates existing location for scheme with postcode " do - expect(Location.last.postcode).to eq("ZZ11ZZ") + expect(Location.last.postcode).to eq("ZZ1 1ZZ") end end @@ -659,7 +657,7 @@ RSpec.describe LocationsController, type: :request do it "updates existing location for scheme with valid params" do expect(Location.last.name).to eq("Test") - expect(Location.last.postcode).to eq("ZZ11ZZ") + expect(Location.last.postcode).to eq("ZZ1 1ZZ") expect(Location.last.units).to eq(5) expect(Location.last.type_of_unit).to eq("Bungalow") end @@ -682,7 +680,7 @@ RSpec.describe LocationsController, type: :request do let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", add_another_location: "No", postcode: "zz1 1zz", page: "edit" } } } it "updates a location for scheme with postcode " do - expect(Location.last.postcode).to eq("ZZ11ZZ") + expect(Location.last.postcode).to eq("ZZ1 1ZZ") end end @@ -804,7 +802,7 @@ RSpec.describe LocationsController, type: :request do it "shows scheme" do locations.each do |location| expect(page).to have_content(location.id) - expect(page).to have_content(location.postcode.formatted_postcode) + expect(page).to have_content(location.postcode) expect(page).to have_content(location.type_of_unit) expect(page).to have_content(location.startdate&.to_formatted_s(:govuk_date)) end @@ -906,7 +904,7 @@ RSpec.describe LocationsController, type: :request do it "shows scheme" do locations.each do |location| expect(page).to have_content(location.id) - expect(page).to have_content(location.postcode.formatted_postcode) + expect(page).to have_content(location.postcode) expect(page).to have_content(location.type_of_unit) expect(page).to have_content(location.startdate&.to_formatted_s(:govuk_date)) end