From ffc42ac3b05e8ce7aa98da57ca1180988038d9e1 Mon Sep 17 00:00:00 2001 From: Jack S Date: Thu, 6 Apr 2023 10:19:23 +0100 Subject: [PATCH] Format more locales --- .../validations/financial_validations.rb | 21 ++++++++++++++++--- config/locales/en.yml | 14 ++++++------- .../validations/financial_validations_spec.rb | 4 ++-- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb index db80b6bb7..3a0014119 100644 --- a/app/models/validations/financial_validations.rb +++ b/app/models/validations/financial_validations.rb @@ -1,5 +1,6 @@ module Validations::FinancialValidations include Validations::SharedValidations + include MoneyFormattingHelper # 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) @@ -24,12 +25,26 @@ module Validations::FinancialValidations def validate_net_income(record) if record.ecstat1 && record.weekly_net_income if record.weekly_net_income > record.applicable_income_range.hard_max - record.errors.add :earnings, :over_hard_max, message: I18n.t("validations.financial.earnings.over_hard_max", hard_max: record.applicable_income_range.hard_max) - record.errors.add :ecstat1, :over_hard_max, message: I18n.t("validations.financial.ecstat.over_hard_max", hard_max: record.applicable_income_range.hard_max) + hard_max = format_as_currency(record.applicable_income_range.hard_max) + record.errors.add( + :earnings, + :over_hard_max, + message: I18n.t("validations.financial.earnings.over_hard_max", hard_max:), + ) + record.errors.add( + :ecstat1, + :over_hard_max, + message: I18n.t("validations.financial.ecstat.over_hard_max", hard_max:), + ) end if record.weekly_net_income < record.applicable_income_range.hard_min - record.errors.add :earnings, :under_hard_min, message: I18n.t("validations.financial.earnings.under_hard_min", hard_min: record.applicable_income_range.hard_min) + hard_min = format_as_currency(record.applicable_income_range.hard_min) + record.errors.add( + :earnings, + :under_hard_min, + message: I18n.t("validations.financial.earnings.under_hard_min", hard_min:), + ) end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 196022b45..5f703b7e9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -243,15 +243,15 @@ en: benefits: part_or_full_time: "Answer cannot be ‘all’ for income from Universal Credit, state pensions or benefits if the tenant or their partner works part-time or full-time" earnings: - over_hard_max: "Net income cannot be greater than £%{hard_max} per week given the tenant’s working situation" - under_hard_min: "Net income cannot be less than £%{hard_min} per week given the tenant’s working situation" + over_hard_max: "Net income cannot be greater than %{hard_max} per week given the tenant’s working situation" + under_hard_min: "Net income cannot be less than %{hard_min} per week given the tenant’s working situation" freq_missing: "Select how often the household receives income" earnings_missing: "Enter how much income the household has in total" income: - over_hard_max_for_london: "Income must not exceed £90,000 for properties within London local authorities" - over_hard_max_for_outside_london: "Income must not exceed £80,000 for properties outside London local authorities" - combined_over_hard_max_for_london: "Combined income must not exceed £90,000 for properties within London local authorities" - combined_over_hard_max_for_outside_london: "Combined income must not exceed £80,000 for properties outside London local authorities" + over_hard_max_for_london: "Income must not exceed £90,000.00 for properties within London local authorities" + over_hard_max_for_outside_london: "Income must not exceed £80,000.00 for properties outside London local authorities" + combined_over_hard_max_for_london: "Combined income must not exceed £90,000.00 for properties within London local authorities" + combined_over_hard_max_for_outside_london: "Combined income must not exceed £80,000.00 for properties outside London local authorities" child_has_income: "Child's income must be £0" negative_currency: "Enter an amount above 0" rent: @@ -493,7 +493,7 @@ en: property_type_bedsit: "A bedsit cannot have more than 1 bedroom" discounted_ownership_value: "Mortgage, deposit, and grant total must equal %{value_with_discount}" monthly_rent: - higher_than_expected: "Basic monthly rent must be between £0 and £9,999" + higher_than_expected: "Basic monthly rent must be between £0.00 and £9,999.00" soft_validations: net_income: diff --git a/spec/models/validations/financial_validations_spec.rb b/spec/models/validations/financial_validations_spec.rb index ab7fd1693..6ae2a4607 100644 --- a/spec/models/validations/financial_validations_spec.rb +++ b/spec/models/validations/financial_validations_spec.rb @@ -202,7 +202,7 @@ RSpec.describe Validations::FinancialValidations do record.ecstat1 = 1 financial_validator.validate_net_income(record) expect(record.errors["earnings"]) - .to include(match I18n.t("validations.financial.earnings.over_hard_max", hard_max: 1230)) + .to eq(["Net income cannot be greater than £1,230.00 per week given the tenant’s working situation"]) end end @@ -213,7 +213,7 @@ RSpec.describe Validations::FinancialValidations do record.ecstat1 = 1 financial_validator.validate_net_income(record) expect(record.errors["earnings"]) - .to include(match I18n.t("validations.financial.earnings.under_hard_min", hard_min: 90)) + .to eq(["Net income cannot be less than £90.00 per week given the tenant’s working situation"]) end end end