Browse Source

add more financial validations (#329)

pull/333/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
b60fbde4bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      app/models/validations/financial_validations.rb
  2. 1
      config/locales/en.yml
  3. 24
      spec/models/validations/financial_validations_spec.rb

9
app/models/validations/financial_validations.rb

@ -40,6 +40,15 @@ module Validations::FinancialValidations
end end
end end
def validate_negative_currency(record)
t = %w[earnings brent scharge pscharge supcharg]
t.each do |x|
if record[x].present? && record[x].negative?
record.errors.add x.to_sym, I18n.t("validations.financial.negative_currency")
end
end
end
def validate_tshortfall(record) def validate_tshortfall(record)
is_yes = record.hbrentshortfall == "Yes" is_yes = record.hbrentshortfall == "Yes"
hb_donotknow = record.hb == "Don’t know" hb_donotknow = record.hb == "Don’t know"

1
config/locales/en.yml

@ -78,6 +78,7 @@ en:
under_hard_min: "Net income cannot be less than %{hard_min} given the tenant’s working situation" under_hard_min: "Net income cannot be less than %{hard_min} given the tenant’s working situation"
freq_missing: "Select how often the household receives income" freq_missing: "Select how often the household receives income"
earnings_missing: "Enter how much income the household has in total" earnings_missing: "Enter how much income the household has in total"
negative_currency: "Enter an amount above 0"
household: household:
reasonpref: reasonpref:

24
spec/models/validations/financial_validations_spec.rb

@ -152,4 +152,28 @@ RSpec.describe Validations::FinancialValidations do
end end
end end
end end
describe "financial validations" do
context "when currency is negative" do
it "returns error" do
record.earnings = -8
record.brent = -2
record.scharge = -134
record.pscharge = -10_024
record.supcharg = -1
financial_validator.validate_negative_currency(record)
expect(record.errors["earnings"])
.to include(match I18n.t("validations.financial.negative_currency"))
expect(record.errors["brent"])
.to include(match I18n.t("validations.financial.negative_currency"))
expect(record.errors["scharge"])
.to include(match I18n.t("validations.financial.negative_currency"))
expect(record.errors["pscharge"])
.to include(match I18n.t("validations.financial.negative_currency"))
expect(record.errors["supcharg"])
.to include(match I18n.t("validations.financial.negative_currency"))
end
end
end
end end

Loading…
Cancel
Save