From 8d6cd8354970e3c79330853614f64d4d5b63dc1d Mon Sep 17 00:00:00 2001 From: Nat Dean-Lewis <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Wed, 29 Apr 2026 12:26:44 +0100 Subject: [PATCH] CLDC-4269: Raise max hhmemb (#3332) * CLDC-4269: update hhmemb question * CLDC-4269: update counts in vars and validations * CLDC-4269: update depends_on for person_known and update tests * CLDC-4269: reformat * CLDC-4269: update spec * CLDC-4269: update spec * CLDC-4269: cleanup * CLDC-4269: cleanup * CLDC-4352: refactoring * CLDC-4269: move depends_on after person_index for safety * CLDC-4269: comment for not fully implemented const --- .../lettings_log_variables.rb | 2 +- .../form/lettings/pages/person_known.rb | 9 ++++- app/models/form/lettings/questions/hhmemb.rb | 2 +- app/models/lettings_log.rb | 3 +- app/models/log.rb | 8 +++++ app/models/sales_log.rb | 1 + .../validations/financial_validations.rb | 4 +-- app/models/validations/soft_validations.rb | 35 ++++++------------- .../lettings/household_characteristics.en.yml | 2 +- .../lettings/household_characteristics.en.yml | 2 +- .../form/lettings/pages/person_known_spec.rb | 29 +++++++-------- .../validations/household_validations_spec.rb | 12 +++---- 12 files changed, 53 insertions(+), 56 deletions(-) diff --git a/app/models/derived_variables/lettings_log_variables.rb b/app/models/derived_variables/lettings_log_variables.rb index abce99667..f0f4ff279 100644 --- a/app/models/derived_variables/lettings_log_variables.rb +++ b/app/models/derived_variables/lettings_log_variables.rb @@ -339,7 +339,7 @@ private def infer_only_partner!(partner_number) return unless hhmemb - (2..hhmemb).each do |i| + (2..people_with_details).each do |i| next if i == partner_number if ["P", nil].include?(public_send("relat#{i}")) diff --git a/app/models/form/lettings/pages/person_known.rb b/app/models/form/lettings/pages/person_known.rb index 6e699926d..db22da32e 100644 --- a/app/models/form/lettings/pages/person_known.rb +++ b/app/models/form/lettings/pages/person_known.rb @@ -2,11 +2,18 @@ class Form::Lettings::Pages::PersonKnown < ::Form::Page def initialize(id, hsh, subsection, person_index:) super(id, hsh, subsection) @id = "person_#{person_index}_known" - @depends_on = (person_index..8).map { |index| { "hhmemb" => index } } @person_index = person_index + @depends_on = depends_on end def questions @questions ||= [Form::Lettings::Questions::DetailsKnown.new(nil, nil, self, person_index: @person_index)] end + + def depends_on + [{ "hhmemb" => { + "operator" => ">=", + "operand" => @person_index, + } }] + end end diff --git a/app/models/form/lettings/questions/hhmemb.rb b/app/models/form/lettings/questions/hhmemb.rb index 614b2b27e..8aa071788 100644 --- a/app/models/form/lettings/questions/hhmemb.rb +++ b/app/models/form/lettings/questions/hhmemb.rb @@ -5,7 +5,7 @@ class Form::Lettings::Questions::Hhmemb < ::Form::Question @type = "numeric" @width = 2 @check_answers_card_number = 0 - @max = 8 + @max = 15 @min = 1 @step = 1 @question_number = get_question_number_from_hash(QUESTION_NUMBER_FROM_YEAR) diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 2e6b800eb..5a11da38a 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -191,6 +191,7 @@ class LettingsLog < Log NUM_OF_WEEKS_FROM_PERIOD = { 2 => 26, 3 => 13, 4 => 12, 5 => 50, 6 => 49, 7 => 48, 8 => 47, 9 => 46, 11 => 51, 1 => 52, 10 => 53 }.freeze SUFFIX_FROM_PERIOD = { 2 => "every 2 weeks", 3 => "every 4 weeks", 4 => "every month" }.freeze DUPLICATE_LOG_ATTRIBUTES = %w[owning_organisation_id tenancycode startdate age1_known age1 sex1 sexrab1 ecstat1 tcharge household_charge chcharge].freeze + MAX_PEOPLE_WITH_DETAILS = 8 # This is not yet used in all lettings validations etc. so check for other occurrences of this concept if updating this RENT_TYPE = { social_rent: 0, affordable_rent: 1, @@ -284,7 +285,7 @@ class LettingsLog < Log range = ALLOWED_INCOME_RANGES[ecstat1].clone if hhmemb > 1 - (2..hhmemb).each do |person_index| + (2..people_with_details).each do |person_index| ecstat = self["ecstat#{person_index}"] if ecstat.nil? diff --git a/app/models/log.rb b/app/models/log.rb index 5500991b6..abb652474 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -204,6 +204,14 @@ class Log < ApplicationRecord false end + def people_with_details + [hhmemb || max_people_with_details, max_people_with_details].min + end + + def max_people_with_details + self.class::MAX_PEOPLE_WITH_DETAILS + end + def ethnic_refused? ethnic_group == 17 end diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index 4d6e152a2..06f1c201b 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -104,6 +104,7 @@ class SalesLog < Log OPTIONAL_FIELDS = %w[purchid othtype buyers_organisations].freeze DUPLICATE_LOG_ATTRIBUTES = %w[owning_organisation_id purchid saledate age1_known age1 sex1 sexrab1 ecstat1 postcode_full uprn address_line1].freeze + MAX_PEOPLE_WITH_DETAILS = 6 # This is not yet used in all sales validations etc. so check for other occurrences of this concept if updating this def lettings? false diff --git a/app/models/validations/financial_validations.rb b/app/models/validations/financial_validations.rb index a5794a5e3..dd8029ebb 100644 --- a/app/models/validations/financial_validations.rb +++ b/app/models/validations/financial_validations.rb @@ -41,7 +41,7 @@ module Validations::FinancialValidations :over_hard_max, message: I18n.t("validations.lettings.financial.hhmemb.earnings_over_hard_max", earnings: format_as_currency(record.earnings), frequency:), ) - (1..record.hhmemb).each do |n| + (1..record.people_with_details).each do |n| record.errors.add( "ecstat#{n}", :over_hard_max, @@ -70,7 +70,7 @@ module Validations::FinancialValidations :under_hard_min, message: I18n.t("validations.lettings.financial.hhmemb.earnings_under_hard_min", earnings: format_as_currency(record.earnings), frequency:), ) - (1..record.hhmemb).each do |n| + (1..record.people_with_details).each do |n| record.errors.add( "ecstat#{n}", :under_hard_min, diff --git a/app/models/validations/soft_validations.rb b/app/models/validations/soft_validations.rb index 0ff08afb1..71ef99a4f 100644 --- a/app/models/validations/soft_validations.rb +++ b/app/models/validations/soft_validations.rb @@ -208,8 +208,7 @@ module Validations::SoftValidations def multiple_partners? return unless hhmemb - max_person_with_details = sales? ? [hhmemb, 6].min : [hhmemb, 8].min - (2..max_person_with_details).many? { |n| public_send("relat#{n}") == "P" } + (2..people_with_details).many? { |n| public_send("relat#{n}") == "P" } end def at_least_one_working_situation_is_sickness_and_household_sickness_is_no? @@ -219,22 +218,18 @@ module Validations::SoftValidations private def all_tenants_age_and_gender_information_completed? - return false if hhmemb.present? && hhmemb > 8 + return false if hhmemb.present? && hhmemb > max_people_with_details return false unless all_tenants_gender_information_completed? - person_count = hhmemb || 8 - - (1..person_count).all? do |n| + (1..people_with_details).all? do |n| public_send("age#{n}").present? && public_send("age#{n}_known").present? && public_send("age#{n}_known").zero? end end def all_tenants_gender_information_completed? - return false if hhmemb.present? && hhmemb > 8 - - person_count = hhmemb || 8 + return false if hhmemb.present? && hhmemb > max_people_with_details - (1..person_count).all? do |n| + (1..people_with_details).all? do |n| tenant_gender_information_completed?(n) end end @@ -258,27 +253,21 @@ private end def any_non_male_in_expected_pregnancy_age_range(min, max) - person_count = hhmemb || 8 - - (1..person_count).any? do |n| + (1..people_with_details).any? do |n| person_in_expected_pregnancy_age_range(n, min, max) && person_is_non_male(n) end end def non_males_in_the_household? - person_count = hhmemb || 8 - - (1..person_count).any? do |n| + (1..people_with_details).any? do |n| person_is_non_male(n) end end def all_male_tenants_in_the_household? - return false if hhmemb.present? && hhmemb > 8 + return false if hhmemb.present? && hhmemb > max_people_with_details - person_count = hhmemb || 8 - - (1..person_count).all? do |n| + (1..people_with_details).all? do |n| person_is_male(n) end end @@ -344,11 +333,7 @@ private end def at_least_one_person_working_situation_is_illness? - return if hhmemb.present? && hhmemb > 8 - - person_count = hhmemb || 8 - - (1..person_count).any? { |n| public_send("ecstat#{n}") == 8 } + (1..people_with_details).any? { |n| public_send("ecstat#{n}") == 8 } end def no_one_in_household_with_illness? diff --git a/config/locales/forms/2025/lettings/household_characteristics.en.yml b/config/locales/forms/2025/lettings/household_characteristics.en.yml index 432b0d08f..3ed45dcea 100644 --- a/config/locales/forms/2025/lettings/household_characteristics.en.yml +++ b/config/locales/forms/2025/lettings/household_characteristics.en.yml @@ -7,7 +7,7 @@ en: page_header: "" check_answer_label: "Number of household members" check_answer_prompt: "Enter total number of household members" - hint_text: "You can provide details for a maximum of 8 people." + hint_text: "You can answer up to 15 people. You will be asked to add details for a maximum of 8 people in the next questions." question_text: "How many people live in the household for this letting?" age1: diff --git a/config/locales/forms/2026/lettings/household_characteristics.en.yml b/config/locales/forms/2026/lettings/household_characteristics.en.yml index 84d7c5f33..bff084a3c 100644 --- a/config/locales/forms/2026/lettings/household_characteristics.en.yml +++ b/config/locales/forms/2026/lettings/household_characteristics.en.yml @@ -7,7 +7,7 @@ en: page_header: "" check_answer_label: "Number of household members" check_answer_prompt: "Enter total number of household members" - hint_text: "You can provide details for a maximum of 8 people." + hint_text: "You can answer up to 15 people. You will be asked to add details for a maximum of 8 people in the next questions." question_text: "How many people live in the household for this letting?" age1: diff --git a/spec/models/form/lettings/pages/person_known_spec.rb b/spec/models/form/lettings/pages/person_known_spec.rb index 7b77c5c0f..01616e5e0 100644 --- a/spec/models/form/lettings/pages/person_known_spec.rb +++ b/spec/models/form/lettings/pages/person_known_spec.rb @@ -26,15 +26,12 @@ RSpec.describe Form::Lettings::Pages::PersonKnown, type: :model do it "has correct depends_on" do expect(page.depends_on).to eq( - [ - { "hhmemb" => 2 }, - { "hhmemb" => 3 }, - { "hhmemb" => 4 }, - { "hhmemb" => 5 }, - { "hhmemb" => 6 }, - { "hhmemb" => 7 }, - { "hhmemb" => 8 }, - ], + [{ + "hhmemb" => { + "operator" => ">=", + "operand" => 2, + }, + }], ) end end @@ -52,14 +49,12 @@ RSpec.describe Form::Lettings::Pages::PersonKnown, type: :model do it "has correct depends_on" do expect(page.depends_on).to eq( - [ - { "hhmemb" => 3 }, - { "hhmemb" => 4 }, - { "hhmemb" => 5 }, - { "hhmemb" => 6 }, - { "hhmemb" => 7 }, - { "hhmemb" => 8 }, - ], + [{ + "hhmemb" => { + "operator" => ">=", + "operand" => 3, + }, + }], ) end end diff --git a/spec/models/validations/household_validations_spec.rb b/spec/models/validations/household_validations_spec.rb index 9848afd67..0f874dcc5 100644 --- a/spec/models/validations/household_validations_spec.rb +++ b/spec/models/validations/household_validations_spec.rb @@ -252,18 +252,18 @@ RSpec.describe Validations::HouseholdValidations do record.hhmemb = 0 household_validator.validate_numeric_min_max(record) expect(record.errors["hhmemb"]) - .to include(match I18n.t("validations.shared.numeric.within_range", field: "Number of household members", min: 1, max: 8)) + .to include(match I18n.t("validations.shared.numeric.within_range", field: "Number of household members", min: 1, max: 15)) end - it "validates that the number of household members cannot be more than 8" do - record.hhmemb = 9 + it "validates that the number of household members cannot be more than 15" do + record.hhmemb = 16 household_validator.validate_numeric_min_max(record) expect(record.errors["hhmemb"]) - .to include(match I18n.t("validations.shared.numeric.within_range", field: "Number of household members", min: 1, max: 8)) + .to include(match I18n.t("validations.shared.numeric.within_range", field: "Number of household members", min: 1, max: 15)) end - it "expects that the number of other household members is between the min and max" do - record.hhmemb = 5 + it "expects that the number of household members is between the min and max" do + record.hhmemb = 11 household_validator.validate_numeric_min_max(record) expect(record.errors["hhmemb"]).to be_empty end