Browse Source

Remove another validation, update test names

pull/2256/head
Kat 2 years ago
parent
commit
5b795b12ce
  1. 8
      app/models/validations/sales/household_validations.rb
  2. 1
      config/locales/en.yml
  3. 4
      spec/models/validations/household_validations_spec.rb
  4. 50
      spec/models/validations/sales/household_validations_spec.rb

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

@ -107,14 +107,6 @@ module Validations::Sales::HouseholdValidations
end end
end end
def validate_buyer_2_not_child(record)
return unless record.form.start_year_after_2024?
if record.joint_purchase? && person_is_child?(record.relat2)
record.errors.add "relat2", I18n.t("validations.household.relat.buyer_is_a_child")
end
end
private private
def person_is_fulltime_student?(economic_status) def person_is_fulltime_student?(economic_status)

1
config/locales/en.yml

@ -496,7 +496,6 @@ en:
student_not_16_19: "Answer cannot be ‘child’ if the person is a student but not aged 16-19" student_not_16_19: "Answer cannot be ‘child’ if the person is a student but not aged 16-19"
16_19_not_student: "Answer cannot be ‘child’ if the person is aged 16-19 but not a student" 16_19_not_student: "Answer cannot be ‘child’ if the person is aged 16-19 but not a student"
child_over_19: "Answer cannot be child as you told us person %{person_num} is over 19" child_over_19: "Answer cannot be child as you told us person %{person_num} is over 19"
buyer_is_a_child: "Relationship cannot be child, as this person is a buyer"
housingneeds_a: housingneeds_a:
one_or_two_choices: "You can only select one option or ‘other disabled access needs’ plus ‘wheelchair-accessible housing’, ‘wheelchair access to essential rooms’ or ‘level access housing’" one_or_two_choices: "You can only select one option or ‘other disabled access needs’ plus ‘wheelchair-accessible housing’, ‘wheelchair access to essential rooms’ or ‘level access housing’"
housingneeds_type: housingneeds_type:

4
spec/models/validations/household_validations_spec.rb

@ -362,7 +362,7 @@ RSpec.describe Validations::HouseholdValidations do
Singleton.__init__(FormHandler) Singleton.__init__(FormHandler)
end end
it "validates person under 16 is not partner" do it "does not add an error is person under 16 is a partner" do
record.age2 = 14 record.age2 = 14
record.relat2 = "P" record.relat2 = "P"
household_validator.validate_person_age_matches_relationship(record) household_validator.validate_person_age_matches_relationship(record)
@ -370,7 +370,7 @@ RSpec.describe Validations::HouseholdValidations do
expect(record.errors["age2"]).to be_empty expect(record.errors["age2"]).to be_empty
end end
it "validates person over 19 is not child" do it "does not add an error if person over 19 is child" do
record.age2 = 20 record.age2 = 20
record.relat2 = "C" record.relat2 = "C"
household_validator.validate_person_age_matches_relationship(record) household_validator.validate_person_age_matches_relationship(record)

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

@ -75,7 +75,7 @@ RSpec.describe Validations::Sales::HouseholdValidations do
context "with 2024 logs" do context "with 2024 logs" do
let(:log_date) { Time.zone.local(2024, 4, 1) } let(:log_date) { Time.zone.local(2024, 4, 1) }
it "validates person under 16 is not partner" do it "does not add error if person under 16 is a partner" do
record.age2 = 14 record.age2 = 14
record.relat2 = "P" record.relat2 = "P"
household_validator.validate_person_age_matches_relationship(record) household_validator.validate_person_age_matches_relationship(record)
@ -83,7 +83,7 @@ RSpec.describe Validations::Sales::HouseholdValidations do
expect(record.errors["age2"]).to be_empty expect(record.errors["age2"]).to be_empty
end end
it "validates person over 19 is not child" do it "does not add error if person over 19 is a child" do
record.age2 = 20 record.age2 = 20
record.relat2 = "C" record.relat2 = "C"
household_validator.validate_person_age_matches_relationship(record) household_validator.validate_person_age_matches_relationship(record)
@ -192,7 +192,7 @@ RSpec.describe Validations::Sales::HouseholdValidations do
context "with 2024 logs" do context "with 2024 logs" do
let(:log_date) { Time.zone.local(2024, 4, 1) } let(:log_date) { Time.zone.local(2024, 4, 1) }
it "validates that child is at least 12 year younger than buyer" do it "does not validate that child is at least 12 year younger than buyer" do
record.age1 = 20 record.age1 = 20
record.age2 = 17 record.age2 = 17
record.relat2 = "C" record.relat2 = "C"
@ -201,15 +201,6 @@ RSpec.describe Validations::Sales::HouseholdValidations do
expect(record.errors["age2"]).to be_empty expect(record.errors["age2"]).to be_empty
expect(record.errors["relat2"]).to be_empty expect(record.errors["relat2"]).to be_empty
end end
it "expects that child is at least 12 years younger than buyer" do
record.age1 = 30
record.age2 = 17
record.relat2 = "C"
household_validator.validate_child_12_years_younger(record)
expect(record.errors["age2"]).to be_empty
expect(record.errors["relat2"]).to be_empty
end
end end
end end
@ -324,41 +315,6 @@ RSpec.describe Validations::Sales::HouseholdValidations do
end end
end end
describe "#validate_buyer_2_not_child" do
before do
Timecop.freeze(log_date)
Singleton.__init__(FormHandler)
end
after do
Timecop.return
Singleton.__init__(FormHandler)
end
context "with 2023 logs" do
let(:log_date) { Time.zone.local(2023, 4, 1) }
it "does not add an error if buyer 2 is a child" do
record.jointpur = 1
record.relat2 = "C"
household_validator.validate_buyer_2_not_child(record)
expect(record.errors["relat2"]).to be_empty
end
end
context "with 2024 logs" do
let(:log_date) { Time.zone.local(2024, 4, 1) }
it "validates buyer 2 isn't a child" do
record.jointpur = 1
record.relat2 = "C"
household_validator.validate_buyer_2_not_child(record)
expect(record.errors["relat2"])
.to include("Relationship cannot be child, as this person is a buyer")
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:) }

Loading…
Cancel
Save