Browse Source

Add validation to dependent earnings and incfreq fields (#985)

We need to add a validation here so that we can clear both values on import. If we don't do this then the validation will continue to trigger and the importer will get stuck in an endless loop.
pull/986/head
James Rose 2 years ago committed by GitHub
parent
commit
492ebb2d4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/models/validations/financial_validations.rb
  2. 4
      spec/models/validations/financial_validations_spec.rb

2
app/models/validations/financial_validations.rb

@ -34,10 +34,12 @@ module Validations::FinancialValidations
if record.earnings.present? && record.incfreq.blank?
record.errors.add :incfreq, I18n.t("validations.financial.earnings.freq_missing")
record.errors.add :earnings, I18n.t("validations.financial.earnings.freq_missing")
end
if record.incfreq.present? && record.earnings.blank?
record.errors.add :earnings, I18n.t("validations.financial.earnings.earnings_missing")
record.errors.add :incfreq, I18n.t("validations.financial.earnings.earnings_missing")
end
end

4
spec/models/validations/financial_validations_spec.rb

@ -18,6 +18,8 @@ RSpec.describe Validations::FinancialValidations do
financial_validator.validate_net_income(record)
expect(record.errors["incfreq"])
.to include(match I18n.t("validations.financial.earnings.freq_missing"))
expect(record.errors["earnings"])
.to include(match I18n.t("validations.financial.earnings.freq_missing"))
end
it "when income frequency is provided it validates that earnings must be provided" do
@ -26,6 +28,8 @@ RSpec.describe Validations::FinancialValidations do
financial_validator.validate_net_income(record)
expect(record.errors["earnings"])
.to include(match I18n.t("validations.financial.earnings.earnings_missing"))
expect(record.errors["incfreq"])
.to include(match I18n.t("validations.financial.earnings.earnings_missing"))
end
end

Loading…
Cancel
Save