Browse Source

Also add london borough error message to postcode field

pull/378/head
baarkerlounger 3 years ago
parent
commit
6de33be936
  1. 2
      app/models/case_log.rb
  2. 3
      app/models/validations/property_validations.rb
  3. 12
      spec/models/validations/property_validations_spec.rb

2
app/models/case_log.rb

@ -385,7 +385,7 @@ private
def get_inferred_la(postcode)
postcode_lookup = nil
Timeout.timeout(5) { postcode_lookup = PIO.lookup(postcode) }
Timeout.timeout(5) { postcode_lookup = PIO.lookup(postcode) } rescue Timeout::Error
if postcode_lookup && postcode_lookup.info.present?
postcode_lookup.codes["admin_district"]
end

3
app/models/validations/property_validations.rb

@ -57,6 +57,9 @@ 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")
end
end
if record.la_known? && record.la.blank?

12
spec/models/validations/property_validations_spec.rb

@ -156,6 +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
end
it "expects that the local authority is in London" do
@ -164,6 +165,17 @@ RSpec.describe Validations::PropertyValidations do
property_validator.validate_la(record)
expect(record.errors["la"]).to be_empty
end
context "when the la has been derived from a known postcode" do
it "also adds an error to the postcode field" do
record.la = "E07000105"
record.rent_type = 2
record.postcode_known = 1
record.property_postcode = "BN18 7TR"
property_validator.validate_la(record)
expect(record.errors["property_postcode"]).to include(match(expected_error))
end
end
end
context "when previous la is known" do

Loading…
Cancel
Save