diff --git a/app/models/case_log.rb b/app/models/case_log.rb index ae6e06fb6..672ea89ae 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -68,6 +68,7 @@ class CaseLog < ApplicationRecord enum housingneeds_f: POLAR, _suffix: true enum housingneeds_g: POLAR, _suffix: true enum housingneeds_h: POLAR, _suffix: true + enum accessibility_requirements_prefer_not_to_say: POLAR, _suffix: true enum illness_type_1: POLAR, _suffix: true enum illness_type_2: POLAR, _suffix: true enum illness_type_3: POLAR, _suffix: true diff --git a/app/models/constants/case_log.rb b/app/models/constants/case_log.rb index c503ec1b3..3a537035d 100644 --- a/app/models/constants/case_log.rb +++ b/app/models/constants/case_log.rb @@ -65,7 +65,7 @@ module Constants::CaseLog ILLNESS = { "Yes" => 1, "No" => 2, - "Do not know" => 3, + "Prefer not to say" => 3, }.freeze LEFTREG = { diff --git a/app/models/validations/household_validations.rb b/app/models/validations/household_validations.rb index ba29953e7..dc4e9acf2 100644 --- a/app/models/validations/household_validations.rb +++ b/app/models/validations/household_validations.rb @@ -74,6 +74,16 @@ module Validations::HouseholdValidations validate_person_age_matches_economic_status(record, 1) end + def validate_accessibility_requirements(record) + all_options = [record.housingneeds_a, record.housingneeds_b, record.housingneeds_c, record.housingneeds_f, record.housingneeds_g, record.housingneeds_h, record.accessibility_requirements_prefer_not_to_say] + if all_options.count("Yes") > 1 + mobility_accessibility_options = [record.housingneeds_a, record.housingneeds_b, record.housingneeds_c] + unless all_options.count("Yes") == 2 && record.housingneeds_f == "Yes" && mobility_accessibility_options.any? { |x| x == "Yes" } + record.errors.add :housingneeds_a, "Only one box must be ticked or 'other disabilities' plus one of mobility disabilities" + end + end + end + def validate_shared_housing_rooms(record) unless record.unittype_gn.nil? if record.unittype_gn == "Bed-sit" && record.beds != 1 && record.beds.present? diff --git a/spec/features/form/saving_data_spec.rb b/spec/features/form/saving_data_spec.rb index ab7b03643..f419a3438 100644 --- a/spec/features/form/saving_data_spec.rb +++ b/spec/features/form/saving_data_spec.rb @@ -17,7 +17,6 @@ RSpec.describe "Form Saving Data" do FactoryBot.create( :case_log, :in_progress, housingneeds_a: "Yes", - housingneeds_c: "Yes", owning_organisation: user.organisation, managing_organisation: user.organisation ) @@ -93,9 +92,5 @@ RSpec.describe "Form Saving Data" do "case-log-accessibility-requirements-housingneeds-b-field", visible: false, ) - expect(page).to have_checked_field( - "case-log-accessibility-requirements-housingneeds-c-field", - visible: false, - ) end end diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index ed39fcb1f..b2d9e5820 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -826,6 +826,61 @@ RSpec.describe Form, type: :model do }.not_to raise_error end end + + context "For accessibility requirements" do + it "validates that only one option can be selected" do + expect { + CaseLog.create!(housingneeds_a: "Yes", + housingneeds_b: "Yes", + rent_type: "London Affordable rent", + owning_organisation: owning_organisation, + managing_organisation: managing_organisation) + }.to raise_error(ActiveRecord::RecordInvalid) + end + + it "validates that only one option a, b, or c can be selected in conjunction with f" do + expect { + CaseLog.create!(housingneeds_a: "Yes", + housingneeds_f: "Yes", + rent_type: "London Affordable rent", + owning_organisation: owning_organisation, + managing_organisation: managing_organisation) + }.to_not raise_error + + expect { + CaseLog.create!(housingneeds_b: "Yes", + housingneeds_f: "Yes", + rent_type: "London Affordable rent", + owning_organisation: owning_organisation, + managing_organisation: managing_organisation) + }.to_not raise_error + + expect { + CaseLog.create!(housingneeds_c: "Yes", + housingneeds_f: "Yes", + rent_type: "London Affordable rent", + owning_organisation: owning_organisation, + managing_organisation: managing_organisation) + }.to_not raise_error + + expect { + CaseLog.create!(housingneeds_g: "Yes", + housingneeds_f: "Yes", + rent_type: "London Affordable rent", + owning_organisation: owning_organisation, + managing_organisation: managing_organisation) + }.to raise_error(ActiveRecord::RecordInvalid) + + expect { + CaseLog.create!(housingneeds_a: "Yes", + housingneeds_b: "Yes", + housingneeds_f: "Yes", + rent_type: "London Affordable rent", + owning_organisation: owning_organisation, + managing_organisation: managing_organisation) + }.to raise_error(ActiveRecord::RecordInvalid) + end + end end describe "status" do diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index b8f889cb9..ee9115184 100644 --- a/spec/requests/form_controller_spec.rb +++ b/spec/requests/form_controller_spec.rb @@ -135,9 +135,7 @@ RSpec.describe FormController, type: :request do case_log: { page: "accessibility_requirements", accessibility_requirements: - %w[ housingneeds_a - housingneeds_b - housingneeds_c], + %w[housingneeds_b], }, } end @@ -156,16 +154,13 @@ RSpec.describe FormController, type: :request do post "/logs/#{case_log.id}/form", params: case_log_form_params case_log.reload - expect(case_log.housingneeds_a).to eq("Yes") expect(case_log.housingneeds_b).to eq("Yes") - expect(case_log.housingneeds_c).to eq("Yes") end it "sets previously submitted items to false when resubmitted with new values" do post "/logs/#{case_log.id}/form", params: new_case_log_form_params case_log.reload - expect(case_log.housingneeds_a).to eq("No") expect(case_log.housingneeds_b).to eq("No") expect(case_log.housingneeds_c).to eq("Yes") end @@ -179,8 +174,7 @@ RSpec.describe FormController, type: :request do page: "accessibility_requirements", accessibility_requirements: %w[ housingneeds_a - housingneeds_b - housingneeds_c], + housingneeds_f], tenant_code: tenant_code, }, } @@ -213,8 +207,7 @@ RSpec.describe FormController, type: :request do case_log.reload expect(case_log.housingneeds_a).to eq("Yes") - expect(case_log.housingneeds_b).to eq("Yes") - expect(case_log.housingneeds_c).to eq("Yes") + expect(case_log.housingneeds_f).to eq("Yes") expect(case_log.tenant_code).to eq(tenant_code) end end