Browse Source

Move LA validation to LA validation file

pull/484/head
baarkerlounger 3 years ago
parent
commit
829e199478
  1. 46
      app/models/validations/local_authority_validations.rb
  2. 46
      app/models/validations/property_validations.rb
  3. 2
      spec/helpers/details_table_helper_spec.rb
  4. 43
      spec/models/validations/local_authority_validations_spec.rb
  5. 43
      spec/models/validations/property_validations_spec.rb

46
app/models/validations/local_authority_validations.rb

@ -8,4 +8,50 @@ module Validations::LocalAuthorityValidations
record.errors.add :ppostcode_full, error_message
end
end
LONDON_BOROUGHS = %w[E09000001
E09000002
E09000003
E09000004
E09000005
E09000006
E09000007
E09000008
E09000009
E09000010
E09000011
E09000012
E09000013
E09000014
E09000015
E09000016
E09000017
E09000018
E09000019
E09000020
E09000021
E09000022
E09000023
E09000024
E09000025
E09000026
E09000027
E09000028
E09000029
E09000030
E09000031
E09000032
E09000033].freeze
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.postcode_full.present?
record.errors.add :postcode_full, I18n.t("validations.property.la.london_rent_postcode")
end
end
if record.la_known? && record.la.blank?
record.errors.add :la, I18n.t("validations.property.la.la_known")
end
end
end

46
app/models/validations/property_validations.rb

@ -21,52 +21,6 @@ module Validations::PropertyValidations
end
end
LONDON_BOROUGHS = %w[E09000001
E09000002
E09000003
E09000004
E09000005
E09000006
E09000007
E09000008
E09000009
E09000010
E09000011
E09000012
E09000013
E09000014
E09000015
E09000016
E09000017
E09000018
E09000019
E09000020
E09000021
E09000022
E09000023
E09000024
E09000025
E09000026
E09000027
E09000028
E09000029
E09000030
E09000031
E09000032
E09000033].freeze
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.postcode_full.present?
record.errors.add :postcode_full, I18n.t("validations.property.la.london_rent_postcode")
end
end
if record.la_known? && record.la.blank?
record.errors.add :la, I18n.t("validations.property.la.la_known")
end
end
REFERRAL_INVALID_TMP = [8, 10, 12, 13, 14, 15].freeze
def validate_rsnvac(record)
if !record.first_time_property_let_as_social_housing? && record.has_first_let_vacancy_reason?

2
spec/helpers/details_table_helper_spec.rb

@ -24,7 +24,7 @@ RSpec.describe DetailsTableHelper do
end
it "displays the string wrapped in an unordered list with the correct classes" do
expect(details).to eq("<ul class=\"govuk-list govuk-list--bullet\"><li>Camden</li>\n<br /><li>Westminster</li>\n<br /><li>Bristol</li></ul>")
expect(details).to eq("<ul class=\"govuk-list govuk-list--bullet\"><li>Camden</li><li>Westminster</li><li>Bristol</li></ul>")
end
end
end

43
spec/models/validations/local_authority_validations_spec.rb

@ -35,4 +35,47 @@ RSpec.describe Validations::LocalAuthorityValidations do
expect(record.errors["ppostcode_full"]).to include(match I18n.t("validations.postcode"))
end
end
describe "#validate_la" do
context "when the rent type is London affordable" do
let(:expected_error) { I18n.t("validations.property.la.london_rent") }
it "validates that the local authority is in London" do
record.la = "E07000105"
record.rent_type = 2
local_auth_validator.validate_la(record)
expect(record.errors["la"]).to include(match(expected_error))
expect(record.errors["postcode_full"]).to be_empty
end
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
context "when the la has been derived from a known postcode" do
let(:expected_error) { I18n.t("validations.property.la.london_rent_postcode") }
it "also adds an error to the postcode field" do
record.la = "E07000105"
record.rent_type = 2
record.postcode_known = 1
record.postcode_full = "BN18 7TR"
local_auth_validator.validate_la(record)
expect(record.errors["postcode_full"]).to include(match(expected_error))
end
end
end
context "when previous la is known" do
it "la has to be provided" do
record.la_known = 1
local_auth_validator.validate_la(record)
expect(record.errors["la"])
.to include(match I18n.t("validations.property.la.la_known"))
end
end
end
end

43
spec/models/validations/property_validations_spec.rb

@ -147,49 +147,6 @@ RSpec.describe Validations::PropertyValidations do
end
end
describe "#validate_la" do
context "when the rent type is London affordable" do
let(:expected_error) { I18n.t("validations.property.la.london_rent") }
it "validates that the local authority is in London" do
record.la = "E07000105"
record.rent_type = 2
property_validator.validate_la(record)
expect(record.errors["la"]).to include(match(expected_error))
expect(record.errors["postcode_full"]).to be_empty
end
it "expects that the local authority is in London" do
record.la = "E09000033"
record.rent_type = 2
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
let(:expected_error) { I18n.t("validations.property.la.london_rent_postcode") }
it "also adds an error to the postcode field" do
record.la = "E07000105"
record.rent_type = 2
record.postcode_known = 1
record.postcode_full = "BN18 7TR"
property_validator.validate_la(record)
expect(record.errors["postcode_full"]).to include(match(expected_error))
end
end
end
context "when previous la is known" do
it "la has to be provided" do
record.la_known = 1
property_validator.validate_la(record)
expect(record.errors["la"])
.to include(match I18n.t("validations.property.la.la_known"))
end
end
end
describe "#validate_unitletas" do
context "when the property has not been let before" do
it "validates that no previous let type is provided" do

Loading…
Cancel
Save