Browse Source

Merge branch 'main' into CLDC-467/validate_other_household_members

pull/74/head
Matthew Phelan 3 years ago
parent
commit
4a4ffd90f2
  1. 20
      app/validations/household_validations.rb
  2. 39
      spec/models/case_log_spec.rb

20
app/validations/household_validations.rb

@ -73,6 +73,26 @@ module HouseholdValidations
validate_person_age_matches_economic_status(record, 1) validate_person_age_matches_economic_status(record, 1)
end end
def validate_shared_housing_rooms(record)
unless record.property_unit_type.nil?
if record.property_unit_type == "Bed-sit" && record.property_number_of_bedrooms != 1
record.errors.add :property_unit_type, "A bedsit can only have one bedroom"
end
unless record.household_number_of_other_members.nil?
if record.household_number_of_other_members > 0
if record.property_unit_type.include?("Shared") && !record.property_number_of_bedrooms.to_i.between?(1, 7)
record.errors.add :property_unit_type, "A shared house must have 1 to 7 bedrooms"
end
end
end
if record.property_unit_type.include?("Shared") && !record.property_number_of_bedrooms.to_i.between?(1, 3)
record.errors.add :property_unit_type, "A shared house with less than two tenants must have 1 to 3 bedrooms"
end
end
end
private private
def women_of_child_bearing_age_in_household(record) def women_of_child_bearing_age_in_household(record)

39
spec/models/case_log_spec.rb

@ -97,6 +97,45 @@ RSpec.describe Form, type: :model do
end end
end end
context "Shared accomodation bedrooms validation" do
it "you must have more than zero bedrooms" do
expect {
CaseLog.create!(property_unit_type: "Shared house",
property_number_of_bedrooms: 0)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "you must answer less than 8 bedrooms" do
expect {
CaseLog.create!(property_unit_type: "Shared bungalow",
property_number_of_bedrooms: 8,
household_number_of_other_members: 1)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "you must answer less than 8 bedrooms" do
expect {
CaseLog.create!(property_unit_type: "Shared bungalow",
property_number_of_bedrooms: 4,
household_number_of_other_members: 0)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "A bedsit must only have one room" do
expect {
CaseLog.create!(property_unit_type: "Bed-sit",
property_number_of_bedrooms: 2)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "A bedsit must only have one room" do
expect {
CaseLog.create!(property_unit_type: "Bed-sit",
property_number_of_bedrooms: 0)
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
context "outstanding rent or charges validation" do context "outstanding rent or charges validation" do
it "must be anwered if answered yes to outstanding rent or charges" do it "must be anwered if answered yes to outstanding rent or charges" do
expect { expect {

Loading…
Cancel
Save