diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 09b98f381..f4fa0b9cf 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -111,6 +111,7 @@ private next if record["person_#{n}_gender"].nil? || record["person_#{n}_age"].nil? count += 1 end + return count end end diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index c9339d719..111a69943 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -96,6 +96,36 @@ RSpec.describe Form, type: :model do }.to raise_error(ActiveRecord::RecordInvalid) 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) + }.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 end describe "status" do