Browse Source

Last settled accommodation and discounted ownership property postcodes must match (#1213)

pull/1226/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
3308d86a10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      app/models/validations/sales/household_validations.rb
  2. 4
      config/locales/en.yml
  3. 58
      spec/models/validations/sales/household_validations_spec.rb

9
app/models/validations/sales/household_validations.rb

@ -32,6 +32,15 @@ module Validations::Sales::HouseholdValidations
end
end
def validate_previous_postcode(record)
return unless record.postcode_full && record.ppostcode_full && record.discounted_ownership_sale?
unless record.postcode_full == record.ppostcode_full
record.errors.add :postcode_full, I18n.t("validations.household.postcode.discounted_ownership")
record.errors.add :ppostcode_full, I18n.t("validations.household.postcode.discounted_ownership")
end
end
private
def validate_person_age_matches_relationship(record, person_num)

4
config/locales/en.yml

@ -369,7 +369,9 @@ en:
condition_effects:
no_choices: "You cannot answer this question as you told us nobody in the household has a physical or mental health condition (or other illness) expected to last 12 months or more"
old_persons_shared_ownership: "Are you sure? At least one buyer should be aged over 64 for Older persons‘ shared ownership scheme"
postcode:
discounted_ownership: "Last settled accommodation and discounted ownership property postcodes must match"
tenancy:
length:
fixed_term_not_required: "You must only answer the length of the tenancy if it's fixed-term"

58
spec/models/validations/sales/household_validations_spec.rb

@ -280,4 +280,62 @@ RSpec.describe Validations::Sales::HouseholdValidations do
end
end
end
describe "previous postcode validations" do
let(:record) { build(:sales_log) }
context "with a discounted sale" do
before do
record.ownershipsch = 2
end
it "adds an error when previous and current postcodes are not the same" do
record.postcode_full = "SO32 3PT"
record.ppostcode_full = "DN6 7FB"
household_validator.validate_previous_postcode(record)
expect(record.errors["postcode_full"])
.to include(match I18n.t("validations.household.postcode.discounted_ownership"))
expect(record.errors["ppostcode_full"])
.to include(match I18n.t("validations.household.postcode.discounted_ownership"))
end
it "allows same postcodes" do
record.postcode_full = "SO32 3PT"
record.ppostcode_full = "SO32 3PT"
household_validator.validate_previous_postcode(record)
expect(record.errors["postcode_full"]).to be_empty
expect(record.errors["ppostcode_full"]).to be_empty
end
it "does not add an error when postcode is missing" do
record.postcode_full = nil
record.ppostcode_full = "SO32 3PT"
household_validator.validate_previous_postcode(record)
expect(record.errors["postcode_full"]).to be_empty
expect(record.errors["ppostcode_full"]).to be_empty
end
it "does not add an error when previous postcode is missing" do
record.postcode_full = "SO32 3PT"
record.ppostcode_full = nil
household_validator.validate_previous_postcode(record)
expect(record.errors["postcode_full"]).to be_empty
expect(record.errors["ppostcode_full"]).to be_empty
end
end
context "without a discounted sale" do
before do
record.ownershipsch = 1
end
it "allows different postcodes" do
record.postcode_full = "SO32 3PT"
record.ppostcode_full = "DN6 7FB"
household_validator.validate_previous_postcode(record)
expect(record.errors["postcode_full"]).to be_empty
expect(record.errors["ppostcode_full"]).to be_empty
end
end
end
end

Loading…
Cancel
Save