Browse Source

Remove validation for 2024

pull/2207/head
Kat 2 years ago
parent
commit
8737650b12
  1. 9
      app/models/validations/sales/household_validations.rb
  2. 1
      app/models/validations/sales/property_validations.rb
  3. 58
      spec/models/validations/sales/household_validations_spec.rb
  4. 12
      spec/models/validations/sales/property_validations_spec.rb

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

@ -11,15 +11,6 @@ module Validations::Sales::HouseholdValidations
shared_validate_partner_count(record, 6) shared_validate_partner_count(record, 6)
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, :postcodes_not_matching, message: I18n.t("validations.household.postcode.discounted_ownership")
record.errors.add :ppostcode_full, :postcodes_not_matching, message: I18n.t("validations.household.postcode.discounted_ownership")
end
end
def validate_buyers_living_in_property(record) def validate_buyers_living_in_property(record)
return unless record.form.start_date.year >= 2023 return unless record.form.start_date.year >= 2023

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

@ -1,5 +1,6 @@
module Validations::Sales::PropertyValidations module Validations::Sales::PropertyValidations
def validate_postcodes_match_if_discounted_ownership(record) def validate_postcodes_match_if_discounted_ownership(record)
return unless record.saledate && !record.form.start_year_after_2024?
return unless record.ppostcode_full.present? && record.postcode_full.present? return unless record.ppostcode_full.present? && record.postcode_full.present?
if record.discounted_ownership_sale? && record.ppostcode_full != record.postcode_full if record.discounted_ownership_sale? && record.ppostcode_full != record.postcode_full

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

@ -154,64 +154,6 @@ RSpec.describe Validations::Sales::HouseholdValidations do
end 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
describe "validating fields about buyers living in the property" do describe "validating fields about buyers living in the property" do
let(:sales_log) { FactoryBot.create(:sales_log, :outright_sale_setup_complete, noint: 1, companybuy: 2, buylivein:, jointpur:, jointmore:, buy1livein:) } let(:sales_log) { FactoryBot.create(:sales_log, :outright_sale_setup_complete, noint: 1, companybuy: 2, buylivein:, jointpur:, jointmore:, buy1livein:) }

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

@ -19,7 +19,7 @@ RSpec.describe Validations::Sales::PropertyValidations do
end end
context "when ownership scheme is discounted ownership" do context "when ownership scheme is discounted ownership" do
let(:record) { build(:sales_log, ownershipsch: 2) } let(:record) { build(:sales_log, ownershipsch: 2, saledate: Time.zone.local(2023, 4, 5)) }
it "when ppostcode_full is not present no error is added" do it "when ppostcode_full is not present no error is added" do
record.postcode_full = "SW1A 1AA" record.postcode_full = "SW1A 1AA"
@ -54,6 +54,16 @@ RSpec.describe Validations::Sales::PropertyValidations do
expect(record.errors["ppostcode_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["ownershipsch"]).to include(match I18n.t("validations.property.postcode.must_match_previous"))
end end
it "does not add error for 2024 log" do
record.postcode_full = "SW1A 1AA"
record.ppostcode_full = "SW1A 0AA"
record.saledate = Time.zone.local(2024, 4, 5)
property_validator.validate_postcodes_match_if_discounted_ownership(record)
expect(record.errors["postcode_full"]).to be_empty
expect(record.errors["ppostcode_full"]).to be_empty
expect(record.errors["ownershipsch"]).to be_empty
end
end end
end end

Loading…
Cancel
Save