Browse Source

Add brent/tshortfall validation

pull/388/head
Kat 3 years ago
parent
commit
f3c4628502
  1. 7
      app/models/validations/financial_validations.rb
  2. 5
      config/locales/en.yml
  3. 15
      spec/models/validations/financial_validations_spec.rb
  4. 4
      spec/models/validations/shared_validations_spec.rb

7
app/models/validations/financial_validations.rb

@ -58,4 +58,11 @@ module Validations::FinancialValidations
record.errors.add :tshortfall, I18n.t("validations.financial.hbrentshortfall.outstanding_no_benefits")
end
end
def validate_rent_amount(record)
if record.brent.present? && record.tshortfall.present? && record.brent < record.tshortfall * 2
record.errors.add :brent, I18n.t("validations.financial.rent.less_than_double_shortfall", tshortfall: record.tshortfall * 2)
record.errors.add :tshortfall, I18n.t("validations.financial.tshortfall.more_than_rent")
end
end
end

5
config/locales/en.yml

@ -78,7 +78,8 @@ en:
financial:
tshortfall:
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"
more_than_rent: "Answer cannot be more than half of the basic rent amount"
hbrentshortfall:
outstanding_no_benefits: "Outstanding amount for basic rent and/or benefit eligible charges cannot be 'Yes' if tenant is not in receipt of housing benefit or universal benefit or if benefit is unknown"
benefits:
@ -89,6 +90,8 @@ en:
freq_missing: "Select how often the household receives income"
earnings_missing: "Enter how much income the household has in total"
negative_currency: "Enter an amount above 0"
rent:
less_than_double_shortfall: "Answer cannot be less than double shortfall in basic rent"
household:
reasonpref:

15
spec/models/validations/financial_validations_spec.rb

@ -186,4 +186,19 @@ RSpec.describe Validations::FinancialValidations do
end
end
end
describe "rent and charges validations" do
context "when shortfall amount is provided" do
it "validates that basic rent is no less than double the shortfall" do
record.hbrentshortfall = 1
record.tshortfall = 99.50
record.brent = 198
financial_validator.validate_rent_amount(record)
expect(record.errors["brent"])
.to include(match I18n.t("validations.financial.rent.less_than_double_shortfall", shortfall: 198))
expect(record.errors["tshortfall"])
.to include(match I18n.t("validations.financial.tshortfall.more_than_rent"))
end
end
end
end

4
spec/models/validations/shared_validations_spec.rb

@ -1,9 +1,9 @@
require "rails_helper"
RSpec.describe Validations::HouseholdValidations do
RSpec.describe Validations::SharedValidations do
subject(:household_validator) { validator_class.new }
let(:validator_class) { Class.new { include Validations::HouseholdValidations } }
let(:validator_class) { Class.new { include Validations::SharedValidations } }
let(:record) { FactoryBot.create(:case_log) }
describe "numeric min max validations" do

Loading…
Cancel
Save