diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb index f39c17af7..fc1c44585 100644 --- a/app/models/validations/financial_validations.rb +++ b/app/models/validations/financial_validations.rb @@ -188,7 +188,12 @@ private 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 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 :needstype, I18n.t("validations.financial.brent.needstype.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 :beds, I18n.t("validations.financial.brent.beds.above_hard_max") record.errors.add :la, I18n.t("validations.financial.brent.la.above_hard_max") diff --git a/spec/models/validations/financial_validations_spec.rb b/spec/models/validations/financial_validations_spec.rb index 1f40f7cbc..8cb777029 100644 --- a/spec/models/validations/financial_validations_spec.rb +++ b/spec/models/validations/financial_validations_spec.rb @@ -788,7 +788,7 @@ RSpec.describe Validations::FinancialValidations do LaRentRange.create!( ranges_rent_id: "1", la: "E07000223", - beds: 1, + beds: 4, lettype: 1, soft_min: 12.41, soft_max: 89.54, @@ -814,7 +814,7 @@ RSpec.describe Validations::FinancialValidations do record.lettype = 1 record.period = 1 record.la = "E07000223" - record.beds = 1 + record.beds = 4 record.startdate = Time.zone.local(2021, 9, 17) record.brent = 9.17 @@ -846,7 +846,7 @@ RSpec.describe Validations::FinancialValidations do record.lettype = 1 record.period = 1 record.la = "E07000223" - record.beds = 1 + record.beds = 4 record.startdate = Time.zone.local(2021, 9, 17) record.brent = 200 @@ -883,7 +883,7 @@ RSpec.describe Validations::FinancialValidations do record.period = 1 record.la = "E07000223" record.startdate = Time.zone.local(2022, 2, 5) - record.beds = 1 + record.beds = 4 record.brent = 200 financial_validator.validate_rent_amount(record)