Browse Source

Merge pull request #489 from communitiesuk/fix_la_validation_for_postcode

Add error to postcode for LA validation
pull/494/head
baarkerlounger 3 years ago committed by GitHub
parent
commit
7c71f99246
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/models/validations/local_authority_validations.rb
  2. 1
      config/locales/en.yml
  3. 23
      spec/models/validations/local_authority_validations_spec.rb

2
app/models/validations/local_authority_validations.rb

@ -18,7 +18,9 @@ module Validations::LocalAuthorityValidations
record.la && !record.owning_organisation.local_authorities.include?(record.la) record.la && !record.owning_organisation.local_authorities.include?(record.la)
la_name = record.form.get_question("la", record).label_from_value(record.la) la_name = record.form.get_question("la", record).label_from_value(record.la)
org_name = record.owning_organisation.name org_name = record.owning_organisation.name
postcode = UKPostcode.parse(record.postcode_full) if record.postcode_full
record.errors.add :la, I18n.t("validations.property.la.la_invalid_for_org", org_name:, la_name:) record.errors.add :la, I18n.t("validations.property.la.la_invalid_for_org", org_name:, la_name:)
record.errors.add :postcode_known, I18n.t("validations.property.la.postcode_invalid_for_org", org_name:, postcode:)
end end
end end
end end

1
config/locales/en.yml

@ -69,6 +69,7 @@ en:
la: la:
la_known: "Enter name of local authority" la_known: "Enter name of local authority"
la_invalid_for_org: "%{org_name} does not operate in %{la_name}" la_invalid_for_org: "%{org_name} does not operate in %{la_name}"
postcode_invalid_for_org: "Postcode must be in an area covered by %{org_name}"
rsnvac: rsnvac:
first_let_not_social: "Reason for vacancy cannot be first let if unit has been previously let as social housing" first_let_not_social: "Reason for vacancy cannot be first let if unit has been previously let as social housing"
first_let_social: "Reason for vacancy must be first let if unit has been previously let as social housing" first_let_social: "Reason for vacancy must be first let if unit has been previously let as social housing"

23
spec/models/validations/local_authority_validations_spec.rb

@ -37,15 +37,6 @@ RSpec.describe Validations::LocalAuthorityValidations do
end end
describe "#validate_la" do describe "#validate_la" do
context "when the rent type is London affordable" do
it "expects that the local authority is in London" do
record.la = "E09000033"
record.rent_type = 2
local_auth_validator.validate_la(record)
expect(record.errors["la"]).to be_empty
end
end
context "when previous la is known" do context "when previous la is known" do
it "la has to be provided" do it "la has to be provided" do
record.la_known = 1 record.la_known = 1
@ -80,6 +71,20 @@ RSpec.describe Validations::LocalAuthorityValidations do
local_auth_validator.validate_la(record) local_auth_validator.validate_la(record)
expect(record.errors["la"]).to be_empty expect(record.errors["la"]).to be_empty
end end
context "when a postcode is given" do
it "validates that it matches a local authority the organisation operates in" do
record.postcode_full = "YO10 3RR"
record.la = "E06000014"
local_auth_validator.validate_la(record)
expect(record.errors["postcode_known"])
.to include(match I18n.t(
"validations.property.la.postcode_invalid_for_org",
org_name: organisation.name,
postcode: "YO10 3RR",
))
end
end
end end
context "when the organisation has not listed specific local authorities it operates in" do context "when the organisation has not listed specific local authorities it operates in" do

Loading…
Cancel
Save