diff --git a/app/admin/case_logs.rb b/app/admin/case_logs.rb index f958ba670..389830a16 100644 --- a/app/admin/case_logs.rb +++ b/app/admin/case_logs.rb @@ -12,7 +12,7 @@ ActiveAdmin.register CaseLog do column :updated_at column :status column :tenant_code - column :property_postcode + column :postcode_full column :owning_organisation column :managing_organisation actions diff --git a/app/admin/dashboard.rb b/app/admin/dashboard.rb index 9db09a42e..579f6f487 100644 --- a/app/admin/dashboard.rb +++ b/app/admin/dashboard.rb @@ -11,7 +11,7 @@ ActiveAdmin.register_page "Dashboard" do column :updated_at column :status column :tenant_code - column :property_postcode + column :postcode_full end end end diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 2bc3335d2..6e542799b 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -22,8 +22,8 @@ class CaseLog < ApplicationRecord has_paper_trail validates_with CaseLogValidator - before_validation :process_postcode_changes!, if: :property_postcode_changed? - before_validation :process_previous_postcode_changes!, if: :previous_postcode_changed? + before_validation :process_postcode_changes!, if: :postcode_full_changed? + before_validation :process_previous_postcode_changes!, if: :ppostcode_full_changed? before_validation :reset_invalidated_dependent_fields! before_validation :reset_location_fields!, unless: :postcode_known? before_validation :reset_previous_location_fields!, unless: :previous_postcode_known? @@ -332,9 +332,9 @@ private end def set_derived_fields! - if previous_postcode.present? - self.ppostc1 = UKPostcode.parse(previous_postcode).outcode - self.ppostc2 = UKPostcode.parse(previous_postcode).incode + if ppostcode_full.present? + self.ppostc1 = UKPostcode.parse(ppostcode_full).outcode + self.ppostc2 = UKPostcode.parse(ppostcode_full).incode end if mrcdate.present? self.mrcday = mrcdate.day @@ -400,11 +400,13 @@ private end def process_postcode_changes! - process_postcode(property_postcode, "postcode_known", "is_la_inferred", "la", "postcode", "postcod2") + self.postcode_full = postcode_full.present? ? postcode_full.upcase.gsub(/\s+/, "") : postcode_full + process_postcode(postcode_full, "postcode_known", "is_la_inferred", "la", "postcode", "postcod2") end def process_previous_postcode_changes! - process_postcode(previous_postcode, "previous_postcode_known", "is_previous_la_inferred", "prevloc", "ppostc1", "ppostc2") + self.ppostcode_full = ppostcode_full.present? ? ppostcode_full.upcase.gsub(/\s+/, "") : ppostcode_full + process_postcode(ppostcode_full, "previous_postcode_known", "is_previous_la_inferred", "prevloc", "ppostc1", "ppostc2") end def process_postcode(postcode, postcode_known_key, la_inferred_key, la_key, outcode_key, incode_key) @@ -419,11 +421,11 @@ private end def reset_location_fields! - reset_location(is_la_inferred, "la", "is_la_inferred", "property_postcode", "postcode", "postcod2", la_known) + reset_location(is_la_inferred, "la", "is_la_inferred", "postcode_full", "postcode", "postcod2", la_known) end def reset_previous_location_fields! - reset_location(is_previous_la_inferred, "prevloc", "is_previous_la_inferred", "previous_postcode", "ppostc1", "ppostc2", previous_la_known) + reset_location(is_previous_la_inferred, "prevloc", "is_previous_la_inferred", "ppostcode_full", "ppostc1", "ppostc2", previous_la_known) end def reset_location(is_inferred, la_key, is_inferred_key, postcode_key, incode_key, outcode_key, is_la_known) diff --git a/app/models/form.rb b/app/models/form.rb index e8e553fac..b68eef18c 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -117,7 +117,7 @@ class Form def invalidated_page_questions(case_log) # we're already treating address fields as a special case and reset their values upon saving a case_log - address_questions = %w[postcode_known la previous_postcode_known prevloc property_postcode previous_postcode] + address_questions = %w[postcode_known la previous_postcode_known prevloc postcode_full ppostcode_full] invalidated_pages(case_log).flat_map(&:questions).reject { |q| address_questions.include?(q.id) } || [] end diff --git a/app/models/validations/local_authority_validations.rb b/app/models/validations/local_authority_validations.rb index 2264145ce..a7b3ed30d 100644 --- a/app/models/validations/local_authority_validations.rb +++ b/app/models/validations/local_authority_validations.rb @@ -2,10 +2,10 @@ module Validations::LocalAuthorityValidations POSTCODE_REGEXP = Validations::PropertyValidations::POSTCODE_REGEXP def validate_previous_accommodation_postcode(record) - postcode = record.previous_postcode + postcode = record.ppostcode_full if record.previous_postcode_known? && (postcode.blank? || !postcode.match(POSTCODE_REGEXP)) error_message = I18n.t("validations.postcode") - record.errors.add :previous_postcode, error_message + record.errors.add :ppostcode_full, error_message end end end diff --git a/app/models/validations/property_validations.rb b/app/models/validations/property_validations.rb index 8a72bdabb..ab97a20d4 100644 --- a/app/models/validations/property_validations.rb +++ b/app/models/validations/property_validations.rb @@ -57,8 +57,8 @@ module Validations::PropertyValidations def validate_la(record) if record.la.present? && !LONDON_BOROUGHS.include?(record.la) && record.is_london_rent? record.errors.add :la, I18n.t("validations.property.la.london_rent") - if record.postcode_known? && record.property_postcode.present? - record.errors.add :property_postcode, I18n.t("validations.property.la.london_rent_postcode") + if record.postcode_known? && record.postcode_full.present? + record.errors.add :postcode_full, I18n.t("validations.property.la.london_rent_postcode") end end @@ -94,10 +94,10 @@ module Validations::PropertyValidations end def validate_property_postcode(record) - postcode = record.property_postcode + postcode = record.postcode_full if record.postcode_known? && (postcode.blank? || !postcode.match(POSTCODE_REGEXP)) error_message = I18n.t("validations.postcode") - record.errors.add :property_postcode, error_message + record.errors.add :postcode_full, error_message end end diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 3f3fdf31f..2903be295 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -196,13 +196,13 @@ } }, "conditional_for": { - "property_postcode": [ + "postcode_full": [ 1 ] }, "hidden_in_check_answers": true }, - "property_postcode": { + "postcode_full": { "check_answer_label": "Postcode", "header": "What is the property’s postcode?", "hint_text": "", @@ -3697,13 +3697,13 @@ } }, "conditional_for": { - "previous_postcode": [ + "ppostcode_full": [ 1 ] }, "hidden_in_check_answers": true }, - "previous_postcode": { + "ppostcode_full": { "check_answer_label": "Postcode of household’s last settled accommodation", "header": "Postcode for the previous accommodation", "hint_text": "", diff --git a/db/migrate/20220324152359_rename_postcode_columns.rb b/db/migrate/20220324152359_rename_postcode_columns.rb new file mode 100644 index 000000000..e984daf37 --- /dev/null +++ b/db/migrate/20220324152359_rename_postcode_columns.rb @@ -0,0 +1,6 @@ +class RenamePostcodeColumns < ActiveRecord::Migration[7.0] + def change + rename_column :case_logs, :previous_postcode, :ppostcode_full + rename_column :case_logs, :property_postcode, :postcode_full + end +end diff --git a/db/schema.rb b/db/schema.rb index 11d585b51..1468b9dc9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -87,7 +87,7 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do t.integer "tenancylength" t.integer "tenancy" t.integer "landlord" - t.string "previous_postcode" + t.string "ppostcode_full" t.integer "rsnvac" t.integer "unittype_gn" t.integer "beds" @@ -99,7 +99,7 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do t.integer "period" t.integer "layear" t.integer "lawaitlist" - t.string "property_postcode" + t.string "postcode_full" t.integer "reasonpref" t.integer "cbl" t.integer "chr" diff --git a/docs/api/DLUHC-CORE-Data.v1.json b/docs/api/DLUHC-CORE-Data.v1.json index 6750069f6..742c2a571 100644 --- a/docs/api/DLUHC-CORE-Data.v1.json +++ b/docs/api/DLUHC-CORE-Data.v1.json @@ -324,7 +324,7 @@ "tenancy": 3, "landlord": "This landlord", "la": "Barnet", - "property_postcode": "NW1 5TY", + "postcode_full": "NW1 5TY", "property_relet": 0, "rsnvac": 0, "property_reference": "P9876", @@ -354,7 +354,7 @@ "layear": 2, "lawaitlist": 1, "prevloc": "E07000105", - "previous_postcode": "SE2 6RT", + "ppostcode_full": "SE2 6RT", "reasonpref": 1, "cbl": 1, "chr": 1, @@ -625,7 +625,7 @@ "type": "string", "minLength": 1 }, - "previous_postcode": { + "ppostcode_full": { "type": "string", "minLength": 1 }, @@ -710,7 +710,7 @@ "type": "string", "minLength": 1 }, - "property_postcode": { + "postcode_full": { "type": "string", "minLength": 1 }, @@ -866,7 +866,7 @@ "lettype", "landlord", "la", - "previous_postcode", + "ppostcode_full", "property_relet", "rsnvac", "property_reference", @@ -892,7 +892,7 @@ "layear", "lawaitlist", "prevloc", - "property_postcode", + "postcode_full", "reasonpref", "reasonable_preference_reason", "cbl", diff --git a/spec/factories/case_log.rb b/spec/factories/case_log.rb index 99a7e72fc..60cdc72bd 100644 --- a/spec/factories/case_log.rb +++ b/spec/factories/case_log.rb @@ -12,8 +12,8 @@ FactoryBot.define do trait :in_progress do status { 1 } tenant_code { "TH356" } - property_postcode { "PO5 3TE" } - previous_postcode { "SW2 6HI" } + postcode_full { "PO5 3TE" } + ppostcode_full { "SW2 6HI" } age1 { 17 } end trait :soft_validations_triggered do @@ -58,7 +58,7 @@ FactoryBot.define do tenancylength { 5 } tenancy { 3 } landlord { 1 } - previous_postcode { "SE2 6RT" } + ppostcode_full { "SE2 6RT" } rsnvac { 7 } unittype_gn { 2 } beds { 3 } @@ -79,7 +79,7 @@ FactoryBot.define do tcharge { 325 } layear { 2 } lawaitlist { 1 } - property_postcode { "NW1 5TY" } + postcode_full { "NW1 5TY" } reasonpref { 1 } cbl { 1 } chr { 1 } diff --git a/spec/features/form/check_answers_page_spec.rb b/spec/features/form/check_answers_page_spec.rb index ae093cd24..6ef6d7d3b 100644 --- a/spec/features/form/check_answers_page_spec.rb +++ b/spec/features/form/check_answers_page_spec.rb @@ -184,9 +184,9 @@ RSpec.describe "Form Check Answers Page" do age1: nil, layear: 2, lawaitlist: 1, - property_postcode: "NW1 5TY", + postcode_full: "NW1 5TY", reason: 4, - previous_postcode: "SE2 6RT", + ppostcode_full: "SE2 6RT", mrcdate: Time.zone.parse("03/11/2019"), ) end diff --git a/spec/features/form/conditional_questions_spec.rb b/spec/features/form/conditional_questions_spec.rb index 051bf5862..db558c93a 100644 --- a/spec/features/form/conditional_questions_spec.rb +++ b/spec/features/form/conditional_questions_spec.rb @@ -38,9 +38,9 @@ RSpec.describe "Form Conditional Questions" do context "when a conditional question has a saved answer", js: true do it "is displayed correctly" do - case_log.update!(postcode_known: 1, property_postcode: "NW1 6RT") + case_log.update!(postcode_known: 1, postcode_full: "NW1 6RT") visit("/logs/#{id}/property-postcode") - expect(page).to have_field("case-log-property-postcode-field", with: "NW1 6RT") + expect(page).to have_field("case-log-postcode-full-field", with: "NW16RT") end end end diff --git a/spec/features/form/page_routing_spec.rb b/spec/features/form/page_routing_spec.rb index 28358e949..d4f50f118 100644 --- a/spec/features/form/page_routing_spec.rb +++ b/spec/features/form/page_routing_spec.rb @@ -50,7 +50,7 @@ RSpec.describe "Form Page Routing" do context "when the answers are inferred", js: true do it "shows question if the answer could not be inferred" do visit("/logs/#{id}/property-postcode") - fill_in("case-log-property-postcode-field", with: "PO5 3TE") + fill_in("case-log-postcode-full-field", with: "PO5 3TE") click_button("Save and continue") expect(page).to have_current_path("/logs/#{id}/do-you-know-the-local-authority") end @@ -66,7 +66,7 @@ RSpec.describe "Form Page Routing" do .to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\", \"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {}) visit("/logs/#{id}/property-postcode") - fill_in("case-log-property-postcode-field", with: "P0 5ST") + fill_in("case-log-postcode-full-field", with: "P0 5ST") click_button("Save and continue") expect(page).to have_current_path("/logs/#{id}/property-wheelchair-accessible") end diff --git a/spec/features/form/saving_data_spec.rb b/spec/features/form/saving_data_spec.rb index 9bea5515d..d9fa2feba 100644 --- a/spec/features/form/saving_data_spec.rb +++ b/spec/features/form/saving_data_spec.rb @@ -73,7 +73,7 @@ RSpec.describe "Form Saving Data" do it "displays number answers in inputs if they are already saved" do visit("/logs/#{id}/property-postcode") - expect(page).to have_field("case-log-property-postcode-field", with: "PO5 3TE") + expect(page).to have_field("case-log-postcode-full-field", with: "PO53TE") end it "displays text answers in inputs if they are already saved" do diff --git a/spec/fixtures/complete_case_log.json b/spec/fixtures/complete_case_log.json index e2bbf0245..dcfa683d0 100644 --- a/spec/fixtures/complete_case_log.json +++ b/spec/fixtures/complete_case_log.json @@ -55,7 +55,7 @@ "tenancy": 3, "landlord": "This landlord", "la": "Barnet", - "property_postcode": "NW1 5TY", + "postcode_full": "NW1 5TY", "property_relet": 0, "rsnvac": 0, "property_reference": "P9876", @@ -88,7 +88,7 @@ "layear": 2, "lawaitlist": 1, "prevloc": "E07000105", - "previous_postcode": "SE2 6RT", + "ppostcode_full": "SE2 6RT", "reasonpref": 1, "cbl": 1, "chr": 1, diff --git a/spec/fixtures/exports/case_logs.xml b/spec/fixtures/exports/case_logs.xml index 6f2148f0b..e64b91d20 100644 --- a/spec/fixtures/exports/case_logs.xml +++ b/spec/fixtures/exports/case_logs.xml @@ -45,7 +45,7 @@ 5 3 1 - SE2 6RT + SE26RT 7 2 3 @@ -57,7 +57,7 @@ 2 2 1 - NW1 5TY + NW15TY 1 1 1 diff --git a/spec/fixtures/forms/2021_2022.json b/spec/fixtures/forms/2021_2022.json index 0eea7737a..8bd6c662e 100644 --- a/spec/fixtures/forms/2021_2022.json +++ b/spec/fixtures/forms/2021_2022.json @@ -379,13 +379,13 @@ } }, "conditional_for": { - "property_postcode": [ + "postcode_full": [ 1 ] }, "hidden_in_check_answers": true }, - "property_postcode": { + "postcode_full": { "check_answer_label": "Postcode", "header": "", "hint_text": "", @@ -888,7 +888,7 @@ "width": 5, "conditional_for": { "fake_key": "fake_condition" } }, - "previous_postcode": { + "ppostcode_full": { "check_answer_label": "Postcode of previous accommodation if the household has moved from settled accommodation", "header": "Postcode for the previous accommodation", "hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed", diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index ee8215211..0c751be4e 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -196,8 +196,8 @@ RSpec.describe CaseLog do described_class.create({ managing_organisation: organisation, owning_organisation: organisation, - property_postcode: "M1 1AE", - previous_postcode: "M2 2AE", + postcode_full: "M1 1AE", + ppostcode_full: "M2 2AE", startdate: Time.gm(2021, 10, 10), mrcdate: Time.gm(2021, 5, 4), property_void_date: Time.gm(2021, 3, 3), @@ -1134,6 +1134,15 @@ RSpec.describe CaseLog do end end + def check_postcode_fields(postcode_field, outcode_field, incode_field) + record_from_db = ActiveRecord::Base.connection.execute("select #{postcode_field}, #{outcode_field}, #{incode_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[outcode_field]).to eq("M1") + expect(record_from_db[outcode_field]).to eq("M1") + expect(address_case_log[incode_field]).to eq("1AE") + expect(record_from_db[incode_field]).to eq("1AE") + end context "when saving addresses" do before do stub_request(:get, /api.postcodes.io/) @@ -1145,10 +1154,28 @@ RSpec.describe CaseLog do managing_organisation: organisation, owning_organisation: organisation, postcode_known: 1, - property_postcode: "M1 1AE", + postcode_full: "M1 1AE", }) end + def check_property_postcode_fields + check_postcode_fields("postcode_full", "postcode", "postcod2") + end + + it "correctly formats previous postcode" do + address_case_log.update!(postcode_full: "M1 1AE") + check_property_postcode_fields + + address_case_log.update!(postcode_full: "m1 1ae") + check_property_postcode_fields + + address_case_log.update!(postcode_full: "m11Ae") + check_property_postcode_fields + + address_case_log.update!(postcode_full: "m11ae") + check_property_postcode_fields + end + it "correctly infers la" do record_from_db = ActiveRecord::Base.connection.execute("select la from case_logs where id=#{address_case_log.id}").to_a[0] expect(address_case_log.la).to eq("E08000003") @@ -1156,12 +1183,12 @@ RSpec.describe CaseLog do end it "errors if the property postcode is emptied" do - expect { address_case_log.update!({ property_postcode: "" }) } + expect { address_case_log.update!({ postcode_full: "" }) } .to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/) end it "errors if the property postcode is not valid" do - expect { address_case_log.update!({ property_postcode: "invalid_postcode" }) } + expect { address_case_log.update!({ postcode_full: "invalid_postcode" }) } .to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/) end @@ -1172,15 +1199,15 @@ RSpec.describe CaseLog do it "logs a warning" do expect(Rails.logger).to receive(:warn).with("Postcodes.io lookup timed out") - address_case_log.update!({ postcode_known: 1, property_postcode: "M1 1AD" }) + address_case_log.update!({ postcode_known: 1, postcode_full: "M1 1AD" }) end end it "correctly resets all fields if property postcode not known" do address_case_log.update!({ postcode_known: 0 }) - record_from_db = ActiveRecord::Base.connection.execute("select la, property_postcode from case_logs where id=#{address_case_log.id}").to_a[0] - expect(record_from_db["property_postcode"]).to eq(nil) + 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(nil) expect(address_case_log.la).to eq(nil) expect(record_from_db["la"]).to eq(nil) end @@ -1189,15 +1216,15 @@ RSpec.describe CaseLog do address_case_log.update!({ postcode_known: 0 }) address_case_log.update!({ la_known: 1, la: "E09000033" }) - record_from_db = ActiveRecord::Base.connection.execute("select la, property_postcode from case_logs where id=#{address_case_log.id}").to_a[0] - expect(record_from_db["property_postcode"]).to eq(nil) + 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(nil) expect(address_case_log.la).to eq("E09000033") expect(record_from_db["la"]).to eq("E09000033") - address_case_log.update!({ postcode_known: 1, property_postcode: "M1 1AD" }) + address_case_log.update!({ postcode_known: 1, postcode_full: "M1 1AD" }) - record_from_db = ActiveRecord::Base.connection.execute("select la, property_postcode from case_logs where id=#{address_case_log.id}").to_a[0] - expect(record_from_db["property_postcode"]).to eq("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(address_case_log.la).to eq("E08000003") expect(record_from_db["la"]).to eq("E08000003") end @@ -1214,10 +1241,28 @@ RSpec.describe CaseLog do managing_organisation: organisation, owning_organisation: organisation, previous_postcode_known: 1, - previous_postcode: "M1 1AE", + ppostcode_full: "M1 1AE", }) end + def check_previous_postcode_fields + check_postcode_fields("ppostcode_full", "ppostc1", "ppostc2") + end + + it "correctly formats previous postcode" do + address_case_log.update!(ppostcode_full: "M1 1AE") + check_previous_postcode_fields + + address_case_log.update!(ppostcode_full: "m1 1ae") + check_previous_postcode_fields + + address_case_log.update!(ppostcode_full: "m11Ae") + check_previous_postcode_fields + + address_case_log.update!(ppostcode_full: "m11ae") + check_previous_postcode_fields + end + it "correctly infers prevloc" do record_from_db = ActiveRecord::Base.connection.execute("select prevloc from case_logs where id=#{address_case_log.id}").to_a[0] expect(address_case_log.prevloc).to eq("E08000003") @@ -1225,20 +1270,20 @@ RSpec.describe CaseLog do end it "errors if the previous postcode is emptied" do - expect { address_case_log.update!({ previous_postcode: "" }) } + expect { address_case_log.update!({ ppostcode_full: "" }) } .to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/) end it "errors if the previous postcode is not valid" do - expect { address_case_log.update!({ previous_postcode: "invalid_postcode" }) } + expect { address_case_log.update!({ ppostcode_full: "invalid_postcode" }) } .to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/) end it "correctly resets all fields if previous postcode not known" do address_case_log.update!({ previous_postcode_known: 0 }) - record_from_db = ActiveRecord::Base.connection.execute("select prevloc, previous_postcode from case_logs where id=#{address_case_log.id}").to_a[0] - expect(record_from_db["previous_postcode"]).to eq(nil) + 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(nil) expect(address_case_log.prevloc).to eq(nil) expect(record_from_db["prevloc"]).to eq(nil) end @@ -1260,15 +1305,15 @@ RSpec.describe CaseLog do address_case_log.update!({ previous_postcode_known: 0 }) address_case_log.update!({ previous_la_known: 1, prevloc: "E09000033" }) - record_from_db = ActiveRecord::Base.connection.execute("select prevloc, previous_postcode from case_logs where id=#{address_case_log.id}").to_a[0] - expect(record_from_db["previous_postcode"]).to eq(nil) + 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(nil) expect(address_case_log.prevloc).to eq("E09000033") expect(record_from_db["prevloc"]).to eq("E09000033") - address_case_log.update!({ previous_postcode_known: 0, previous_postcode: "M1 1AD" }) + address_case_log.update!({ previous_postcode_known: 0, ppostcode_full: "M1 1AD" }) - record_from_db = ActiveRecord::Base.connection.execute("select prevloc, previous_postcode from case_logs where id=#{address_case_log.id}").to_a[0] - expect(record_from_db["previous_postcode"]).to eq("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(address_case_log.prevloc).to eq("E08000003") expect(record_from_db["prevloc"]).to eq("E08000003") end diff --git a/spec/models/form/question_spec.rb b/spec/models/form/question_spec.rb index f901398ab..c5aa26e12 100644 --- a/spec/models/form/question_spec.rb +++ b/spec/models/form/question_spec.rb @@ -211,7 +211,7 @@ RSpec.describe Form::Question, type: :model do let(:section_id) { "tenancy_and_property" } let(:subsection_id) { "property_information" } let(:page_id) { "property_postcode" } - let(:case_log) { FactoryBot.build(:case_log, :in_progress, postcode_known: 0, property_postcode: nil) } + let(:case_log) { FactoryBot.build(:case_log, :in_progress, postcode_known: 0, postcode_full: nil) } let(:question_id) { "property_postcode" } it "displays 'change' in the check answers link text" do @@ -299,7 +299,7 @@ RSpec.describe Form::Question, type: :model do let(:section_id) { "tenancy_and_property" } let(:subsection_id) { "property_information" } let(:page_id) { "property_postcode" } - let(:question_id) { "property_postcode" } + let(:question_id) { "postcode_full" } it "returns true" do case_log["postcode_known"] = 0 diff --git a/spec/models/form_spec.rb b/spec/models/form_spec.rb index fff2375aa..34c2ab929 100644 --- a/spec/models/form_spec.rb +++ b/spec/models/form_spec.rb @@ -79,9 +79,9 @@ RSpec.describe Form, type: :model do def answer_local_authority(case_log) case_log.layear = "1 year but under 2 years" case_log.lawaitlist = "Less than 1 year" - case_log.property_postcode = "NW1 5TY" + case_log.postcode_full = "NW1 5TY" case_log.reason = "Permanently decanted from another property owned by this landlord" - case_log.previous_postcode = "SE2 6RT" + case_log.ppostcode_full = "SE2 6RT" case_log.mrcdate = Time.zone.parse("03/11/2019") end diff --git a/spec/models/validations/local_authority_validations_spec.rb b/spec/models/validations/local_authority_validations_spec.rb index 65ad84fdc..6ece1932c 100644 --- a/spec/models/validations/local_authority_validations_spec.rb +++ b/spec/models/validations/local_authority_validations_spec.rb @@ -7,32 +7,32 @@ RSpec.describe Validations::LocalAuthorityValidations do let(:record) { FactoryBot.create(:case_log) } describe "#validate_previous_accommodation_postcode" do - it "does not add an error if the record previous_postcode is missing" do - record.previous_postcode = nil + it "does not add an error if the record ppostcode_full is missing" do + record.ppostcode_full = nil local_auth_validator.validate_previous_accommodation_postcode(record) expect(record.errors).to be_empty end - it "does not add an error if the record previous_postcode is valid (uppercase space)" do + it "does not add an error if the record ppostcode_full is valid (uppercase space)" do record.previous_postcode_known = 1 - record.previous_postcode = "M1 1AE" + record.ppostcode_full = "M1 1AE" local_auth_validator.validate_previous_accommodation_postcode(record) expect(record.errors).to be_empty end - it "does not add an error if the record previous_postcode is valid (lowercase no space)" do + it "does not add an error if the record ppostcode_full is valid (lowercase no space)" do record.previous_postcode_known = 1 - record.previous_postcode = "m11ae" + record.ppostcode_full = "m11ae" local_auth_validator.validate_previous_accommodation_postcode(record) expect(record.errors).to be_empty end it "does add an error when the postcode is invalid" do record.previous_postcode_known = 1 - record.previous_postcode = "invalid" + record.ppostcode_full = "invalid" local_auth_validator.validate_previous_accommodation_postcode(record) expect(record.errors).not_to be_empty - expect(record.errors["previous_postcode"]).to include(match I18n.t("validations.postcode")) + expect(record.errors["ppostcode_full"]).to include(match I18n.t("validations.postcode")) end end end diff --git a/spec/models/validations/property_validations_spec.rb b/spec/models/validations/property_validations_spec.rb index 12d7b7206..5dd339984 100644 --- a/spec/models/validations/property_validations_spec.rb +++ b/spec/models/validations/property_validations_spec.rb @@ -156,7 +156,7 @@ RSpec.describe Validations::PropertyValidations do record.rent_type = 2 property_validator.validate_la(record) expect(record.errors["la"]).to include(match(expected_error)) - expect(record.errors["property_postcode"]).to be_empty + expect(record.errors["postcode_full"]).to be_empty end it "expects that the local authority is in London" do @@ -173,9 +173,9 @@ RSpec.describe Validations::PropertyValidations do record.la = "E07000105" record.rent_type = 2 record.postcode_known = 1 - record.property_postcode = "BN18 7TR" + record.postcode_full = "BN18 7TR" property_validator.validate_la(record) - expect(record.errors["property_postcode"]).to include(match(expected_error)) + expect(record.errors["postcode_full"]).to include(match(expected_error)) end end end diff --git a/spec/requests/case_logs_controller_spec.rb b/spec/requests/case_logs_controller_spec.rb index 4a9859cfc..0c1e3524a 100644 --- a/spec/requests/case_logs_controller_spec.rb +++ b/spec/requests/case_logs_controller_spec.rb @@ -29,7 +29,7 @@ RSpec.describe CaseLogsController, type: :request do let(:age1) { 35 } let(:offered) { 12 } let(:period) { 2 } - let(:property_postcode) { "SE11 6TY" } + let(:postcode_full) { "SE116TY" } let(:in_progress) { "in_progress" } let(:completed) { "completed" } @@ -40,7 +40,7 @@ RSpec.describe CaseLogsController, type: :request do "managing_organisation_id": managing_organisation.id, "tenant_code": tenant_code, "age1": age1, - "property_postcode": property_postcode, + "postcode_full": postcode_full, "offered": offered, "period": period, } @@ -63,7 +63,7 @@ RSpec.describe CaseLogsController, type: :request do json_response = JSON.parse(response.body) expect(json_response["tenant_code"]).to eq(tenant_code) expect(json_response["age1"]).to eq(age1) - expect(json_response["property_postcode"]).to eq(property_postcode) + expect(json_response["postcode_full"]).to eq(postcode_full) end context "with invalid json parameters" do @@ -283,7 +283,7 @@ RSpec.describe CaseLogsController, type: :request do la_known: 1, is_la_inferred: true, postcode_known: 1, - property_postcode: "PO5 3TE") + postcode_full: "PO5 3TE") id = case_log.id get "/logs/#{id}/property-information/check-answers" expected_inferred_answer = "Manchester" @@ -309,7 +309,7 @@ RSpec.describe CaseLogsController, type: :request do describe "PATCH" do let(:case_log) do - FactoryBot.create(:case_log, :in_progress, tenant_code: "Old Value", property_postcode: "M1 1AE") + FactoryBot.create(:case_log, :in_progress, tenant_code: "Old Value", postcode_full: "M1 1AE") end let(:params) do { tenant_code: "New Value" } @@ -327,7 +327,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.tenant_code).to eq("New Value") - expect(case_log.property_postcode).to eq("M1 1AE") + expect(case_log.postcode_full).to eq("M11AE") end context "with an invalid case log id" do @@ -367,7 +367,7 @@ RSpec.describe CaseLogsController, type: :request do # what actually happens to an ActiveRecord object and what we're doing here, but either is allowed. describe "PUT" do let(:case_log) do - FactoryBot.create(:case_log, :in_progress, tenant_code: "Old Value", property_postcode: "SW1A 2AA") + FactoryBot.create(:case_log, :in_progress, tenant_code: "Old Value", postcode_full: "SW1A 2AA") end let(:params) do { tenant_code: "New Value" } @@ -385,7 +385,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.tenant_code).to eq("New Value") - expect(case_log.property_postcode).to eq("SW1A 2AA") + expect(case_log.postcode_full).to eq("SW1A2AA") end context "with an invalid case log id" do