Browse Source

Add la validation if rent type is lar or london living rent (#148)

pull/149/head^2
kosiakkatrina 3 years ago committed by GitHub
parent
commit
ababf75103
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 34
      app/models/constants/case_log.rb
  2. 7
      app/models/validations/property_validations.rb
  3. 18
      spec/models/case_log_spec.rb

34
app/models/constants/case_log.rb

@ -699,4 +699,38 @@ module Constants::CaseLog
"London living rent" => "Intermediate Rent",
"Other intermediate rent product" => "Intermediate Rent",
}.freeze
LONDON_BOROUGHS = ["City of London",
"Barking & Dagenham",
"Barnet",
"Bexley",
"Brent",
"Bromley",
"Camden",
"Croydon",
"Ealing",
"Enfield",
"Greenwich",
"Hackney",
"Hammersmith & Fulham",
"Haringey",
"Harrow",
"Havering",
"Hillingdon",
"Hounslow",
"Islington",
"Kensington & Chelsea",
"Kingston-upon-Thames",
"Lambeth",
"Lewisham",
"Merton",
"Newham",
"Redbridge",
"Richmond-upon-Thames",
"Southwark",
"Sutton",
"Tower Hamlets",
"Waltham Forest",
"Wandsworth",
"Westminster"].freeze
end

7
app/models/validations/property_validations.rb

@ -1,9 +1,16 @@
module Validations::PropertyValidations
# Validations methods need to be called 'validate_<page_name>' to run on model save
# or 'validate_' to run on submit as well
include Constants::CaseLog
def validate_property_number_of_times_relet(record)
if record.offered && !/^[1-9]$|^0[1-9]$|^1[0-9]$|^20$/.match?(record.offered.to_s)
record.errors.add :offered, "Property number of times relet must be between 0 and 20"
end
end
def validate_la(record)
if record.la.present? && !LONDON_BOROUGHS.include?(record.la) && (record.rent_type == "London Affordable rent" || record.rent_type == "London living rent")
record.errors.add :la, "Local authority has to be in London"
end
end
end

18
spec/models/case_log_spec.rb

@ -808,6 +808,24 @@ RSpec.describe Form, type: :model do
}.not_to raise_error
end
end
context "Validate local authority" do
it "Has to be london if rent type london affordable rent" do
expect {
CaseLog.create!(la: "Ashford",
rent_type: "London Affordable rent",
owning_organisation: owning_organisation,
managing_organisation: managing_organisation)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
CaseLog.create!(la: "Westminster",
rent_type: "London Affordable rent",
owning_organisation: owning_organisation,
managing_organisation: managing_organisation)
}.not_to raise_error
end
end
end
describe "status" do

Loading…
Cancel
Save