Browse Source

Run rent validations when >= 4 beds (#1465)

pull/1456/head
Jack 2 years ago committed by GitHub
parent
commit
5aba3ef9a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      app/models/validations/financial_validations.rb
  2. 8
      spec/models/validations/financial_validations_spec.rb

11
app/models/validations/financial_validations.rb

@ -188,7 +188,12 @@ private
collection_year = record.collection_start_year collection_year = record.collection_start_year
rent_range = LaRentRange.find_by(start_year: collection_year, la: record.la, beds: record.beds_for_la_rent_range, lettype: record.lettype) rent_range = LaRentRange.find_by(
start_year: collection_year,
la: record.la,
beds: record.beds_for_la_rent_range,
lettype: record.lettype,
)
if rent_range.present? && !weekly_value_in_range(record, "brent", rent_range.hard_min, rent_range.hard_max) && record.brent.present? && record.period.present? if rent_range.present? && !weekly_value_in_range(record, "brent", rent_range.hard_min, rent_range.hard_max) && record.brent.present? && record.period.present?
if record.weekly_value(record["brent"]) < rent_range.hard_min if record.weekly_value(record["brent"]) < rent_range.hard_min
@ -201,7 +206,9 @@ private
record.errors.add :rent_type, I18n.t("validations.financial.brent.rent_type.below_hard_min") record.errors.add :rent_type, I18n.t("validations.financial.brent.rent_type.below_hard_min")
record.errors.add :needstype, I18n.t("validations.financial.brent.needstype.below_hard_min") record.errors.add :needstype, I18n.t("validations.financial.brent.needstype.below_hard_min")
record.errors.add :period, I18n.t("validations.financial.brent.period.below_hard_min") record.errors.add :period, I18n.t("validations.financial.brent.period.below_hard_min")
elsif record.beds.blank? || record.beds < LaRentRange::MAX_BEDS end
if record.weekly_value(record["brent"]) > rent_range.hard_max
record.errors.add :brent, I18n.t("validations.financial.brent.above_hard_max") record.errors.add :brent, I18n.t("validations.financial.brent.above_hard_max")
record.errors.add :beds, I18n.t("validations.financial.brent.beds.above_hard_max") record.errors.add :beds, I18n.t("validations.financial.brent.beds.above_hard_max")
record.errors.add :la, I18n.t("validations.financial.brent.la.above_hard_max") record.errors.add :la, I18n.t("validations.financial.brent.la.above_hard_max")

8
spec/models/validations/financial_validations_spec.rb

@ -788,7 +788,7 @@ RSpec.describe Validations::FinancialValidations do
LaRentRange.create!( LaRentRange.create!(
ranges_rent_id: "1", ranges_rent_id: "1",
la: "E07000223", la: "E07000223",
beds: 1, beds: 4,
lettype: 1, lettype: 1,
soft_min: 12.41, soft_min: 12.41,
soft_max: 89.54, soft_max: 89.54,
@ -814,7 +814,7 @@ RSpec.describe Validations::FinancialValidations do
record.lettype = 1 record.lettype = 1
record.period = 1 record.period = 1
record.la = "E07000223" record.la = "E07000223"
record.beds = 1 record.beds = 4
record.startdate = Time.zone.local(2021, 9, 17) record.startdate = Time.zone.local(2021, 9, 17)
record.brent = 9.17 record.brent = 9.17
@ -846,7 +846,7 @@ RSpec.describe Validations::FinancialValidations do
record.lettype = 1 record.lettype = 1
record.period = 1 record.period = 1
record.la = "E07000223" record.la = "E07000223"
record.beds = 1 record.beds = 4
record.startdate = Time.zone.local(2021, 9, 17) record.startdate = Time.zone.local(2021, 9, 17)
record.brent = 200 record.brent = 200
@ -883,7 +883,7 @@ RSpec.describe Validations::FinancialValidations do
record.period = 1 record.period = 1
record.la = "E07000223" record.la = "E07000223"
record.startdate = Time.zone.local(2022, 2, 5) record.startdate = Time.zone.local(2022, 2, 5)
record.beds = 1 record.beds = 4
record.brent = 200 record.brent = 200
financial_validator.validate_rent_amount(record) financial_validator.validate_rent_amount(record)

Loading…
Cancel
Save