From edcf57adac30dd90281a7d634fa7b29d8723b3af Mon Sep 17 00:00:00 2001 From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com> Date: Wed, 20 Nov 2024 12:26:56 +0000 Subject: [PATCH] Update location units question validation --- app/models/location.rb | 3 ++- config/locales/en.yml | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/location.rb b/app/models/location.rb index 03af24a94..1f0f89fbc 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -2,7 +2,8 @@ class Location < ApplicationRecord validates :postcode, on: :postcode, presence: { message: I18n.t("validations.location.postcode_blank") } validate :validate_postcode, on: :postcode, if: proc { |model| model.postcode.presence } validates :location_admin_district, on: :location_admin_district, presence: { message: I18n.t("validations.location_admin_district") } - validates :units, on: :units, presence: { message: I18n.t("validations.location.units") } + validates :units, on: :units, presence: { message: I18n.t("validations.location.units.must_be_number") } + validates :units, numericality: { greater_than: 1, message: I18n.t("validations.location.units.must_be_one_or_more") } validates :type_of_unit, on: :type_of_unit, presence: { message: I18n.t("validations.location.type_of_unit") } validates :mobility_type, on: :mobility_type, presence: { message: I18n.t("validations.location.mobility_standards") } validates :startdate, on: :startdate, presence: { message: I18n.t("validations.location.startdate_invalid") } diff --git a/config/locales/en.yml b/config/locales/en.yml index f8bb8255b..0950210f3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -354,7 +354,9 @@ en: location: postcode_blank: "Enter a postcode." - units: "The units at this location must be a number." + units: + must_be_number: "The units at this location must be a number." + must_be_one_or_more: "Number of units must be at least 1." type_of_unit: "Select the most common type of unit at this location." mobility_standards: "Select the mobility standard for the majority of the units at this location." startdate_invalid: "Enter a valid day, month and year when the first property became available at this location."