From efc1bf050a0fd061339d04eaba0665d0dc5879d8 Mon Sep 17 00:00:00 2001 From: Sam Seed Date: Fri, 13 Jan 2023 17:57:05 +0000 Subject: [PATCH] feat: add same bedsit validation to number of bedrooms question --- app/models/validations/sales/property_validations.rb | 8 ++++++++ config/locales/en.yml | 1 + 2 files changed, 9 insertions(+) diff --git a/app/models/validations/sales/property_validations.rb b/app/models/validations/sales/property_validations.rb index 80c72d327..aced46af5 100644 --- a/app/models/validations/sales/property_validations.rb +++ b/app/models/validations/sales/property_validations.rb @@ -15,4 +15,12 @@ module Validations::Sales::PropertyValidations record.errors.add :proptype, I18n.t("validations.property.proptype.bedsits_have_max_one_bedroom") end end + + def validate_property_number_of_bedrooms(record) + return if record.proptype.blank? || record.beds.blank? + + unless record.proptype != 2 || record.beds <= 1 + record.errors.add :beds, I18n.t("validations.property.beds.bedsits_have_max_one_bedroom") + end + end end diff --git a/config/locales/en.yml b/config/locales/en.yml index c8b849817..56bd780c3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -202,6 +202,7 @@ en: beds: non_positive: "Number of bedrooms has to be greater than 0" over_max: "Number of bedrooms cannot be more than 12" + bedsits_have_max_one_bedroom: "Properties with 2 or more bedrooms cannot be bedsits" proptype: bedsits_have_max_one_bedroom: "Properties with 2 or more bedrooms cannot be bedsits" postcode: