Browse Source

Pluralise buyer in validations and translations

pull/2272/head
Kat 2 years ago
parent
commit
08036cab4c
  1. 8
      app/models/validations/sales/financial_validations.rb
  2. 8
      app/models/validations/sales/property_validations.rb
  3. 18
      config/locales/en.yml
  4. 27
      spec/models/validations/sales/financial_validations_spec.rb
  5. 19
      spec/models/validations/sales/property_validations_spec.rb

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

@ -48,7 +48,7 @@ module Validations::Sales::FinancialValidations
return unless record.stairbought && record.stairowned
if record.stairbought > record.stairowned
record.errors.add :stairowned, I18n.t("validations.financial.staircasing.percentage_bought_must_be_greater_than_percentage_owned")
record.errors.add :stairowned, I18n.t("validations.financial.staircasing.percentage_bought_must_be_greater_than_percentage_owned", persons: record.joint_purchase? ? "buyers" : "buyer")
end
end
@ -125,9 +125,9 @@ module Validations::Sales::FinancialValidations
if record.equity > record.stairowned - record.stairbought
formatted_equity = sprintf("%g", record.equity)
record.errors.add :equity, I18n.t("validations.financial.equity.over_stairowned_minus_stairbought", equity: formatted_equity, staircase_difference: record.stairowned - record.stairbought)
record.errors.add :stairowned, I18n.t("validations.financial.equity.over_stairowned_minus_stairbought", equity: formatted_equity, staircase_difference: record.stairowned - record.stairbought)
record.errors.add :stairbought, I18n.t("validations.financial.equity.over_stairowned_minus_stairbought", equity: formatted_equity, staircase_difference: record.stairowned - record.stairbought)
record.errors.add :equity, I18n.t("validations.financial.equity.over_stairowned_minus_stairbought", equity: formatted_equity, staircase_difference: record.stairowned - record.stairbought, person_owns: record.joint_purchase? ? "buyers own" : "buyer owns")
record.errors.add :stairowned, I18n.t("validations.financial.equity.over_stairowned_minus_stairbought", equity: formatted_equity, staircase_difference: record.stairowned - record.stairbought, person_owns: record.joint_purchase? ? "buyers own" : "buyer owns")
record.errors.add :stairbought, I18n.t("validations.financial.equity.over_stairowned_minus_stairbought", equity: formatted_equity, staircase_difference: record.stairowned - record.stairbought, person_owns: record.joint_purchase? ? "buyers own" : "buyer owns")
end
end

8
app/models/validations/sales/property_validations.rb

@ -4,10 +4,10 @@ module Validations::Sales::PropertyValidations
return unless record.ppostcode_full.present? && record.postcode_full.present?
if record.discounted_ownership_sale? && record.ppostcode_full != record.postcode_full
record.errors.add :postcode_full, I18n.t("validations.property.postcode.must_match_previous")
record.errors.add :ppostcode_full, I18n.t("validations.property.postcode.must_match_previous")
record.errors.add :ownershipsch, I18n.t("validations.property.postcode.must_match_previous")
record.errors.add :uprn, I18n.t("validations.property.postcode.must_match_previous")
record.errors.add :postcode_full, I18n.t("validations.property.postcode.must_match_previous", persons: record.joint_purchase? ? "Buyers‘" : "Buyer‘s")
record.errors.add :ppostcode_full, I18n.t("validations.property.postcode.must_match_previous", persons: record.joint_purchase? ? "Buyers‘" : "Buyer‘s")
record.errors.add :ownershipsch, I18n.t("validations.property.postcode.must_match_previous", persons: record.joint_purchase? ? "Buyers‘" : "Buyer‘s")
record.errors.add :uprn, I18n.t("validations.property.postcode.must_match_previous", persons: record.joint_purchase? ? "Buyers‘" : "Buyer‘s")
end
end

18
config/locales/en.yml

