|
|
|
|
@ -4,14 +4,13 @@ RSpec.describe Validations::Sales::HouseholdValidations do
|
|
|
|
|
subject(:household_validator) { validator_class.new } |
|
|
|
|
|
|
|
|
|
let(:validator_class) { Class.new { include Validations::Sales::HouseholdValidations } } |
|
|
|
|
let(:record) { build(:sales_log) } |
|
|
|
|
|
|
|
|
|
describe "household member validations" do |
|
|
|
|
let(:record) { build(:sales_log) } |
|
|
|
|
|
|
|
|
|
describe "#validate_partner_count" do |
|
|
|
|
it "validates that only 1 partner exists" do |
|
|
|
|
record.relat2 = "P" |
|
|
|
|
record.relat3 = "P" |
|
|
|
|
household_validator.validate_household_number_of_other_members(record) |
|
|
|
|
household_validator.validate_partner_count(record) |
|
|
|
|
expect(record.errors["relat2"]) |
|
|
|
|
.to include(match I18n.t("validations.household.relat.one_partner")) |
|
|
|
|
expect(record.errors["relat3"]) |
|
|
|
|
@ -22,15 +21,17 @@ RSpec.describe Validations::Sales::HouseholdValidations do
|
|
|
|
|
|
|
|
|
|
it "expects that a tenant can have a partner" do |
|
|
|
|
record.relat3 = "P" |
|
|
|
|
household_validator.validate_household_number_of_other_members(record) |
|
|
|
|
household_validator.validate_partner_count(record) |
|
|
|
|
expect(record.errors["base"]).to be_empty |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "#validate_person_age_matches_relationship" do |
|
|
|
|
context "when the household contains a person under 16" do |
|
|
|
|
it "expects that person is a child of the tenant" do |
|
|
|
|
record.age2 = 14 |
|
|
|
|
record.relat2 = "C" |
|
|
|
|
household_validator.validate_household_number_of_other_members(record) |
|
|
|
|
household_validator.validate_person_age_matches_relationship(record) |
|
|
|
|
expect(record.errors["relat2"]).to be_empty |
|
|
|
|
expect(record.errors["age2"]).to be_empty |
|
|
|
|
end |
|
|
|
|
@ -38,80 +39,86 @@ RSpec.describe Validations::Sales::HouseholdValidations do
|
|
|
|
|
it "validates that a person under 16 must not be a partner of the buyer" do |
|
|
|
|
record.age2 = 14 |
|
|
|
|
record.relat2 = "P" |
|
|
|
|
household_validator.validate_household_number_of_other_members(record) |
|
|
|
|
household_validator.validate_person_age_matches_relationship(record) |
|
|
|
|
expect(record.errors["relat2"]) |
|
|
|
|
.to include(match I18n.t("validations.household.relat.child_under_16_sales", person_num: 2)) |
|
|
|
|
expect(record.errors["age2"]) |
|
|
|
|
.to include(match I18n.t("validations.household.age.child_under_16_relat_sales", person_num: 2)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "validates that person's economic status must be Child" do |
|
|
|
|
record.age2 = 14 |
|
|
|
|
record.ecstat2 = 1 |
|
|
|
|
household_validator.validate_household_number_of_other_members(record) |
|
|
|
|
expect(record.errors["ecstat2"]) |
|
|
|
|
.to include(match I18n.t("validations.household.ecstat.child_under_16", person_num: 2)) |
|
|
|
|
expect(record.errors["age2"]) |
|
|
|
|
.to include(match I18n.t("validations.household.age.child_under_16_ecstat", person_num: 2)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "expects that person's economic status is Child" do |
|
|
|
|
record.age2 = 14 |
|
|
|
|
record.ecstat2 = 9 |
|
|
|
|
household_validator.validate_household_number_of_other_members(record) |
|
|
|
|
expect(record.errors["ecstat2"]).to be_empty |
|
|
|
|
expect(record.errors["age2"]).to be_empty |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "validates that a person with economic status 'child' must be under 16" do |
|
|
|
|
record.age2 = 21 |
|
|
|
|
record.ecstat2 = 9 |
|
|
|
|
household_validator.validate_household_number_of_other_members(record) |
|
|
|
|
expect(record.errors["ecstat2"]) |
|
|
|
|
.to include(match I18n.t("validations.household.ecstat.child_over_16", person_num: 2)) |
|
|
|
|
expect(record.errors["age2"]) |
|
|
|
|
.to include(match I18n.t("validations.household.age.child_over_16", person_num: 2)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "validates the child is at least 12 years younger than buyer 1" do |
|
|
|
|
record.age1 = 30 |
|
|
|
|
record.age2 = record.age1 - 11 |
|
|
|
|
record.relat2 = "C" |
|
|
|
|
household_validator.validate_household_number_of_other_members(record) |
|
|
|
|
expect(record.errors["age1"]) |
|
|
|
|
.to include(match I18n.t("validations.household.age.child_12_years_younger", person_num: 2)) |
|
|
|
|
expect(record.errors["age2"]) |
|
|
|
|
.to include(match I18n.t("validations.household.age.child_12_years_younger", person_num: 2)) |
|
|
|
|
expect(record.errors["relat2"]) |
|
|
|
|
.to include(match I18n.t("validations.household.age.child_12_years_younger", person_num: 2)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "expects the child is at least 12 years younger than buyer 1" do |
|
|
|
|
record.age1 = 30 |
|
|
|
|
record.age2 = record.age1 - 12 |
|
|
|
|
record.relat2 = "C" |
|
|
|
|
household_validator.validate_household_number_of_other_members(record) |
|
|
|
|
expect(record.errors["age1"]).to be_empty |
|
|
|
|
expect(record.errors["age2"]).to be_empty |
|
|
|
|
expect(record.errors["relate2"]).to be_empty |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "validates that a person over 20 must not be a child of the buyer" do |
|
|
|
|
record.age2 = 21 |
|
|
|
|
record.relat2 = "C" |
|
|
|
|
household_validator.validate_household_number_of_other_members(record) |
|
|
|
|
household_validator.validate_person_age_matches_relationship(record) |
|
|
|
|
expect(record.errors["relat2"]) |
|
|
|
|
.to include(match I18n.t("validations.household.relat.child_over_20")) |
|
|
|
|
expect(record.errors["age2"]) |
|
|
|
|
.to include(match I18n.t("validations.household.age.child_over_20")) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "#validate_person_age_matches_economic_status" do |
|
|
|
|
it "validates that person's economic status must be Child" do |
|
|
|
|
record.age2 = 14 |
|
|
|
|
record.ecstat2 = 1 |
|
|
|
|
household_validator.validate_person_age_matches_economic_status(record) |
|
|
|
|
expect(record.errors["ecstat2"]) |
|
|
|
|
.to include(match I18n.t("validations.household.ecstat.child_under_16", person_num: 2)) |
|
|
|
|
expect(record.errors["age2"]) |
|
|
|
|
.to include(match I18n.t("validations.household.age.child_under_16_ecstat", person_num: 2)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "expects that person's economic status is Child" do |
|
|
|
|
record.age2 = 14 |
|
|
|
|
record.ecstat2 = 9 |
|
|
|
|
household_validator.validate_person_age_matches_economic_status(record) |
|
|
|
|
expect(record.errors["ecstat2"]).to be_empty |
|
|
|
|
expect(record.errors["age2"]).to be_empty |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "validates that a person with economic status 'child' must be under 16" do |
|
|
|
|
record.age2 = 21 |
|
|
|
|
record.ecstat2 = 9 |
|
|
|
|
household_validator.validate_person_age_matches_economic_status(record) |
|
|
|
|
expect(record.errors["ecstat2"]) |
|
|
|
|
.to include(match I18n.t("validations.household.ecstat.child_over_16", person_num: 2)) |
|
|
|
|
expect(record.errors["age2"]) |
|
|
|
|
.to include(match I18n.t("validations.household.age.child_over_16", person_num: 2)) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "#validate_child_12_years_younger" do |
|
|
|
|
it "validates the child is at least 12 years younger than buyer 1" do |
|
|
|
|
record.age1 = 30 |
|
|
|
|
record.age2 = record.age1 - 11 |
|
|
|
|
record.relat2 = "C" |
|
|
|
|
household_validator.validate_child_12_years_younger(record) |
|
|
|
|
expect(record.errors["age1"]) |
|
|
|
|
.to include(match I18n.t("validations.household.age.child_12_years_younger", person_num: 2)) |
|
|
|
|
expect(record.errors["age2"]) |
|
|
|
|
.to include(match I18n.t("validations.household.age.child_12_years_younger", person_num: 2)) |
|
|
|
|
expect(record.errors["relat2"]) |
|
|
|
|
.to include(match I18n.t("validations.household.age.child_12_years_younger", person_num: 2)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "expects the child is at least 12 years younger than buyer 1" do |
|
|
|
|
record.age1 = 30 |
|
|
|
|
record.age2 = record.age1 - 12 |
|
|
|
|
record.relat2 = "C" |
|
|
|
|
household_validator.validate_child_12_years_younger(record) |
|
|
|
|
expect(record.errors["age1"]).to be_empty |
|
|
|
|
expect(record.errors["age2"]).to be_empty |
|
|
|
|
expect(record.errors["relate2"]).to be_empty |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "#validate_person_age_and_relationship_matches_economic_status" do |
|
|
|
|
it "does not add an error for a person aged 16-19 who is a student but not a child of the buyer" do |
|
|
|
|
record.age2 = 18 |
|
|
|
|
record.ecstat2 = "7" |
|
|
|
|
record.relat2 = "P" |
|
|
|
|
household_validator.validate_household_number_of_other_members(record) |
|
|
|
|
household_validator.validate_person_age_and_relationship_matches_economic_status(record) |
|
|
|
|
expect(record.errors["relat2"]).to be_empty |
|
|
|
|
expect(record.errors["ecstat2"]).to be_empty |
|
|
|
|
expect(record.errors["age2"]).to be_empty |
|
|
|
|
@ -121,7 +128,7 @@ RSpec.describe Validations::Sales::HouseholdValidations do
|
|
|
|
|
record.age2 = 20 |
|
|
|
|
record.ecstat2 = "7" |
|
|
|
|
record.relat2 = "P" |
|
|
|
|
household_validator.validate_household_number_of_other_members(record) |
|
|
|
|
household_validator.validate_person_age_and_relationship_matches_economic_status(record) |
|
|
|
|
expect(record.errors["relat2"]).to be_empty |
|
|
|
|
expect(record.errors["ecstat2"]).to be_empty |
|
|
|
|
expect(record.errors["age2"]).to be_empty |
|
|
|
|
@ -131,7 +138,7 @@ RSpec.describe Validations::Sales::HouseholdValidations do
|
|
|
|
|
record.age2 = 17 |
|
|
|
|
record.ecstat2 = "1" |
|
|
|
|
record.relat2 = "C" |
|
|
|
|
household_validator.validate_household_number_of_other_members(record) |
|
|
|
|
household_validator.validate_person_age_and_relationship_matches_economic_status(record) |
|
|
|
|
expect(record.errors["relat2"]) |
|
|
|
|
.to include(match I18n.t("validations.household.relat.student_16_19.cannot_be_child.16_19_not_student")) |
|
|
|
|
expect(record.errors["age2"]) |
|
|
|
|
@ -144,7 +151,7 @@ RSpec.describe Validations::Sales::HouseholdValidations do
|
|
|
|
|
record.age2 = 14 |
|
|
|
|
record.ecstat2 = "7" |
|
|
|
|
record.relat2 = "C" |
|
|
|
|
household_validator.validate_household_number_of_other_members(record) |
|
|
|
|
household_validator.validate_person_age_and_relationship_matches_economic_status(record) |
|
|
|
|
expect(record.errors["relat2"]) |
|
|
|
|
.to include(match I18n.t("validations.household.relat.student_16_19.cannot_be_child.student_not_16_19")) |
|
|
|
|
expect(record.errors["age2"]) |
|
|
|
|
|