Browse Source

Remove validations for presence (#223)

pull/225/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
34454ed9d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      app/models/validations/financial_validations.rb
  2. 4
      config/forms/2021_2022.json
  3. 2
      config/locales/en.yml
  4. 9
      spec/models/case_log_spec.rb

18
app/models/validations/financial_validations.rb

@ -2,9 +2,6 @@ module Validations::FinancialValidations
# Validations methods need to be called 'validate_<page_name>' to run on model save # Validations methods need to be called 'validate_<page_name>' to run on model save
# or 'validate_' to run on submit as well # or 'validate_' to run on submit as well
def validate_outstanding_rent_amount(record) 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? if record.hbrentshortfall == "No" && record.tshortfall.present?
record.errors.add :tshortfall, I18n.t("validations.financial.tshortfall.outstanding_amount_not_required") record.errors.add :tshortfall, I18n.t("validations.financial.tshortfall.outstanding_amount_not_required")
end end
@ -35,21 +32,14 @@ module Validations::FinancialValidations
end end
end end
def validate_hbrentshortfall(record) def validate_tshortfall(record)
is_present = record.hbrentshortfall.present?
is_yes = record.hbrentshortfall == "Yes" is_yes = record.hbrentshortfall == "Yes"
hb_donotknow = record.hb == "Don't know" hb_donotknow = record.hb == "Don't know"
hb_none = record.hb == "None" hb_none = record.hb == "None"
hb_uc_no_hb = record.hb == "Universal Credit (without housing element)" 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
end end

4
config/forms/2021_2022.json

@ -2680,7 +2680,9 @@
"type": "numeric", "type": "numeric",
"min": 0, "min": 0,
"step": 1, "step": 1,
"width": 5 "width": 5,
"prefix": "£",
"suffix": "every month"
} }
}, },
"depends_on": [{"has_benefits": "Yes", "depends_on": [{"has_benefits": "Yes",

2
config/locales/en.yml

@ -58,11 +58,9 @@ en:
financial: financial:
tshortfall: 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." outstanding_amount_not_required: "You must not answer the outstanding amount question if you don't have outstanding rent or charges."
hbrentshortfall: 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" 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: 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" 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: earnings:

9
spec/models/case_log_spec.rb

@ -355,15 +355,6 @@ RSpec.describe Form, type: :model do
end end
context "outstanding rent or charges validation" do 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 it "must be not be anwered if answered no to outstanding rent or charges" do
expect { expect {
CaseLog.create!(hbrentshortfall: "No", CaseLog.create!(hbrentshortfall: "No",

Loading…
Cancel
Save