Browse Source

Add incomplete location validation

pull/1867/head
Kat 3 years ago
parent
commit
748b846739
  1. 5
      app/models/validations/setup_validations.rb
  2. 2
      config/locales/en.yml
  3. 20
      spec/models/validations/setup_validations_spec.rb

5
app/models/validations/setup_validations.rb

@ -26,6 +26,11 @@ module Validations::SetupValidations
def validate_location(record) def validate_location(record)
location_during_startdate_validation(record) location_during_startdate_validation(record)
if record.location&.status == :incomplete
record.errors.add :location_id, :incomplete, message: I18n.t("validations.setup.location.incomplete")
record.errors.add :scheme_id, :incomplete, message: I18n.t("validations.setup.location.incomplete")
end
end end
def validate_scheme_has_confirmed_locations_validation(record) def validate_scheme_has_confirmed_locations_validation(record)

2
config/locales/en.yml

@ -305,6 +305,8 @@ en:
lettype: lettype:
general_needs_mismatch: Lettings type must be a general needs type because you selected general needs when uploading the file general_needs_mismatch: Lettings type must be a general needs type because you selected general needs when uploading the file
supported_housing_mismatch: Lettings type must be a supported housing type because you selected supported housing when uploading the file supported_housing_mismatch: Lettings type must be a supported housing type because you selected supported housing when uploading the file
location:
incomplete: "This location is incomplete"
property: property:
uprn: uprn:

20
spec/models/validations/setup_validations_spec.rb

@ -641,6 +641,26 @@ RSpec.describe Validations::SetupValidations do
.to include(match I18n.t("validations.setup.startdate.location.activating_soon.location_id", postcode: location.postcode, date: "15 September 2022")) .to include(match I18n.t("validations.setup.startdate.location.activating_soon.location_id", postcode: location.postcode, date: "15 September 2022"))
end end
end end
context "with an incomplete location" do
let(:scheme) { create(:scheme) }
let(:location) { create(:location, :incomplete, scheme:) }
it "produces error when location is incomplete" do
record.location = location
setup_validator.validate_location(record)
expect(record.errors["location_id"])
.to include("This location is incomplete")
end
it "produces no error when location is completes" do
location.update!(units: 1)
location.reload
record.location = location
setup_validator.validate_location(record)
expect(record.errors["location_id"]).to be_empty
end
end
end end
describe "#validate_organisation" do describe "#validate_organisation" do

Loading…
Cancel
Save