Browse Source

Update validation message content

pull/2184/head
Kat 2 years ago
parent
commit
cd1a57ccaa
  1. 8
      app/models/sales_log.rb
  2. 5
      app/models/validations/sales/financial_validations.rb
  3. 2
      config/locales/en.yml
  4. 20
      spec/models/validations/sales/financial_validations_spec.rb

8
app/models/sales_log.rb

@ -279,11 +279,17 @@ class SalesLog < Log
mortgage_amount + deposit_amount + cashdis_amount
end
def value_times_equity
return unless value && equity
value * equity / 100
end
def mortgage_deposit_and_discount_error_fields
[
"mortgage",
"deposit",
cashdis.present? ? "discount" : nil,
cashdis.present? ? "cash discount" : nil,
].compact.to_sentence
end

5
app/models/validations/sales/financial_validations.rb

@ -101,7 +101,10 @@ module Validations::Sales::FinancialValidations
if mortgage_value + record.deposit + record.cashdis != record.value * record.equity / 100
%i[mortgage value deposit ownershipsch cashdis equity].each do |field|
record.errors.add field, I18n.t("validations.financial.shared_ownership_deposit", mortgage_deposit_and_discount_error_fields: record.mortgage_deposit_and_discount_error_fields, mortgage_deposit_and_discount_total: record.field_formatted_as_currency("mortgage_deposit_and_discount_total"))
record.errors.add field, I18n.t("validations.financial.shared_ownership_deposit",
mortgage_deposit_and_discount_error_fields: record.mortgage_deposit_and_discount_error_fields,
mortgage_deposit_and_discount_total: record.field_formatted_as_currency("mortgage_deposit_and_discount_total"),
value_times_equity: record.field_formatted_as_currency("value_times_equity"))
end
end
end

2
config/locales/en.yml

@ -433,7 +433,7 @@ en:
under_min: "The minimum initial equity stake for this type of shared ownership sale is %{min_equity}%"
over_max: "The maximum initial equity stake is %{max_equity}%"
mortgage: "Mortgage value cannot be £0 if a mortgage was used for the purchase of this property"
shared_ownership_deposit: "You told us that the %{mortgage_deposit_and_discount_error_fields} add up to %{mortgage_deposit_and_discount_total}"
shared_ownership_deposit: "The %{mortgage_deposit_and_discount_error_fields} added together is %{mortgage_deposit_and_discount_total}. The value times the equity percentage is %{value_times_equity}. These figures should be the same"
household:
reasonable_preference_reason:

20
spec/models/validations/sales/financial_validations_spec.rb

@ -393,11 +393,11 @@ RSpec.describe Validations::Sales::FinancialValidations do
record.equity = 100
financial_validator.validate_shared_ownership_deposit(record)
expect(record.errors["mortgage"]).to include("You told us that the mortgage, deposit, and discount add up to £2,000.00")
expect(record.errors["deposit"]).to include("You told us that the mortgage, deposit, and discount add up to £2,000.00")
expect(record.errors["cashdis"]).to include("You told us that the mortgage, deposit, and discount add up to £2,000.00")
expect(record.errors["value"]).to include("You told us that the mortgage, deposit, and discount add up to £2,000.00")
expect(record.errors["equity"]).to include("You told us that the mortgage, deposit, and discount add up to £2,000.00")
expect(record.errors["mortgage"]).to include("The mortgage, deposit, and cash discount added together is £2,000.00. The value times the equity percentage is £3,000.00. These figures should be the same")
expect(record.errors["deposit"]).to include("The mortgage, deposit, and cash discount added together is £2,000.00. The value times the equity percentage is £3,000.00. These figures should be the same")
expect(record.errors["cashdis"]).to include("The mortgage, deposit, and cash discount added together is £2,000.00. The value times the equity percentage is £3,000.00. These figures should be the same")
expect(record.errors["value"]).to include("The mortgage, deposit, and cash discount added together is £2,000.00. The value times the equity percentage is £3,000.00. These figures should be the same")
expect(record.errors["equity"]).to include("The mortgage, deposit, and cash discount added together is £2,000.00. The value times the equity percentage is £3,000.00. These figures should be the same")
end
it "does not add an error if no deposit is given" do
@ -487,11 +487,11 @@ RSpec.describe Validations::Sales::FinancialValidations do
record.equity = 100
financial_validator.validate_shared_ownership_deposit(record)
expect(record.errors["mortgage"]).to include("You told us that the mortgage, deposit, and discount add up to £3,000.00")
expect(record.errors["deposit"]).to include("You told us that the mortgage, deposit, and discount add up to £3,000.00")
expect(record.errors["cashdis"]).to include("You told us that the mortgage, deposit, and discount add up to £3,000.00")
expect(record.errors["value"]).to include("You told us that the mortgage, deposit, and discount add up to £3,000.00")
expect(record.errors["equity"]).to include("You told us that the mortgage, deposit, and discount add up to £3,000.00")
expect(record.errors["mortgage"]).to include("The mortgage, deposit, and cash discount added together is £3,000.00. The value times the equity percentage is £4,323.00. These figures should be the same")
expect(record.errors["deposit"]).to include("The mortgage, deposit, and cash discount added together is £3,000.00. The value times the equity percentage is £4,323.00. These figures should be the same")
expect(record.errors["cashdis"]).to include("The mortgage, deposit, and cash discount added together is £3,000.00. The value times the equity percentage is £4,323.00. These figures should be the same")
expect(record.errors["value"]).to include("The mortgage, deposit, and cash discount added together is £3,000.00. The value times the equity percentage is £4,323.00. These figures should be the same")
expect(record.errors["equity"]).to include("The mortgage, deposit, and cash discount added together is £3,000.00. The value times the equity percentage is £4,323.00. These figures should be the same")
end
end

Loading…
Cancel
Save