Browse Source

Merge pull request #70 from communitiesuk/CLDC-497-SharedAccomodationBedrooms

Cldc 497 shared accomodation bedrooms
pull/74/head^2
Milo 3 years ago committed by GitHub
parent
commit
f52f498f2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      app/validations/household_validations.rb
  2. 39
      spec/models/case_log_spec.rb

20
app/validations/household_validations.rb

@ -56,6 +56,26 @@ module HouseholdValidations
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
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
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
it "must be anwered if answered yes to outstanding rent or charges" do
expect {

Loading…
Cancel
Save