From 894228c02e455d7b21ade57a6690c75c133352bb Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Thu, 11 Nov 2021 15:50:05 +0000 Subject: [PATCH] CLDC-678: Store total household members (#86) * Store other housdehold members and infer total household members * Remove redundant question --- app/admin/case_logs.rb | 2 +- app/models/case_log.rb | 8 +++++++- app/validations/household_validations.rb | 2 +- config/forms/2021_2022.json | 16 ++-------------- .../20211111143319_add_other_members_column.rb | 7 +++++++ db/schema.rb | 3 ++- docs/api/DLUHC-CORE-Data.v1.json | 6 +++--- spec/features/case_log_spec.rb | 4 ++-- spec/fixtures/complete_case_log.json | 3 ++- spec/fixtures/forms/test_form.json | 2 +- spec/helpers/check_answers_helper_spec.rb | 2 +- spec/models/case_log_spec.rb | 4 ++-- 12 files changed, 31 insertions(+), 28 deletions(-) create mode 100644 db/migrate/20211111143319_add_other_members_column.rb diff --git a/app/admin/case_logs.rb b/app/admin/case_logs.rb index f32cff52b..2a15fbb2a 100644 --- a/app/admin/case_logs.rb +++ b/app/admin/case_logs.rb @@ -2,7 +2,7 @@ ActiveAdmin.register CaseLog do # See permitted parameters documentation: # https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters permit_params do - permitted = %i[status tenant_code age1 sex1 tenant_ethnic_group tenant_nationality previous_housing_situation armed_forces ecstat1 hhmemb relat2 age2 sex2 ecstat2 relat3 age3 sex3 ecstat3 relat4 age4 sex4 ecstat4 relat5 age5 sex5 ecstat5 relat6 age6 sex6 ecstat6 relat7 age7 person_7_gender ecstat7 relat8 age8 sex8 ecstat8 homelessness reason benefit_cap_spare_room_subsidy armed_forces_active armed_forces_injured armed_forces_partner medical_conditions pregnancy accessibility_requirements condition_effects tenancy_code tenancy_start_date starter_tenancy fixed_term_tenancy tenancy_type letting_type letting_provider la previous_postcode property_relet property_vacancy_reason property_reference property_unit_type property_building_type property_number_of_bedrooms property_void_date majorrepairs mrcdate property_number_of_times_relet property_wheelchair_accessible net_income net_income_frequency net_income_uc_proportion hb rent_frequency basic_rent service_charge personal_service_charge support_charge total_charge tshortfall time_lived_in_la time_on_la_waiting_list prevloc property_postcode reasonable_preference reasonable_preference_reason cbl_letting chr_letting cap_letting hbrentshortfall other_reason accessibility_requirements_fully_wheelchair_accessible_housing accessibility_requirements_wheelchair_access_to_essential_rooms accessibility_requirements_level_access_housing accessibility_requirements_other_disability_requirements accessibility_requirements_no_disability_requirements accessibility_requirements_do_not_know accessibility_requirements_prefer_not_to_say condition_effects_vision condition_effects_hearing condition_effects_mobility condition_effects_dexterity condition_effects_stamina condition_effects_learning condition_effects_memory condition_effects_mental_health condition_effects_social_or_behavioral condition_effects_other condition_effects_prefer_not_to_say reasonable_preference_reason_homeless reasonable_preference_reason_unsatisfactory_housing reasonable_preference_reason_medical_grounds reasonable_preference_reason_avoid_hardship reasonable_preference_reason_do_not_know other_tenancy_type override_net_income_validation net_income_known] + permitted = %i[status tenant_code age1 sex1 tenant_ethnic_group tenant_nationality previous_housing_situation armed_forces ecstat1 other_hhmemb relat2 age2 sex2 ecstat2 relat3 age3 sex3 ecstat3 relat4 age4 sex4 ecstat4 relat5 age5 sex5 ecstat5 relat6 age6 sex6 ecstat6 relat7 age7 person_7_gender ecstat7 relat8 age8 sex8 ecstat8 homelessness reason benefit_cap_spare_room_subsidy armed_forces_active armed_forces_injured armed_forces_partner medical_conditions pregnancy accessibility_requirements condition_effects tenancy_code tenancy_start_date starter_tenancy fixed_term_tenancy tenancy_type letting_type letting_provider la previous_postcode property_relet property_vacancy_reason property_reference property_unit_type property_building_type property_number_of_bedrooms property_void_date majorrepairs mrcdate property_number_of_times_relet property_wheelchair_accessible net_income net_income_frequency net_income_uc_proportion hb rent_frequency basic_rent service_charge personal_service_charge support_charge total_charge tshortfall time_lived_in_la time_on_la_waiting_list prevloc property_postcode reasonable_preference reasonable_preference_reason cbl_letting chr_letting cap_letting hbrentshortfall other_reason accessibility_requirements_fully_wheelchair_accessible_housing accessibility_requirements_wheelchair_access_to_essential_rooms accessibility_requirements_level_access_housing accessibility_requirements_other_disability_requirements accessibility_requirements_no_disability_requirements accessibility_requirements_do_not_know accessibility_requirements_prefer_not_to_say condition_effects_vision condition_effects_hearing condition_effects_mobility condition_effects_dexterity condition_effects_stamina condition_effects_learning condition_effects_memory condition_effects_mental_health condition_effects_social_or_behavioral condition_effects_other condition_effects_prefer_not_to_say reasonable_preference_reason_homeless reasonable_preference_reason_unsatisfactory_housing reasonable_preference_reason_medical_grounds reasonable_preference_reason_avoid_hardship reasonable_preference_reason_do_not_know other_tenancy_type override_net_income_validation net_income_known] permitted end diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 4d59ea91a..f21b3338d 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -163,6 +163,12 @@ class CaseLog < ApplicationRecord end end + def hhmemb + if other_hhmemb.present? + other_hhmemb + end + end + def applicable_income_range return unless ecstat1 @@ -239,7 +245,7 @@ private dynamically_not_required << "incfreq" end - start_range = (hhmemb || 0) + 2 + start_range = (other_hhmemb || 0) + 2 (start_range..8).each do |n| dynamically_not_required << "age#{n}" dynamically_not_required << "sex#{n}" diff --git a/app/validations/household_validations.rb b/app/validations/household_validations.rb index b36972667..d3536ae8a 100644 --- a/app/validations/household_validations.rb +++ b/app/validations/household_validations.rb @@ -80,7 +80,7 @@ module HouseholdValidations record.errors.add :unittype_gn, "A bedsit can only have one bedroom" end - if !record.hhmemb.nil? && record.hhmemb.positive? && (record.unittype_gn.include?("Shared") && !record.beds.to_i.between?(1, 7)) + if !record.other_hhmemb.nil? && record.other_hhmemb.positive? && (record.unittype_gn.include?("Shared") && !record.beds.to_i.between?(1, 7)) record.errors.add :unittype_gn, "A shared house must have 1 to 7 bedrooms" end diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 5606f956e..5d06b8bd3 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -104,7 +104,7 @@ "header": "About this log", "description": "", "questions": { - "tenancy_start_date": { + "startdate": { "check_answer_label": "When is the tenancy start date?", "header": "What is the tenancy start date?", "hint_text": "For example, 27 3 2007", @@ -332,7 +332,7 @@ "header": "", "description": "", "questions": { - "hhmemb": { + "other_hhmemb": { "check_answer_label": "Number of Other Household Members", "header": "How many other people are there in the household?", "hint_text": "The maximum number of others is 7", @@ -1027,18 +1027,6 @@ } } }, - "tenancy_start_date": { - "header": "", - "description": "", - "questions": { - "startdate": { - "check_answer_label": "When is the tenancy start date?", - "header": "What is the tenancy start date?", - "hint_text": "For example, 27 3 2007", - "type": "date" - } - } - }, "starter_tenancy": { "header": "", "description": "", diff --git a/db/migrate/20211111143319_add_other_members_column.rb b/db/migrate/20211111143319_add_other_members_column.rb new file mode 100644 index 000000000..2c6ca2658 --- /dev/null +++ b/db/migrate/20211111143319_add_other_members_column.rb @@ -0,0 +1,7 @@ +class AddOtherMembersColumn < ActiveRecord::Migration[6.1] + def change + change_table :case_logs, bulk: true do |t| + t.column :other_hhmemb, :integer + end + end +end diff --git a/db/schema.rb b/db/schema.rb index ba9b956dd..5b1c02e62 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_11_10_140928) do +ActiveRecord::Schema.define(version: 2021_11_11_143319) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -152,6 +152,7 @@ ActiveRecord::Schema.define(version: 2021_11_10_140928) do t.integer "mrcday" t.integer "mrcmonth" t.integer "mrcyear" + t.integer "other_hhmemb" t.index ["discarded_at"], name: "index_case_logs_on_discarded_at" end diff --git a/docs/api/DLUHC-CORE-Data.v1.json b/docs/api/DLUHC-CORE-Data.v1.json index e13ad4f17..17560d14c 100644 --- a/docs/api/DLUHC-CORE-Data.v1.json +++ b/docs/api/DLUHC-CORE-Data.v1.json @@ -263,7 +263,7 @@ "prevten": "Private sector tenancy", "armed_forces": "Yes - a regular", "ecstat1": "Full-time - 30 hours or more", - "hhmemb": 7, + "other_hhmemb": 7, "relat2": "Partner", "age2": 32, "sex2": "Male", @@ -459,7 +459,7 @@ "Prefer not to say" ] }, - "hhmemb": { + "other_hhmemb": { "type": "number", "minimum": 0, "maximum": 7 @@ -1052,7 +1052,7 @@ "prevten", "armed_forces", "ecstat1", - "hhmemb", + "other_hhmemb", "relat2", "age2", "sex2", diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb index aa53b8c7d..b48572d62 100644 --- a/spec/features/case_log_spec.rb +++ b/spec/features/case_log_spec.rb @@ -9,7 +9,7 @@ RSpec.describe "Test Features" do tenant_code: { type: "text", answer: "BZ737", path: "tenant_code" }, age1: { type: "numeric", answer: 25, path: "person_1_age" }, sex1: { type: "radio", answer: "Female", path: "person_1_gender" }, - hhmemb: { type: "numeric", answer: 2, path: "household_number_of_other_members" }, + other_hhmemb: { type: "numeric", answer: 2, path: "household_number_of_other_members" }, } def fill_in_number_question(case_log_id, question, value, path) @@ -265,7 +265,7 @@ RSpec.describe "Test Features" do let(:last_question_for_subsection) { "household_number_of_other_members" } it "redirects to the check answers page when answering the last question and clicking save and continue" do - fill_in_number_question(id, "hhmemb", 0, last_question_for_subsection) + fill_in_number_question(id, "other_hhmemb", 0, last_question_for_subsection) expect(page).to have_current_path("/case_logs/#{id}/#{subsection}/check_answers") end diff --git a/spec/fixtures/complete_case_log.json b/spec/fixtures/complete_case_log.json index 97afaeaa0..4656a04f8 100644 --- a/spec/fixtures/complete_case_log.json +++ b/spec/fixtures/complete_case_log.json @@ -8,7 +8,8 @@ "prevten": "Private sector tenancy", "armed_forces": "Yes - a regular", "ecstat1": "Full-time - 30 hours or more", - "hhmemb": 7, + "other_hhmemb": 7, + "hhmemb": 8, "relat2": "Partner", "age2": 32, "sex2": "Male", diff --git a/spec/fixtures/forms/test_form.json b/spec/fixtures/forms/test_form.json index 95ac050da..988d2176e 100644 --- a/spec/fixtures/forms/test_form.json +++ b/spec/fixtures/forms/test_form.json @@ -45,7 +45,7 @@ }, "household_number_of_other_members": { "questions": { - "hhmemb": { + "other_hhmemb": { "check_answer_label": "Number of Other Household Members", "header": "How many other people are there in the household?", "hint_text": "The maximum number of others is 1", diff --git a/spec/helpers/check_answers_helper_spec.rb b/spec/helpers/check_answers_helper_spec.rb index 7ad04f081..ac3000f6b 100644 --- a/spec/helpers/check_answers_helper_spec.rb +++ b/spec/helpers/check_answers_helper_spec.rb @@ -6,7 +6,7 @@ RSpec.describe CheckAnswersHelper do FactoryBot.create( :case_log, :in_progress, - hhmemb: 1, + other_hhmemb: 1, relat2: "Partner", ) end diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 438bf3c55..e663937db 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -109,7 +109,7 @@ RSpec.describe Form, type: :model do expect { CaseLog.create!(unittype_gn: "Shared bungalow", beds: 8, - hhmemb: 1) + other_hhmemb: 1) }.to raise_error(ActiveRecord::RecordInvalid) end @@ -117,7 +117,7 @@ RSpec.describe Form, type: :model do expect { CaseLog.create!(unittype_gn: "Shared bungalow", beds: 4, - hhmemb: 0) + other_hhmemb: 0) }.to raise_error(ActiveRecord::RecordInvalid) end