Browse Source

Remove London validations (after main merge)

pull/486/head
Stéphane Meny 3 years ago
parent
commit
5783699032
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 41
      app/models/validations/local_authority_validations.rb
  2. 2
      config/locales/en.yml
  3. 23
      spec/models/validations/local_authority_validations_spec.rb
  4. 7
      spec/services/imports/organisation_la_import_service_spec.rb

41
app/models/validations/local_authority_validations.rb

@ -10,13 +10,6 @@ module Validations::LocalAuthorityValidations
end end
def validate_la(record) 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? if record.la_known? && record.la.blank?
record.errors.add :la, I18n.t("validations.property.la.la_known") record.errors.add :la, I18n.t("validations.property.la.la_known")
end end
@ -28,38 +21,4 @@ module Validations::LocalAuthorityValidations
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:)
end end
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
end end

2
config/locales/en.yml

@ -67,8 +67,6 @@ en:
offered: offered:
relet_number: "Number of times the property has been re-let must be between 0 and 20" relet_number: "Number of times the property has been re-let must be between 0 and 20"
la: la:
london_rent: "Local authority must be in London"
london_rent_postcode: "The postcode must be a London postcode because you told us the rent type is London Affordable Rent or London Living Rent"
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}"
rsnvac: rsnvac:

23
spec/models/validations/local_authority_validations_spec.rb

@ -38,35 +38,12 @@ RSpec.describe Validations::LocalAuthorityValidations do
describe "#validate_la" do describe "#validate_la" do
context "when the rent type is London affordable" 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 it "expects that the local authority is in London" do
record.la = "E09000033" record.la = "E09000033"
record.rent_type = 2 record.rent_type = 2
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 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 end
context "when previous la is known" do context "when previous la is known" do

7
spec/services/imports/organisation_la_import_service_spec.rb

@ -6,9 +6,10 @@ RSpec.describe Imports::OrganisationLaImportService do
let(:old_id) { "00013f30e159d7f72a3abe9ea93fb5b685d311e4" } let(:old_id) { "00013f30e159d7f72a3abe9ea93fb5b685d311e4" }
let(:import_file) { File.open("#{fixture_directory}/#{old_id}.xml") } let(:import_file) { File.open("#{fixture_directory}/#{old_id}.xml") }
let(:storage_service) { instance_double(StorageService) } let(:storage_service) { instance_double(StorageService) }
let(:logger) { instance_double(ActiveSupport::Logger) }
context "when importing data protection confirmations" do context "when importing data protection confirmations" do
subject(:import_service) { described_class.new(storage_service) } subject(:import_service) { described_class.new(storage_service, logger) }
before do before do
allow(storage_service) allow(storage_service)
@ -22,8 +23,8 @@ RSpec.describe Imports::OrganisationLaImportService do
context "when the organisation in the import file doesn't exist in the system" do context "when the organisation in the import file doesn't exist in the system" do
it "does not create an organisation la record" do it "does not create an organisation la record" do
expect { import_service.create_organisation_las("organisation_la_directory") } expect(logger).to receive(:error).with(/Organisation must exist/)
.to raise_error(ActiveRecord::RecordInvalid, /Organisation must exist/) import_service.create_organisation_las("organisation_la_directory")
end end
end end

Loading…
Cancel
Save