From 34454ed9d68faa68f2e3236b6337b4d8ff04fe3a Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Mon, 17 Jan 2022 15:01:40 +0000 Subject: [PATCH] Remove validations for presence (#223) --- .../validations/financial_validations.rb | 18 ++++-------------- config/forms/2021_2022.json | 4 +++- config/locales/en.yml | 2 -- spec/models/case_log_spec.rb | 9 --------- 4 files changed, 7 insertions(+), 26 deletions(-) diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb index c9088d30c..fa05c3896 100644 --- a/app/models/validations/financial_validations.rb +++ b/app/models/validations/financial_validations.rb @@ -2,9 +2,6 @@ module Validations::FinancialValidations # Validations methods need to be called 'validate_' to run on model save # or 'validate_' to run on submit as well def validate_outstanding_rent_amount(record) - if record.hbrentshortfall == "Yes" && record.tshortfall.blank? - record.errors.add :tshortfall, I18n.t("validations.financial.tshortfall.outstanding_amount_required") - end if record.hbrentshortfall == "No" && record.tshortfall.present? record.errors.add :tshortfall, I18n.t("validations.financial.tshortfall.outstanding_amount_not_required") end @@ -35,21 +32,14 @@ module Validations::FinancialValidations end end - def validate_hbrentshortfall(record) - is_present = record.hbrentshortfall.present? + def validate_tshortfall(record) is_yes = record.hbrentshortfall == "Yes" hb_donotknow = record.hb == "Don't know" hb_none = record.hb == "None" hb_uc_no_hb = record.hb == "Universal Credit (without housing element)" - hb_no_uc = record.hb == "Housing benefit" - hb_uc_no_he_hb = record.hb == "Universal Credit with housing element (excluding housing benefit)" - hb_and_uc = record.hb == "Housing benefit and Universal Credit (without housing element)" - - conditions = [ - { condition: is_yes && (hb_donotknow || hb_none || hb_uc_no_hb), error: I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits") }, - { condition: (hb_no_uc || hb_uc_no_he_hb || hb_and_uc) && !is_present, error: I18n.t("validations.financial.hbrentshortfall.amount_required") }, - ] - conditions.each { |condition| condition[:condition] ? (record.errors.add :hbrentshortfall, condition[:error]) : nil } + if is_yes && (hb_donotknow || hb_none || hb_uc_no_hb) + record.errors.add :tshortfall, I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits") + end end end diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 81518761d..558720cfd 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -2680,7 +2680,9 @@ "type": "numeric", "min": 0, "step": 1, - "width": 5 + "width": 5, + "prefix": "£", + "suffix": "every month" } }, "depends_on": [{"has_benefits": "Yes", diff --git a/config/locales/en.yml b/config/locales/en.yml index 6047440be..d0c20ef64 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -58,11 +58,9 @@ en: financial: tshortfall: - outstanding_amount_required: "You must answer the outstanding amount question if you have outstanding rent or charges." outstanding_amount_not_required: "You must not answer the outstanding amount question if you don't have outstanding rent or charges." hbrentshortfall: outstanding_no_benefits: "Outstanding amount for basic rent and/or benefit eligible charges can not be 'Yes' if tenant is not in receipt of housing benefit or universal benefit or if benefit is unknown" - amount_required: "Must be completed if Universal credit and/or Housing Benefit received" benefits: part_or_full_time: "income is from Universal Credit, state pensions or benefits cannot be All if the tenant or the partner works part or full time" earnings: diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index e09c209e8..e23c28d33 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -355,15 +355,6 @@ RSpec.describe Form, type: :model do end context "outstanding rent or charges validation" do - it "must be anwered if answered yes to outstanding rent or charges" do - expect { - CaseLog.create!(hbrentshortfall: "Yes", - tshortfall: nil, - owning_organisation: owning_organisation, - managing_organisation: managing_organisation) - }.to raise_error(ActiveRecord::RecordInvalid) - end - it "must be not be anwered if answered no to outstanding rent or charges" do expect { CaseLog.create!(hbrentshortfall: "No",