Browse Source

Age validations

pull/297/head
baarkerlounger 3 years ago
parent
commit
a3e9b5acee
  1. 56
      spec/models/case_log_spec.rb
  2. 52
      spec/models/validations/household_validations_spec.rb

56
spec/models/case_log_spec.rb

@ -18,57 +18,6 @@ RSpec.describe CaseLog do
end
describe "#new" do
it "validates age is a number" do
expect {
described_class.create!(
age1: "random",
owning_organisation: owning_organisation,
managing_organisation: managing_organisation,
)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
described_class.create!(
age3: "random",
owning_organisation: owning_organisation,
managing_organisation: managing_organisation,
)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "validates age is under 120" do
expect {
described_class.create!(
age1: 121,
owning_organisation: owning_organisation,
managing_organisation: managing_organisation,
)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
described_class.create!(
age3: 121,
owning_organisation: owning_organisation,
managing_organisation: managing_organisation,
)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "validates age is over 0" do
expect {
described_class.create!(
age1: 0,
owning_organisation: owning_organisation,
managing_organisation: managing_organisation,
)
}.to raise_error(ActiveRecord::RecordInvalid)
expect {
described_class.create!(
age3: 0,
owning_organisation: owning_organisation,
managing_organisation: managing_organisation,
)
}.to raise_error(ActiveRecord::RecordInvalid)
end
context "when a reasonable preference is set to yes" do
it "validates that previously homeless should be selected" do
expect {
@ -768,6 +717,11 @@ RSpec.describe CaseLog do
case_log.update(age1: 25)
end
it "validates ages" do
expect(validator).to receive(:validate_person_1_age)
expect(validator).to receive(:validate_household_number_of_other_members)
end
it "validates bedroom number" do
expect(validator).to receive(:validate_shared_housing_rooms)
end

52
spec/models/validations/household_validations_spec.rb

@ -0,0 +1,52 @@
require "rails_helper"
RSpec.describe Validations::HouseholdValidations do
subject(:household_validator) { validator_class.new }
let(:validator_class) { Class.new { include Validations::HouseholdValidations } }
let(:record) { FactoryBot.create(:case_log) }
describe "age validations" do
it "validates that person 1's age is a number" do
record.age1 = "random"
household_validator.validate_person_1_age(record)
expect(record.errors["age1"])
.to include(match I18n.t("validations.household.age.must_be_valid", lower_bound: 16))
end
it "validates that other household member ages are a number" do
record.age3 = "random"
household_validator.validate_household_number_of_other_members(record)
expect(record.errors["age3"])
.to include(match I18n.t("validations.household.age.must_be_valid", lower_bound: 1))
end
it "validates that person 1's age is greater than 16" do
record.age1 = 15
household_validator.validate_person_1_age(record)
expect(record.errors["age1"])
.to include(match I18n.t("validations.household.age.must_be_valid", lower_bound: 16))
end
it "validates that other household member ages are greater than 1" do
record.age4 = 0
household_validator.validate_household_number_of_other_members(record)
expect(record.errors["age4"])
.to include(match I18n.t("validations.household.age.must_be_valid", lower_bound: 1))
end
it "validates that person 1's age is less than 121" do
record.age1 = 121
household_validator.validate_person_1_age(record)
expect(record.errors["age1"])
.to include(match I18n.t("validations.household.age.must_be_valid", lower_bound: 16))
end
it "validates that other household member ages are greater than 121" do
record.age4 = 123
household_validator.validate_household_number_of_other_members(record)
expect(record.errors["age4"])
.to include(match I18n.t("validations.household.age.must_be_valid", lower_bound: 1))
end
end
end
Loading…
Cancel
Save