@ -350,7 +350,7 @@ en:
proptype:
bedsits_have_max_one_bedroom: "Answer cannot be 'Bedsit' if the property has 2 or more bedrooms"
postcode:
must_match_previous: "Buyer's last accommodation and discounted ownership postcodes must match"
must_match_previous: "%{persons} last accommodation and discounted ownership postcodes must match"
financial:
tshortfall:
@ -428,7 +428,7 @@ en:
not_provided: "Enter how much rent and other charges the household pays %{period}"
cash_discount_invalid: "Cash discount must be £0 - £999,999"
staircasing:
percentage_bought_must_be_greater_than_percentage_owned: "Total percentage buyer now owns must be more than percentage bought in this transaction"
percentage_bought_must_be_greater_than_percentage_owned: "Total percentage %{persons} now owns must be more than percentage bought in this transaction"
percentage_bought_must_be_at_least_threshold: "The minimum increase in equity while staircasing is %{threshold}%"
percentage_bought_equal_percentage_owned: "The percentage bought is %{stairbought}% and the percentage owned in total is %{stairowned}%. These figures cannot be the same."
monthly_leasehold_charges:
@ -436,7 +436,7 @@ en:
equity:
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}%"
over_stairowned_minus_stairbought: "The initial equity stake is %{equity}% and the percentage owned in total minus the percentage bought is %{staircase_difference}%. In a staircasing transaction, the equity stake purchased cannot be larger than the percentage the buyer owns minus the percentage bought."
over_stairowned_minus_stairbought: "The initial equity stake is %{equity}% and the percentage owned in total minus the percentage bought is %{staircase_difference}%. In a staircasing transaction, the equity stake purchased cannot be larger than the percentage the %{person_owns} minus the percentage bought."
mortgage: "Mortgage value cannot be £0 if a mortgage was used for the purchase of this property"
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"
@ -689,7 +689,9 @@ Make sure these answers are correct."
shared_ownership_deposit:
title_text: "You told us that the %{mortgage_deposit_and_discount_error_fields} add up to %{mortgage_deposit_and_discount_total}"
old_persons_shared_ownership:
title_text: "You told us the buyer is using the Older Persons Shared Ownership scheme."
title_text:
one: "You told us the buyer is using the Older Persons Shared Ownership scheme."
two: "You told us the buyers are using the Older Persons Shared Ownership scheme."
hint_text: "At least one buyer must be aged 65 years and over to use this scheme."
staircase_bought_seems_high:
title_text: "You told us that %{percentage}% was bought in this staircasing transaction."
@ -714,10 +716,14 @@ Make sure these answers are correct."
title_text: "You told us that the percentage discount is %{discount}."
hint_text: "This is higher than we would expect."
savings:
title_text: "You told us the buyer’s savings were %{savings}."
title_text:
one: "You told us the buyer’s savings were %{savings}."
two: "You told us the buyers’ savings were %{savings}."
hint_text: "This is higher than we would expect."
deposit:
title_text: "You told us the buyer’s deposit was %{deposit} and their savings were %{savings}."
title_text:
one: "You told us the buyer’s deposit was %{deposit} and their savings were %{savings}."
two: "You told us the buyers’ deposit was %{deposit} and their savings were %{savings}."
hint_text: "The deposit amount is higher than we would expect for the amount of savings they have."
grant:
title_text: "You told us that the grant amount is %{grant}"

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

@ -148,11 +148,20 @@ RSpec.describe Validations::Sales::FinancialValidations do
expect(record.errors).to be_empty
end
it "adds an error to stairowned and not stairbought if the percentage bought is more than the percentage owned" do
it "adds an error to stairowned and not stairbought if the percentage bought is more than the percentage owned for joint purchase" do
record.stairbought = 50
record.stairowned = 40
record.jointpur = 1
financial_validator.validate_percentage_bought_not_greater_than_percentage_owned(record)
expect(record.errors["stairowned"]).to include(match I18n.t("validations.financial.staircasing.percentage_bought_must_be_greater_than_percentage_owned"))
expect(record.errors["stairowned"]).to include("Total percentage buyers now owns must be more than percentage bought in this transaction")
end
it "adds an error to stairowned and not stairbought if the percentage bought is more than the percentage owned for non joint purchase" do
record.stairbought = 50
record.stairowned = 40
record.jointpur = 2
financial_validator.validate_percentage_bought_not_greater_than_percentage_owned(record)
expect(record.errors["stairowned"]).to include("Total percentage buyer now owns must be more than percentage bought in this transaction")
end
end
@ -589,10 +598,22 @@ RSpec.describe Validations::Sales::FinancialValidations do
context "with a log in 24/25 collection year" do
let(:now) { Time.zone.local(2024, 4, 1) }
it "adds errors if equity is more than stairowned - stairbought" do
it "adds errors if equity is more than stairowned - stairbought for joint purchase" do
record.stairbought = 2
record.stairowned = 3
record.equity = 2
record.jointpur = 1
financial_validator.validate_equity_less_than_staircase_difference(record)
expect(record.errors["equity"]).to include("The initial equity stake is 2% and the percentage owned in total minus the percentage bought is 1%. In a staircasing transaction, the equity stake purchased cannot be larger than the percentage the buyers own minus the percentage bought.")
expect(record.errors["stairowned"]).to include("The initial equity stake is 2% and the percentage owned in total minus the percentage bought is 1%. In a staircasing transaction, the equity stake purchased cannot be larger than the percentage the buyers own minus the percentage bought.")
expect(record.errors["stairbought"]).to include("The initial equity stake is 2% and the percentage owned in total minus the percentage bought is 1%. In a staircasing transaction, the equity stake purchased cannot be larger than the percentage the buyers own minus the percentage bought.")
end
it "adds errors if equity is more than stairowned - stairbought for non joint purchase" do
record.stairbought = 2
record.stairowned = 3
record.equity = 2
record.jointpur = 2
financial_validator.validate_equity_less_than_staircase_difference(record)
expect(record.errors["equity"]).to include("The initial equity stake is 2% and the percentage owned in total minus the percentage bought is 1%. In a staircasing transaction, the equity stake purchased cannot be larger than the percentage the buyer owns minus the percentage bought.")
expect(record.errors["stairowned"]).to include("The initial equity stake is 2% and the percentage owned in total minus the percentage bought is 1%. In a staircasing transaction, the equity stake purchased cannot be larger than the percentage the buyer owns minus the percentage bought.")

19
spec/models/validations/sales/property_validations_spec.rb

@ -46,13 +46,24 @@ RSpec.describe Validations::Sales::PropertyValidations do
expect(record.errors["ownershipsch"]).to be_empty
end
it "when postcodes do not match an error is added" do
it "when postcodes do not match an error is added for joint purchase" do
record.postcode_full = "SW1A 1AA"
record.ppostcode_full = "SW1A 0AA"
record.jointpur = 1
property_validator.validate_postcodes_match_if_discounted_ownership(record)
expect(record.errors["postcode_full"]).to include(match I18n.t("validations.property.postcode.must_match_previous"))
expect(record.errors["ppostcode_full"]).to include(match I18n.t("validations.property.postcode.must_match_previous"))
expect(record.errors["ownershipsch"]).to include(match I18n.t("validations.property.postcode.must_match_previous"))
expect(record.errors["postcode_full"]).to include("Buyers‘ last accommodation and discounted ownership postcodes must match")
expect(record.errors["ppostcode_full"]).to include("Buyers‘ last accommodation and discounted ownership postcodes must match")
expect(record.errors["ownershipsch"]).to include("Buyers‘ last accommodation and discounted ownership postcodes must match")
end
it "when postcodes do not match an error is added for non joint purchase" do
record.postcode_full = "SW1A 1AA"
record.ppostcode_full = "SW1A 0AA"
record.jointpur = 2
property_validator.validate_postcodes_match_if_discounted_ownership(record)
expect(record.errors["postcode_full"]).to include("Buyer‘s last accommodation and discounted ownership postcodes must match")
expect(record.errors["ppostcode_full"]).to include("Buyer‘s last accommodation and discounted ownership postcodes must match")
expect(record.errors["ownershipsch"]).to include("Buyer‘s last accommodation and discounted ownership postcodes must match")
end
it "does not add error for 2024 log" do

Loading…
Cancel
Save