Browse Source

Merge branch 'main' into CLDC-4029-add-additional-user-filters

CLDC-4029-add-additional-user-filters
Samuel Young 2 weeks ago committed by GitHub
parent
commit
8bf40757cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 12
      app/helpers/collection_time_helper.rb
  2. 19
      app/models/derived_variables/lettings_log_variables.rb
  3. 18
      app/models/form/lettings/pages/person_lead_partner.rb
  4. 4
      app/models/form/lettings/questions/person_partner.rb
  5. 49
      app/models/form/lettings/subsections/household_characteristics.rb
  6. 8
      app/models/lettings_log.rb
  7. 13
      app/models/scheme.rb
  8. 8
      app/views/schemes/details.html.erb
  9. 8
      app/views/schemes/new.html.erb
  10. 16
      config/locales/forms/2026/lettings/household_characteristics.en.yml
  11. 9
      config/locales/forms/2026/lettings/soft_validations.en.yml
  12. 14
      config/locales/forms/2026/sales/household_characteristics.en.yml
  13. 5
      db/schema.rb
  14. 4
      lib/tasks/update_scheme_registered_under_care_value.rake
  15. 16
      spec/features/accessibility_spec.rb
  16. 2
      spec/features/schemes_helpers.rb
  17. 4
      spec/features/schemes_spec.rb
  18. 6
      spec/fixtures/files/lettings_log_csv_export_codes_26.csv
  19. 6
      spec/fixtures/files/lettings_log_csv_export_labels_26.csv
  20. 6
      spec/fixtures/files/lettings_log_csv_export_non_support_codes_26.csv
  21. 6
      spec/fixtures/files/lettings_log_csv_export_non_support_labels_26.csv
  22. 10
      spec/fixtures/files/original_schemes.csv
  23. 4
      spec/fixtures/files/updated_schemes.csv
  24. 3
      spec/helpers/check_answers_helper_spec.rb
  25. 16
      spec/helpers/collection_time_helper_spec.rb
  26. 76
      spec/helpers/filters_helper_spec.rb
  27. 1
      spec/helpers/locations_helper_spec.rb
  28. 21
      spec/lib/tasks/count_duplicates_spec.rb
  29. 6
      spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb
  30. 57
      spec/models/form/lettings/pages/person_lead_partner_spec.rb
  31. 62
      spec/models/form/lettings/questions/person_partner_spec.rb
  32. 76
      spec/models/form/lettings/subsections/household_characteristics_spec.rb
  33. 220
      spec/models/lettings_log_derived_fields_spec.rb
  34. 17
      spec/services/merge/merge_organisations_service_spec.rb

12
app/helpers/collection_time_helper.rb

@ -4,6 +4,10 @@ module CollectionTimeHelper
date < window_end_date ? date.year - 1 : date.year
end
def collection_start_date_for_year(year)
Time.zone.local(year, 4, 1)
end
def current_collection_start_year
collection_start_year_for_date(Time.zone.now)
end
@ -50,6 +54,10 @@ module CollectionTimeHelper
current_collection_start_year - 1
end
def previous_collection_end_year
current_collection_end_year - 1
end
def previous_collection_start_date
current_collection_start_date - 1.year
end
@ -58,6 +66,10 @@ module CollectionTimeHelper
current_collection_start_year - 2
end
def archived_collection_end_year
current_collection_end_year - 2
end
def previous_collection_new_logs_end_date
FormHandler.instance.lettings_form_for_start_year(previous_collection_start_year).new_logs_end_date
end

19
app/models/derived_variables/lettings_log_variables.rb

@ -75,7 +75,7 @@ module DerivedVariables::LettingsLogVariables
self.beds = nil
end
clear_child_ecstat_for_age_changes!
clear_child_constraints_for_age_changes!
child_under_16_constraints!
self.hhtype = household_type
@ -246,9 +246,14 @@ private
end
def get_totchild
if form.start_year_2025_or_later?
ages = [age1, age2, age3, age4, age5, age6, age7, age8]
ages.count { |x| !x.nil? && x < 16 }
else
relationships = [relat2, relat3, relat4, relat5, relat6, relat7, relat8]
relationships.count("C")
end
end
def get_totadult
total = !age1.nil? && age1 >= 16 && age1 < 60 ? 1 : 0
@ -269,15 +274,19 @@ private
(2..8).each do |idx|
if age_under_16?(idx)
self["ecstat#{idx}"] = 9
self["relat#{idx}"] = "X" if form.start_year_2026_or_later?
end
end
end
def clear_child_ecstat_for_age_changes!
def clear_child_constraints_for_age_changes!
(2..8).each do |idx|
if public_send("age#{idx}_changed?") && self["ecstat#{idx}"] == 9
self["ecstat#{idx}"] = nil
end
next unless public_send("age#{idx}_changed?")
self["ecstat#{idx}"] = nil if self["ecstat#{idx}"] == 9
# since the user can also input 'No' for relat there are cases when we don't want to clear this (changing age from 50 to 55 for example)
# note if age is changed from 10 to 15 we will clear it but the inference will set it back immediately after, see child_under_16_constraints!
self["relat#{idx}"] = nil if self["relat#{idx}"] == "X" && age_changed_from_below_16(idx) && form.start_year_2026_or_later?
end
end

18
app/models/form/lettings/pages/person_lead_partner.rb

@ -2,11 +2,27 @@ class Form::Lettings::Pages::PersonLeadPartner < ::Form::Page
def initialize(id, hsh, subsection, person_index:)
super(id, hsh, subsection)
@id = "person_#{person_index}_lead_partner"
@depends_on = [{ "details_known_#{person_index}" => 0 }]
@person_index = person_index
end
def questions
@questions ||= [Form::Lettings::Questions::PersonPartner.new(nil, nil, self, person_index: @person_index)]
end
def depends_on
if form.start_year_2026_or_later?
[
{
"details_known_#{@person_index}" => 0,
"age#{@person_index}" => {
"operator" => ">=",
"operand" => 16,
},
},
{ "details_known_#{@person_index}" => 0, "age#{@person_index}" => nil },
]
else
[{ "details_known_#{@person_index}" => 0 }]
end
end
end

4
app/models/form/lettings/questions/person_partner.rb

@ -27,4 +27,8 @@ class Form::Lettings::Questions::PersonPartner < ::Form::Question
base_question_number + (4 * @person_index)
end
def derived?(log)
form.start_year_2026_or_later? && log.is_partner_inferred?(@person_index)
end
end

49
app/models/form/lettings/subsections/household_characteristics.rb

@ -32,17 +32,18 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::LeadTenantUnderRetirementValueCheck.new("working_situation_lead_tenant_under_retirement_value_check", nil, self),
Form::Lettings::Pages::LeadTenantOverRetirementValueCheck.new("working_situation_lead_tenant_over_retirement_value_check", nil, self),
Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 2),
(Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 2) if form.start_year_2026_or_later?),
relationship_question(person_index: 2),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_2_partner_under_16_value_check", nil, self, person_index: 2) if form.start_year_2024_or_later?),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_2_partner_under_16_value_check", nil, self, person_index: 2) if form.start_year_2024_or_later? && !form.start_year_2026_or_later?),
(Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_2_multiple_partners_value_check", nil, self, person_index: 2) if form.start_year_2024_or_later?),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 2),
(Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 2) unless form.start_year_2026_or_later?),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 2),
Form::Lettings::Pages::FemalesInSoftAgeRangeInPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 2),
Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("age_2_under_retirement_value_check", nil, self, person_index: 2),
Form::Lettings::Pages::PersonOverRetirementValueCheck.new("age_2_over_retirement_value_check", nil, self, person_index: 2),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("age_2_partner_under_16_value_check", nil, self, person_index: 2) if form.start_year_2024_or_later?),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("age_2_partner_under_16_value_check", nil, self, person_index: 2) if form.start_year_2024_or_later? && !form.start_year_2026_or_later?),
Form::Lettings::Pages::PersonGenderIdentity.new(nil, nil, self, person_index: 2),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonValueCheck.new(nil, nil, self, person_index: 2),
Form::Lettings::Pages::FemalesInSoftAgeRangeInPregnantHouseholdPersonValueCheck.new(nil, nil, self,
@ -52,17 +53,18 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_2_under_retirement_value_check", nil, self, person_index: 2),
Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_2_over_retirement_value_check", nil, self, person_index: 2),
Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 3),
(Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 3) if form.start_year_2026_or_later?),
relationship_question(person_index: 3),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_3_partner_under_16_value_check", nil, self, person_index: 3) if form.start_year_2024_or_later?),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_3_partner_under_16_value_check", nil, self, person_index: 3) if form.start_year_2024_or_later? && !form.start_year_2026_or_later?),
(Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_3_multiple_partners_value_check", nil, self, person_index: 3) if form.start_year_2024_or_later?),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 3),
(Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 3) unless form.start_year_2026_or_later?),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 3),
Form::Lettings::Pages::FemalesInSoftAgeRangeInPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 3),
Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("age_3_under_retirement_value_check", nil, self, person_index: 3),
Form::Lettings::Pages::PersonOverRetirementValueCheck.new("age_3_over_retirement_value_check", nil, self, person_index: 3),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("age_3_partner_under_16_value_check", nil, self, person_index: 3) if form.start_year_2024_or_later?),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("age_3_partner_under_16_value_check", nil, self, person_index: 3) if form.start_year_2024_or_later? && !form.start_year_2026_or_later?),
Form::Lettings::Pages::PersonGenderIdentity.new(nil, nil, self, person_index: 3),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonValueCheck.new(nil, nil, self, person_index: 3),
Form::Lettings::Pages::FemalesInSoftAgeRangeInPregnantHouseholdPersonValueCheck.new(nil, nil, self,
@ -72,17 +74,18 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_3_under_retirement_value_check", nil, self, person_index: 3),
Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_3_over_retirement_value_check", nil, self, person_index: 3),
Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 4),
(Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 4) if form.start_year_2026_or_later?),
relationship_question(person_index: 4),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_4_partner_under_16_value_check", nil, self, person_index: 4) if form.start_year_2024_or_later?),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_4_partner_under_16_value_check", nil, self, person_index: 4) if form.start_year_2024_or_later? && !form.start_year_2026_or_later?),
(Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_4_multiple_partners_value_check", nil, self, person_index: 4) if form.start_year_2024_or_later?),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 4),
(Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 4) unless form.start_year_2026_or_later?),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 4),
Form::Lettings::Pages::FemalesInSoftAgeRangeInPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 4),
Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("age_4_under_retirement_value_check", nil, self, person_index: 4),
Form::Lettings::Pages::PersonOverRetirementValueCheck.new("age_4_over_retirement_value_check", nil, self, person_index: 4),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("age_4_partner_under_16_value_check", nil, self, person_index: 4) if form.start_year_2024_or_later?),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("age_4_partner_under_16_value_check", nil, self, person_index: 4) if form.start_year_2024_or_later? && !form.start_year_2026_or_later?),
Form::Lettings::Pages::PersonGenderIdentity.new(nil, nil, self, person_index: 4),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonValueCheck.new(nil, nil, self, person_index: 4),
Form::Lettings::Pages::FemalesInSoftAgeRangeInPregnantHouseholdPersonValueCheck.new(nil, nil, self,
@ -92,17 +95,18 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_4_under_retirement_value_check", nil, self, person_index: 4),
Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_4_over_retirement_value_check", nil, self, person_index: 4),
Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 5),
(Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 5) if form.start_year_2026_or_later?),
relationship_question(person_index: 5),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_5_partner_under_16_value_check", nil, self, person_index: 5) if form.start_year_2024_or_later?),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_5_partner_under_16_value_check", nil, self, person_index: 5) if form.start_year_2024_or_later? && !form.start_year_2026_or_later?),
(Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_5_multiple_partners_value_check", nil, self, person_index: 5) if form.start_year_2024_or_later?),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 5),
(Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 5) unless form.start_year_2026_or_later?),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 5),
Form::Lettings::Pages::FemalesInSoftAgeRangeInPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 5),
Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("age_5_under_retirement_value_check", nil, self, person_index: 5),
Form::Lettings::Pages::PersonOverRetirementValueCheck.new("age_5_over_retirement_value_check", nil, self, person_index: 5),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("age_5_partner_under_16_value_check", nil, self, person_index: 5) if form.start_year_2024_or_later?),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("age_5_partner_under_16_value_check", nil, self, person_index: 5) if form.start_year_2024_or_later? && !form.start_year_2026_or_later?),
Form::Lettings::Pages::PersonGenderIdentity.new(nil, nil, self, person_index: 5),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonValueCheck.new(nil, nil, self, person_index: 5),
Form::Lettings::Pages::FemalesInSoftAgeRangeInPregnantHouseholdPersonValueCheck.new(nil, nil, self,
@ -112,17 +116,18 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_5_under_retirement_value_check", nil, self, person_index: 5),
Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_5_over_retirement_value_check", nil, self, person_index: 5),
Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 6),
(Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 6) if form.start_year_2026_or_later?),
relationship_question(person_index: 6),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_6_partner_under_16_value_check", nil, self, person_index: 6) if form.start_year_2024_or_later?),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_6_partner_under_16_value_check", nil, self, person_index: 6) if form.start_year_2024_or_later? && !form.start_year_2026_or_later?),
(Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_6_multiple_partners_value_check", nil, self, person_index: 6) if form.start_year_2024_or_later?),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 6),
(Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 6) unless form.start_year_2026_or_later?),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 6),
Form::Lettings::Pages::FemalesInSoftAgeRangeInPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 6),
Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("age_6_under_retirement_value_check", nil, self, person_index: 6),
Form::Lettings::Pages::PersonOverRetirementValueCheck.new("age_6_over_retirement_value_check", nil, self, person_index: 6),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("age_6_partner_under_16_value_check", nil, self, person_index: 6) if form.start_year_2024_or_later?),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("age_6_partner_under_16_value_check", nil, self, person_index: 6) if form.start_year_2024_or_later? && !form.start_year_2026_or_later?),
Form::Lettings::Pages::PersonGenderIdentity.new(nil, nil, self, person_index: 6),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonValueCheck.new(nil, nil, self, person_index: 6),
Form::Lettings::Pages::FemalesInSoftAgeRangeInPregnantHouseholdPersonValueCheck.new(nil, nil, self,
@ -132,17 +137,18 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_6_under_retirement_value_check", nil, self, person_index: 6),
Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_6_over_retirement_value_check", nil, self, person_index: 6),
Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 7),
(Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 7) if form.start_year_2026_or_later?),
relationship_question(person_index: 7),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_7_partner_under_16_value_check", nil, self, person_index: 7) if form.start_year_2024_or_later?),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_7_partner_under_16_value_check", nil, self, person_index: 7) if form.start_year_2024_or_later? && !form.start_year_2026_or_later?),
(Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_7_multiple_partners_value_check", nil, self, person_index: 7) if form.start_year_2024_or_later?),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 7),
(Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 7) unless form.start_year_2026_or_later?),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 7),
Form::Lettings::Pages::FemalesInSoftAgeRangeInPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 7),
Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("age_7_under_retirement_value_check", nil, self, person_index: 7),
Form::Lettings::Pages::PersonOverRetirementValueCheck.new("age_7_over_retirement_value_check", nil, self, person_index: 7),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("age_7_partner_under_16_value_check", nil, self, person_index: 7) if form.start_year_2024_or_later?),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("age_7_partner_under_16_value_check", nil, self, person_index: 7) if form.start_year_2024_or_later? && !form.start_year_2026_or_later?),
Form::Lettings::Pages::PersonGenderIdentity.new(nil, nil, self, person_index: 7),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonValueCheck.new(nil, nil, self, person_index: 7),
Form::Lettings::Pages::FemalesInSoftAgeRangeInPregnantHouseholdPersonValueCheck.new(nil, nil, self,
@ -152,17 +158,18 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("working_situation_7_under_retirement_value_check", nil, self, person_index: 7),
Form::Lettings::Pages::PersonOverRetirementValueCheck.new("working_situation_7_over_retirement_value_check", nil, self, person_index: 7),
Form::Lettings::Pages::PersonKnown.new(nil, nil, self, person_index: 8),
(Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 8) if form.start_year_2026_or_later?),
relationship_question(person_index: 8),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_8_partner_under_16_value_check", nil, self, person_index: 8) if form.start_year_2024_or_later?),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("relationship_8_partner_under_16_value_check", nil, self, person_index: 8) if form.start_year_2024_or_later? && !form.start_year_2026_or_later?),
(Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_8_multiple_partners_value_check", nil, self, person_index: 8) if form.start_year_2024_or_later?),
Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 8),
(Form::Lettings::Pages::PersonAge.new(nil, nil, self, person_index: 8) unless form.start_year_2026_or_later?),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 8),
Form::Lettings::Pages::FemalesInSoftAgeRangeInPregnantHouseholdPersonAgeValueCheck.new(nil, nil, self,
person_index: 8),
Form::Lettings::Pages::PersonUnderRetirementValueCheck.new("age_8_under_retirement_value_check", nil, self, person_index: 8),
Form::Lettings::Pages::PersonOverRetirementValueCheck.new("age_8_over_retirement_value_check", nil, self, person_index: 8),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("age_8_partner_under_16_value_check", nil, self, person_index: 8) if form.start_year_2024_or_later?),
(Form::Lettings::Pages::PartnerUnder16ValueCheck.new("age_8_partner_under_16_value_check", nil, self, person_index: 8) if form.start_year_2024_or_later? && !form.start_year_2026_or_later?),
Form::Lettings::Pages::PersonGenderIdentity.new(nil, nil, self, person_index: 8),
Form::Lettings::Pages::NoFemalesPregnantHouseholdPersonValueCheck.new(nil, nil, self, person_index: 8),
Form::Lettings::Pages::FemalesInSoftAgeRangeInPregnantHouseholdPersonValueCheck.new(nil, nil, self,

8
app/models/lettings_log.rb

@ -403,6 +403,14 @@ class LettingsLog < Log
unittype_gn_changed? && unittype_gn_was == 2
end
def is_partner_inferred?(person_index)
public_send("age#{person_index}") && public_send("age#{person_index}") < 16
end
def age_changed_from_below_16(person_index)
public_send("age#{person_index}_was") && public_send("age#{person_index}_was") < 16
end
def is_shared_housing?
# 4: Shared flat or maisonette
# 9: Shared house

13
app/models/scheme.rb

@ -148,9 +148,8 @@ class Scheme < ApplicationRecord
enum :sensitive, SENSITIVE, suffix: true
REGISTERED_UNDER_CARE_ACT = {
"Yes – registered care home providing nursing care": 4,
"Yes – registered care home providing personal care": 3,
"Yes – part registered as a care home": 2,
"Yes": 5,
"Partially - some but not all units in the scheme are regulated by the CQC": 2,
"No": 1,
}.freeze
@ -251,7 +250,7 @@ class Scheme < ApplicationRecord
{ name: "Status", value: status, id: "status" },
{ name: "Confidential information", value: sensitive, id: "sensitive", edit: true },
{ name: "Type of scheme", value: scheme_type, id: "scheme_type", edit: true },
{ name: "Registered under Care Standards Act 2000", value: registered_under_care_act, id: "registered_under_care_act", edit: true },
{ name: "Regulated by the Care Quality Commission", value: registered_under_care_act, id: "registered_under_care_act", edit: true },
{ name: "Housing stock owned by", value: owning_organisation.name, id: "owning_organisation_id", edit: true },
{ name: "Support services provided by", value: arrangement_type, id: "arrangement_type", edit: true },
{ name: "Primary client group", value: primary_client_group, id: "primary_client_group", edit: true },
@ -262,10 +261,8 @@ class Scheme < ApplicationRecord
]
end
def care_acts_options_with_hints
hints = { "Yes – part registered as a care home": "A proportion of units are registered as being a care home." }
Scheme.registered_under_care_acts.keys.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize, description: hints[key.to_sym]) }
def self.care_acts_options
Scheme.registered_under_care_acts.keys.map { |key, _| OpenStruct.new(id: key, name: key.to_s) }
end
def support_level_options_with_hints

8
app/views/schemes/details.html.erb

@ -38,16 +38,12 @@
:name,
legend: { text: "What is this type of scheme?", size: "m" } %>
<% care_acts_options_hints = { "Yes – part registered as a care home": "A proportion of units are registered as being a care home." } %>
<% care_acts_options_with_hints = Scheme.registered_under_care_acts.keys.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize, description: care_acts_options_hints[key.to_sym]) } %>
<%= f.govuk_collection_radio_buttons :registered_under_care_act,
care_acts_options_with_hints,
Scheme.care_acts_options,
:id,
:name,
:description,
legend: { text: "Is this scheme registered under the Care Standards Act 2000?", size: "m" } %>
legend: { text: "Is the scheme regulated by the Care Quality Commission (CQC)?", size: "m" } %>
<% scheme_owning_organisation_options = owning_organisation_options(current_user) %>

8
app/views/schemes/new.html.erb

@ -33,16 +33,12 @@
:name,
legend: { text: "What is this type of scheme?", size: "m" } %>
<% care_acts_options_hints = { "Yes – part registered as a care home": "A proportion of units are registered as being a care home." } %>
<% care_acts_options_with_hints = Scheme.registered_under_care_acts.keys.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize, description: care_acts_options_hints[key.to_sym]) } %>
<%= f.govuk_collection_radio_buttons :registered_under_care_act,
care_acts_options_with_hints,
Scheme.care_acts_options,
:id,
:name,
:description,
legend: { text: "Is this scheme registered under the Care Standards Act 2000?", size: "m" } %>
legend: { text: "Is the scheme regulated by the Care Quality Commission (CQC)?", size: "m" } %>
<% if current_user.data_coordinator? && current_user.organisation.stock_owners.count.zero? && !current_user.organisation.has_recent_absorbed_organisations? %>
<%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %>

16
config/locales/forms/2026/lettings/household_characteristics.en.yml

@ -86,7 +86,7 @@ en:
page_header: ""
check_answer_label: "Lead tenant’s working situation"
check_answer_prompt: ""
hint_text: ""
hint_text: "This is the household member who does the most paid work. If several people do the same amount of paid work, it's the oldest household member. People providing informal care for family and friends who are not in formal employment (but may receive carer's allowance) should answer 'Not seeking work'."
question_text: "Which of these best describes the lead tenant’s working situation?"
details_known_2:
@ -127,7 +127,7 @@ en:
page_header: ""
check_answer_label: "Person 2’s working situation"
check_answer_prompt: ""
hint_text: ""
hint_text: "People providing informal care for family and friends who are not in formal employment (but may receive carer's allowance) should answer 'Not seeking work'."
question_text: "Which of these best describes person 2’s working situation?"
details_known_3:
@ -168,7 +168,7 @@ en:
page_header: ""
check_answer_label: "Person 3’s working situation"
check_answer_prompt: ""
hint_text: ""
hint_text: "People providing informal care for family and friends who are not in formal employment (but may receive carer's allowance) should answer 'Not seeking work'."
question_text: "Which of these best describes person 3’s working situation?"
details_known_4:
@ -209,7 +209,7 @@ en:
page_header: ""
check_answer_label: "Person 4’s working situation"
check_answer_prompt: ""
hint_text: ""
hint_text: "People providing informal care for family and friends who are not in formal employment (but may receive carer's allowance) should answer 'Not seeking work'."
question_text: "Which of these best describes person 4’s working situation?"
details_known_5:
@ -250,7 +250,7 @@ en:
page_header: ""
check_answer_label: "Person 5’s working situation"
check_answer_prompt: ""
hint_text: ""
hint_text: "People providing informal care for family and friends who are not in formal employment (but may receive carer's allowance) should answer 'Not seeking work'."
question_text: "Which of these best describes person 5’s working situation?"
details_known_6:
@ -291,7 +291,7 @@ en:
page_header: ""
check_answer_label: "Person 6’s working situation"
check_answer_prompt: ""
hint_text: ""
hint_text: "People providing informal care for family and friends who are not in formal employment (but may receive carer's allowance) should answer 'Not seeking work'."
question_text: "Which of these best describes person 6’s working situation?"
details_known_7:
@ -332,7 +332,7 @@ en:
page_header: ""
check_answer_label: "Person 7’s working situation"
check_answer_prompt: ""
hint_text: ""
hint_text: "People providing informal care for family and friends who are not in formal employment (but may receive carer's allowance) should answer 'Not seeking work'."
question_text: "Which of these best describes person 7’s working situation?"
details_known_8:
@ -373,5 +373,5 @@ en:
page_header: ""
check_answer_label: "Person 8’s working situation"
check_answer_prompt: ""
hint_text: ""
hint_text: "People providing informal care for family and friends who are not in formal employment (but may receive carer's allowance) should answer 'Not seeking work'."
question_text: "Which of these best describes person 8’s working situation?"

9
config/locales/forms/2026/lettings/soft_validations.en.yml

@ -39,15 +39,6 @@ en:
title_text: "You told us this person is over 66 and not retired."
informative_text: "Are you sure this person isn’t retired?"
partner_under_16_value_check:
page_header: ""
check_answer_label: "Partner under 16 confirmation"
check_answer_prompt: "Confirm partner’s age"
hint_text: ""
question_text: "Are you sure this is correct?"
title_text: "You told us this person is aged %{age} years and has 'Partner' relationship to the lead tenant."
informative_text: "Are you sure this is correct?"
multiple_partners_value_check:
page_header: ""
check_answer_label: "Multiple partners confirmation"

14
config/locales/forms/2026/sales/household_characteristics.en.yml

@ -80,7 +80,7 @@ en:
page_header: ""
check_answer_label: "Buyer 1’s working situation"
check_answer_prompt: ""
hint_text: ""
hint_text: "This is the household member who does the most paid work. If several people do the same amount of paid work, it's the oldest household member. People providing informal care for family and friends who are not in formal employment (but may receive carer's allowance) should answer 'Not seeking work'."
question_text: "Which of these best describes buyer 1’s working situation?"
buy1livein:
@ -202,13 +202,13 @@ en:
page_header: ""
check_answer_label: "Buyer 2’s working situation"
check_answer_prompt: ""
hint_text: ""
hint_text: "People providing informal care for family and friends who are not in formal employment (but may receive carer's allowance) should answer 'Not seeking work'."
question_text: "Which of these best describes buyer 2’s working situation?"
person:
page_header: ""
check_answer_label: "Person 2’s working situation"
check_answer_prompt: ""
hint_text: ""
hint_text: "People providing informal care for family and friends who are not in formal employment (but may receive carer's allowance) should answer 'Not seeking work'."
question_text: "Which of these best describes person 2’s working situation?"
buy2livein:
@ -277,7 +277,7 @@ en:
page_header: ""
check_answer_label: "Person 3’s working situation"
check_answer_prompt: ""
hint_text: ""
hint_text: "People providing informal care for family and friends who are not in formal employment (but may receive carer's allowance) should answer 'Not seeking work'."
question_text: "Which of these best describes person 3’s working situation?"
details_known_4:
@ -318,7 +318,7 @@ en:
page_header: ""
check_answer_label: "Person 4’s working situation"
check_answer_prompt: ""
hint_text: ""
hint_text: "People providing informal care for family and friends who are not in formal employment (but may receive carer's allowance) should answer 'Not seeking work'."
question_text: "Which of these best describes person 4’s working situation?"
details_known_5:
@ -359,7 +359,7 @@ en:
page_header: ""
check_answer_label: "Person 5’s working situation"
check_answer_prompt: ""
hint_text: ""
hint_text: "People providing informal care for family and friends who are not in formal employment (but may receive carer's allowance) should answer 'Not seeking work'."
question_text: "Which of these best describes person 5’s working situation?"
details_known_6:
@ -400,5 +400,5 @@ en:
page_header: ""
check_answer_label: "Person 6’s working situation"
check_answer_prompt: ""
hint_text: ""
hint_text: "People providing informal care for family and friends who are not in formal employment (but may receive carer's allowance) should answer 'Not seeking work'."
question_text: "Which of these best describes person 6’s working situation?"

5
db/schema.rb

@ -373,8 +373,8 @@ ActiveRecord::Schema[7.2].define(version: 2025_04_16_111741) do
t.integer "partner_under_16_value_check"
t.integer "multiple_partners_value_check"
t.bigint "created_by_id"
t.integer "referral_type"
t.boolean "manual_address_entry_selected", default: false
t.integer "referral_type"
t.index ["assigned_to_id"], name: "index_lettings_logs_on_assigned_to_id"
t.index ["bulk_upload_id"], name: "index_lettings_logs_on_bulk_upload_id"
t.index ["created_by_id"], name: "index_lettings_logs_on_created_by_id"
@ -504,7 +504,7 @@ ActiveRecord::Schema[7.2].define(version: 2025_04_16_111741) do
t.date "discarded_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["organisation_id", "startdate"], name: "index_org_name_changes_on_org_id_and_startdate", unique: true
t.index ["organisation_id", "startdate", "discarded_at"], name: "index_org_name_changes_on_org_id_startdate_discarded_at", unique: true
t.index ["organisation_id"], name: "index_organisation_name_changes_on_organisation_id"
end
@ -894,6 +894,7 @@ ActiveRecord::Schema[7.2].define(version: 2025_04_16_111741) do
add_foreign_key "local_authority_links", "local_authorities"
add_foreign_key "local_authority_links", "local_authorities", column: "linked_local_authority_id"
add_foreign_key "locations", "schemes"
add_foreign_key "organisation_name_changes", "organisations"
add_foreign_key "organisation_relationships", "organisations", column: "child_organisation_id"
add_foreign_key "organisation_relationships", "organisations", column: "parent_organisation_id"
add_foreign_key "organisations", "organisations", column: "absorbing_organisation_id"

4
lib/tasks/update_scheme_registered_under_care_value.rake

@ -0,0 +1,4 @@
desc "Alter registered under care act values for schemes in the database to 5 if they are 3 or 4, as these options are being deprecated"
task update_scheme_registered_under_care_value: :environment do
Scheme.where(registered_under_care_act: [3, 4]).update_all(registered_under_care_act: 5)
end

16
spec/features/accessibility_spec.rb

@ -21,6 +21,22 @@ RSpec.describe "Accessibility", js: true do
end
before do
# see https://github.com/dequelabs/axe-core-gems/issues/386#issuecomment-2135927504 for why this is needed
# axe-core will normally use 1 second page load timeout.
# see https://github.com/dequelabs/axe-core-gems/blob/87632f5e8e947214f10e35b57ea5e2c327f20612/packages/axe-core-api/lib/axe/api/run.rb#L36
# this causes timeout errors for slower pages
# so we override the page load timeout to 10 seconds for feature specs
# this is for the a11y tests, we can only scope to feature specs
page.driver.browser.manage.timeouts.instance_eval do
def page_load=(*)
# no-op don't want axe-core changing this
end
def page_load
10 # seconds
end
end
allow(Storage::S3Service).to receive(:new).and_return(storage_service)
allow(storage_service).to receive(:configuration).and_return(OpenStruct.new(bucket_name: "core-test-collection-resources"))
allow(user).to receive(:need_two_factor_authentication?).and_return(false)

2
spec/features/schemes_helpers.rb

@ -29,7 +29,7 @@ module SchemesHelpers
fill_in "Scheme name", with: "FooBar"
check "This scheme contains confidential information"
choose "Direct access hostel"
choose "Yes – registered care home providing nursing care"
choose "Yes"
select organisation_name, from: "scheme-owning-organisation-id-field"
choose answers["housing_stock_owners"].presence || "The same organisation that owns the housing stock"
click_button "Save and continue"

4
spec/features/schemes_spec.rb

@ -446,7 +446,7 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content "This scheme contains confidential information"
expect(page).to have_content "Which organisation owns the housing stock for this scheme?"
expect(page).to have_content "What is this type of scheme?"
expect(page).to have_content "Is this scheme registered under the Care Standards Act 2000?"
expect(page).to have_content "Is the scheme regulated by the Care Quality Commission (CQC)?"
expect(page).to have_content "Who provides the support services used by this scheme?"
end
@ -463,7 +463,7 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content "This scheme contains confidential information"
expect(page).to have_content "What is this type of scheme?"
expect(page).to have_content "Who provides the support services used by this scheme?"
expect(page).to have_content "Is this scheme registered under the Care Standards Act 2000?"
expect(page).to have_content "Is the scheme regulated by the Care Quality Commission (CQC)?"
end
it "returns to the primary client group question after amending scheme details" do

6
spec/fixtures/files/lettings_log_csv_export_codes_26.csv vendored

File diff suppressed because one or more lines are too long

6
spec/fixtures/files/lettings_log_csv_export_labels_26.csv vendored

File diff suppressed because one or more lines are too long

6
spec/fixtures/files/lettings_log_csv_export_non_support_codes_26.csv vendored

File diff suppressed because one or more lines are too long

6
spec/fixtures/files/lettings_log_csv_export_non_support_labels_26.csv vendored

File diff suppressed because one or more lines are too long

10
spec/fixtures/files/original_schemes.csv vendored

@ -1,6 +1,6 @@
scheme_code,scheme_service_name,scheme_status,scheme_confidential,scheme_type,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_support_services_provided_by,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,scheme_active_dates
{id1},Test name,active,Yes,Housing for older people,Yes – registered care home providing nursing care,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"
{id2},Test name,active,Yes,Housing for older people,Yes – registered care home providing nursing care,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"
{id3},Test name,active,Yes,Housing for older people,Yes – registered care home providing nursing care,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"
{id4},Incomplete scheme,incomplete,Yes,Housing for older people,Yes – registered care home providing nursing care,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,,,,,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"
SWrong_id,Incomplete scheme,incomplete,Yes,Housing for older people,Yes – registered care home providing nursing care,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,,,,,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"
{id1},Test name,active,Yes,Housing for older people,Yes,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"
{id2},Test name,active,Yes,Housing for older people,Yes,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"
{id3},Test name,active,Yes,Housing for older people,Yes,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"
{id4},Incomplete scheme,incomplete,Yes,Housing for older people,Yes,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,,,,,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"
SWrong_id,Incomplete scheme,incomplete,Yes,Housing for older people,Yes,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,,,,,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"

1 scheme_code scheme_service_name scheme_status scheme_confidential scheme_type scheme_registered_under_care_act scheme_owning_organisation_name scheme_support_services_provided_by scheme_primary_client_group scheme_has_other_client_group scheme_secondary_client_group scheme_support_type scheme_intended_stay scheme_created_at scheme_active_dates
2 {id1} Test name active Yes Housing for older people Yes – registered care home providing nursing care Yes MHCLG The same organisation that owns the housing stock People with alcohol problems Yes Older people with support needs High level Medium stay 2021-04-01T00:00:00+01:00 Active from 1 April 2020
3 {id2} Test name active Yes Housing for older people Yes – registered care home providing nursing care Yes MHCLG The same organisation that owns the housing stock People with alcohol problems Yes Older people with support needs High level Medium stay 2021-04-01T00:00:00+01:00 Active from 1 April 2020
4 {id3} Test name active Yes Housing for older people Yes – registered care home providing nursing care Yes MHCLG The same organisation that owns the housing stock People with alcohol problems Yes Older people with support needs High level Medium stay 2021-04-01T00:00:00+01:00 Active from 1 April 2020
5 {id4} Incomplete scheme incomplete Yes Housing for older people Yes – registered care home providing nursing care Yes MHCLG The same organisation that owns the housing stock People with alcohol problems 2021-04-01T00:00:00+01:00 Active from 1 April 2020
6 SWrong_id Incomplete scheme incomplete Yes Housing for older people Yes – registered care home providing nursing care Yes MHCLG The same organisation that owns the housing stock People with alcohol problems 2021-04-01T00:00:00+01:00 Active from 1 April 2020

4
spec/fixtures/files/updated_schemes.csv vendored

@ -1,6 +1,6 @@
scheme_code,scheme_service_name,scheme_status,scheme_confidential,scheme_type,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_support_services_provided_by,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,scheme_active_dates
{id1},Updated test name,incomplete,No,Direct Access Hostel,No,Different organisation,Another registered stock owner,People with drug problems,No,Older people with support needs,Low level,Permanent,2022-04-01T00:00:00+01:00,"Active from 2 April 2020"
{id2},Test name,active,Yes,Housing for older people,Yes – registered care home providing nursing care,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"
{id3}, ,active,Yse,Direct access Hostel,Yes – registered care home providing nursing care,non existing org,wrong answer,FD,no,lder people with support needs,high,Permanent ,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"
{id2},Test name,active,Yes,Housing for older people,Yes,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"
{id3}, ,active,Yse,Direct access Hostel,Yes,non existing org,wrong answer,FD,no,lder people with support needs,high,Permanent ,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"
Wrong_id,Incomplete scheme,incomplete,Yes,Housing for older people,No,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,,,,,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"
SWrong_id,Incomplete scheme,incomplete,Yes,Housing for older people,No,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,,,,,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"

1 scheme_code scheme_service_name scheme_status scheme_confidential scheme_type scheme_registered_under_care_act scheme_owning_organisation_name scheme_support_services_provided_by scheme_primary_client_group scheme_has_other_client_group scheme_secondary_client_group scheme_support_type scheme_intended_stay scheme_created_at scheme_active_dates
2 {id1} Updated test name incomplete No Direct Access Hostel No Different organisation Another registered stock owner People with drug problems No Older people with support needs Low level Permanent 2022-04-01T00:00:00+01:00 Active from 2 April 2020
3 {id2} Test name active Yes Housing for older people Yes – registered care home providing nursing care Yes MHCLG The same organisation that owns the housing stock People with alcohol problems Yes Older people with support needs High level Medium stay 2021-04-01T00:00:00+01:00 Active from 1 April 2020
4 {id3} active Yse Direct access Hostel Yes – registered care home providing nursing care Yes non existing org wrong answer FD no lder people with support needs high Permanent 2021-04-01T00:00:00+01:00 Active from 1 April 2020
5 Wrong_id Incomplete scheme incomplete Yes Housing for older people No MHCLG The same organisation that owns the housing stock People with alcohol problems 2021-04-01T00:00:00+01:00 Active from 1 April 2020
6 SWrong_id Incomplete scheme incomplete Yes Housing for older people No MHCLG The same organisation that owns the housing stock People with alcohol problems 2021-04-01T00:00:00+01:00 Active from 1 April 2020

3
spec/helpers/check_answers_helper_spec.rb

@ -41,7 +41,8 @@ RSpec.describe CheckAnswersHelper do
describe "#get_answer_label" do
context "when unanswered and bulk upload" do
let(:question) { log.form.questions.reject { |q| log.optional_fields.include?(q.id) }.sample }
# make sure to not include questions that override the answer label
let(:question) { log.form.questions.reject { |q| log.optional_fields.include?(q.id) || q.answer_label(log, current_user).present? }.sample }
let(:bulk_upload) { create(:bulk_upload) }
let(:log) { create(:sales_log, creation_method: "bulk upload", bulk_upload:) }

16
spec/helpers/collection_time_helper_spec.rb

@ -152,7 +152,7 @@ RSpec.describe CollectionTimeHelper do
it "returns a different date within the collection year" do
result = generate_different_date_within_collection_year(date)
expect(result).not_to eq(date)
expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2025, 3, 31)).inclusive
expect(result).to be_between(Date.new(2024, 4, 1), Date.new(2025, 3, 31)).inclusive
end
end
@ -162,7 +162,7 @@ RSpec.describe CollectionTimeHelper do
it "returns a different date within the collection year" do
result = generate_different_date_within_collection_year(date)
expect(result).not_to eq(date)
expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2025, 3, 31)).inclusive
expect(result).to be_between(Date.new(2024, 4, 1), Date.new(2025, 3, 31)).inclusive
end
end
@ -170,7 +170,7 @@ RSpec.describe CollectionTimeHelper do
it "ignores the override and returns a different date within the collection year" do
result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2023, 12, 31))
expect(result).not_to eq(date)
expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2025, 3, 31)).inclusive
expect(result).to be_between(Date.new(2024, 4, 1), Date.new(2025, 3, 31)).inclusive
end
end
@ -178,7 +178,7 @@ RSpec.describe CollectionTimeHelper do
it "ignores the override and returns a different date within the collection year" do
result = generate_different_date_within_collection_year(date, end_date_override: Time.zone.local(2025, 12, 1))
expect(result).not_to eq(date)
expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2025, 3, 31)).inclusive
expect(result).to be_between(Date.new(2024, 4, 1), Date.new(2025, 3, 31)).inclusive
end
end
@ -186,7 +186,7 @@ RSpec.describe CollectionTimeHelper do
it "returns a different date within the overridden range" do
result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2024, 8, 1), end_date_override: Time.zone.local(2024, 9, 1))
expect(result).not_to eq(date)
expect(result).to be_between(Time.zone.local(2024, 8, 1), Time.zone.local(2024, 9, 1)).inclusive
expect(result).to be_between(Date.new(2024, 8, 1), Date.new(2024, 9, 1)).inclusive
end
end
@ -194,7 +194,7 @@ RSpec.describe CollectionTimeHelper do
it "ignores the start_date_override and returns a different date within the collection year" do
result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2023, 12, 31), end_date_override: Time.zone.local(2024, 5, 1))
expect(result).not_to eq(date)
expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2024, 5, 1)).inclusive
expect(result).to be_between(Date.new(2024, 4, 1), Date.new(2024, 5, 1)).inclusive
end
end
@ -202,7 +202,7 @@ RSpec.describe CollectionTimeHelper do
it "ignores the end_date_override and returns a different date within the collection year" do
result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2025, 3, 1), end_date_override: Time.zone.local(2025, 12, 1))
expect(result).not_to eq(date)
expect(result).to be_between(Time.zone.local(2025, 3, 1), Time.zone.local(2025, 3, 31)).inclusive
expect(result).to be_between(Date.new(2025, 3, 1), Date.new(2025, 3, 31)).inclusive
end
end
@ -210,7 +210,7 @@ RSpec.describe CollectionTimeHelper do
it "ignores both overrides and returns a different date within the collection year" do
result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2023, 12, 31), end_date_override: Time.zone.local(2025, 12, 1))
expect(result).not_to eq(date)
expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2025, 3, 31)).inclusive
expect(result).to be_between(Date.new(2024, 4, 1), Date.new(2025, 3, 31)).inclusive
end
end
end

76
spec/helpers/filters_helper_spec.rb

@ -478,45 +478,6 @@ RSpec.describe FiltersHelper do
end
describe "#collection_year_options" do
context "with 23/24 as the current collection year" do
before do
allow(Time).to receive(:now).and_return(Time.zone.local(2023, 5, 1))
end
context "and in crossover period" do
before do
allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true)
end
it "has the correct options" do
expect(collection_year_options).to eq(
{
"2023" => "2023 to 2024", "2022" => "2022 to 2023", "2021" => "2021 to 2022"
},
)
end
end
context "and not in crossover period" do
before do
allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false)
end
it "has the correct options" do
expect(collection_year_options).to eq(
{
"2023" => "2023 to 2024", "2022" => "2022 to 2023"
},
)
end
end
end
context "with 24/25 as the current collection year" do
before do
allow(Time).to receive(:now).and_return(Time.zone.local(2024, 5, 1))
end
context "and in crossover period" do
before do
allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true)
@ -525,7 +486,9 @@ RSpec.describe FiltersHelper do
it "has the correct options" do
expect(collection_year_options).to eq(
{
"2024" => "2024 to 2025", "2023" => "2023 to 2024", "2022" => "2022 to 2023"
current_collection_start_year.to_s => "#{current_collection_start_year} to #{current_collection_end_year}",
previous_collection_start_year.to_s => "#{previous_collection_start_year} to #{previous_collection_end_year}",
archived_collection_start_year.to_s => "#{archived_collection_start_year} to #{archived_collection_end_year}",
},
)
end
@ -539,7 +502,8 @@ RSpec.describe FiltersHelper do
it "has the correct options" do
expect(collection_year_options).to eq(
{
"2024" => "2024 to 2025", "2023" => "2023 to 2024"
current_collection_start_year.to_s => "#{current_collection_start_year} to #{current_collection_end_year}",
previous_collection_start_year.to_s => "#{previous_collection_start_year} to #{previous_collection_end_year}",
},
)
end
@ -552,21 +516,17 @@ RSpec.describe FiltersHelper do
it "includes next year in the options" do
expect(collection_year_options).to eq(
{
"2025" => "2025 to 2026", "2024" => "2024 to 2025", "2023" => "2023 to 2024"
next_collection_start_year.to_s => "#{next_collection_start_year} to #{next_collection_end_year}",
current_collection_start_year.to_s => "#{current_collection_start_year} to #{current_collection_end_year}",
previous_collection_start_year.to_s => "#{previous_collection_start_year} to #{previous_collection_end_year}",
},
)
end
end
end
end
end
describe "#collection_year_radio_options" do
context "with 23/24 as the current collection year" do
before do
allow(Time).to receive(:now).and_return(Time.zone.local(2023, 5, 1))
end
context "and in crossover period" do
before do
allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true)
@ -575,7 +535,9 @@ RSpec.describe FiltersHelper do
it "has the correct options" do
expect(collection_year_radio_options).to eq(
{
"2023" => { label: "2023 to 2024" }, "2022" => { label: "2022 to 2023" }, "2021" => { label: "2021 to 2022" }
current_collection_start_year.to_s => { label: "#{current_collection_start_year} to #{current_collection_end_year}" },
previous_collection_start_year.to_s => { label: "#{previous_collection_start_year} to #{previous_collection_end_year}" },
archived_collection_start_year.to_s => { label: "#{archived_collection_start_year} to #{archived_collection_end_year}" },
},
)
end
@ -589,27 +551,29 @@ RSpec.describe FiltersHelper do
it "has the correct options" do
expect(collection_year_radio_options).to eq(
{
"2023" => { label: "2023 to 2024" }, "2022" => { label: "2022 to 2023" }
current_collection_start_year.to_s => { label: "#{current_collection_start_year} to #{current_collection_end_year}" },
previous_collection_start_year.to_s => { label: "#{previous_collection_start_year} to #{previous_collection_end_year}" },
},
)
end
end
end
context "with 24/25 as the current collection year" do
context "with future form use turned on" do
before do
allow(Time).to receive(:now).and_return(Time.zone.local(2024, 5, 1))
allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true)
end
it "has the correct options" do
it "includes next year in the options" do
expect(collection_year_radio_options).to eq(
{
"2024" => { label: "2024 to 2025" }, "2023" => { label: "2023 to 2024" }, "2022" => { label: "2022 to 2023" }
next_collection_start_year.to_s => { label: "#{next_collection_start_year} to #{next_collection_end_year}" },
current_collection_start_year.to_s => { label: "#{current_collection_start_year} to #{current_collection_end_year}" },
previous_collection_start_year.to_s => { label: "#{previous_collection_start_year} to #{previous_collection_end_year}" },
},
)
end
end
end
end
describe "#filters_applied_text" do
let(:filter_type) { "lettings_logs" }

1
spec/helpers/locations_helper_spec.rb

@ -59,6 +59,7 @@ RSpec.describe LocationsHelper do
before do
allow(Time).to receive(:now).and_return(today)
allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(true)
Singleton.__init__(FormHandler)
end
it "returns one active period without to date" do

21
spec/lib/tasks/count_duplicates_spec.rb

@ -101,7 +101,12 @@ RSpec.describe "count_duplicates" do
end
it "creates a csv with correct duplicate numbers" do
expect(storage_service).to receive(:write_file).with(/location-duplicates-.*\.csv/, "\uFEFFOrganisation id,Duplicate sets within individual schemes,Duplicate locations within individual schemes,All duplicate sets,All duplicates\n#{organisation.id},3,6,4,9\n#{organisation2.id},2,7,2,7\n")
expect(storage_service).to receive(:write_file).with(/location-duplicates-.*\.csv/, satisfy do |s|
s.start_with?("\uFEFFOrganisation id,Duplicate sets within individual schemes,Duplicate locations within individual schemes,All duplicate sets,All duplicates") &&
s.include?("#{organisation.id},3,6,4,9") &&
s.include?("#{organisation2.id},2,7,2,7") &&
s.count("\n") == 3
end)
expect(Rails.logger).to receive(:info).with("Download URL: #{test_url}")
task.invoke
end
@ -149,7 +154,12 @@ RSpec.describe "count_duplicates" do
end
it "creates a csv with correct duplicate numbers" do
expect(storage_service).to receive(:write_file).with(/scheme-duplicates-.*\.csv/, "\uFEFFOrganisation id,Number of duplicate sets,Total duplicate schemes\n#{organisation.id},2,5\n#{organisation2.id},1,5\n")
expect(storage_service).to receive(:write_file).with(/scheme-duplicates-.*\.csv/, satisfy do |s|
s.start_with?("\uFEFFOrganisation id,Number of duplicate sets,Total duplicate schemes") &&
s.include?("#{organisation.id},2,5") &&
s.include?("#{organisation2.id},1,5") &&
s.count("\n") == 3
end)
expect(Rails.logger).to receive(:info).with("Download URL: #{test_url}")
task.invoke
end
@ -211,7 +221,12 @@ RSpec.describe "count_duplicates" do
end
it "creates a csv with correct duplicate numbers" do
expect(storage_service).to receive(:write_file).with(/location-duplicates-.*\.csv/, "\uFEFFOrganisation id,Duplicate sets within individual schemes,Duplicate locations within individual schemes,All duplicate sets,All duplicates\n#{organisation.id},3,6,4,9\n#{organisation2.id},2,7,2,7\n")
expect(storage_service).to receive(:write_file).with(/location-duplicates-.*\.csv/, satisfy do |s|
s.start_with?("\uFEFFOrganisation id,Duplicate sets within individual schemes,Duplicate locations within individual schemes,All duplicate sets,All duplicates")
s.include?("#{organisation.id},3,6,4,9") &&
s.include?("#{organisation2.id},2,7,2,7") &&
s.count("\n") == 3
end)
expect(Rails.logger).to receive(:info).with("Download URL: #{test_url}")
task.invoke
end

6
spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb

@ -57,7 +57,7 @@ RSpec.describe "bulk_update" do
3,
service_name: "Test name",
sensitive: 1,
registered_under_care_act: 4,
registered_under_care_act: 5,
support_type: 4,
scheme_type: 7,
arrangement_type: "D",
@ -123,7 +123,7 @@ RSpec.describe "bulk_update" do
schemes[1].reload
expect(schemes[1].service_name).to eq("Test name")
expect(schemes[1].sensitive).to eq("Yes")
expect(schemes[1].registered_under_care_act).to eq("Yes – registered care home providing nursing care")
expect(schemes[1].registered_under_care_act).to eq("Yes")
expect(schemes[1].support_type).to eq("High level")
expect(schemes[1].scheme_type).to eq("Housing for older people")
expect(schemes[1].arrangement_type).to eq("The same organisation that owns the housing stock")
@ -141,7 +141,7 @@ RSpec.describe "bulk_update" do
schemes[2].reload
expect(schemes[2].service_name).to eq("Test name")
expect(schemes[2].sensitive).to eq("Yes")
expect(schemes[2].registered_under_care_act).to eq("Yes – registered care home providing nursing care")
expect(schemes[2].registered_under_care_act).to eq("Yes")
expect(schemes[2].support_type).to eq("High level")
expect(schemes[2].scheme_type).to eq("Housing for older people")
expect(schemes[2].arrangement_type).to eq("The same organisation that owns the housing stock")

57
spec/models/form/lettings/pages/person_lead_partner_spec.rb

@ -4,7 +4,8 @@ RSpec.describe Form::Lettings::Pages::PersonLeadPartner, type: :model do
subject(:page) { described_class.new(nil, page_definition, subsection, person_index:) }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2024, 4, 1), start_year_2025_or_later?: true)) }
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1)) }
let(:subsection) { instance_double(Form::Subsection, form:) }
let(:person_index) { 2 }
it "has correct subsection" do
@ -24,6 +25,11 @@ RSpec.describe Form::Lettings::Pages::PersonLeadPartner, type: :model do
expect(page.id).to eq("person_2_lead_partner")
end
context "with start year < 2026", metadata: { year: 25 } do
before do
allow(form).to receive(:start_year_2026_or_later?).and_return(false)
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[{ "details_known_2" => 0 }],
@ -31,6 +37,28 @@ RSpec.describe Form::Lettings::Pages::PersonLeadPartner, type: :model do
end
end
context "with start year >= 2026", metadata: { year: 26 } do
before do
allow(form).to receive(:start_year_2026_or_later?).and_return(true)
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[
{
"details_known_2" => 0,
"age2" => {
"operator" => ">=",
"operand" => 16,
},
},
{ "details_known_2" => 0, "age2" => nil },
],
)
end
end
end
context "with person 3" do
let(:person_index) { 3 }
@ -42,10 +70,37 @@ RSpec.describe Form::Lettings::Pages::PersonLeadPartner, type: :model do
expect(page.id).to eq("person_3_lead_partner")
end
context "with start year < 2026", metadata: { year: 25 } do
before do
allow(form).to receive(:start_year_2026_or_later?).and_return(false)
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[{ "details_known_3" => 0 }],
)
end
end
context "with start year >= 2026", metadata: { year: 26 } do
before do
allow(form).to receive(:start_year_2026_or_later?).and_return(true)
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[
{
"details_known_3" => 0,
"age3" => {
"operator" => ">=",
"operand" => 16,
},
},
{ "details_known_3" => 0, "age3" => nil },
],
)
end
end
end
end

62
spec/models/form/lettings/questions/person_partner_spec.rb

@ -1,10 +1,26 @@
require "rails_helper"
RSpec.describe Form::Lettings::Questions::PersonPartner, type: :model do
include CollectionTimeHelper
subject(:question) { described_class.new(nil, question_definition, page, person_index:) }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2025, 4, 4), start_year_2025_or_later?: true))) }
let(:year) { nil }
let(:page) do
instance_double(
Form::Page,
subsection: instance_double(
Form::Subsection,
form: instance_double(
Form,
start_date: year ? collection_start_date_for_year(year) : current_collection_start_date,
start_year_2025_or_later?: year.nil? || year >= 2025,
start_year_2026_or_later?: year.nil? || year >= 2026,
),
),
)
end
let(:person_index) { 2 }
it "has correct page" do
@ -15,10 +31,6 @@ RSpec.describe Form::Lettings::Questions::PersonPartner, type: :model do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?(nil)).to be false
end
it "has the correct answer_options" do
expect(question.answer_options).to eq("P" => { "value" => "Yes" },
"X" => { "value" => "No" },
@ -41,6 +53,46 @@ RSpec.describe Form::Lettings::Questions::PersonPartner, type: :model do
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(2)
end
context "with person 2 age < 16" do
let(:log) { build(:lettings_log, age2: 10) }
context "and in 2025", metadata: { year: 25 } do
let(:year) { 2025 }
it "is not marked as derived" do
expect(question.derived?(log)).to be false
end
end
context "and in 2026", metadata: { year: 26 } do
let(:year) { 2026 }
it "is marked as derived" do
expect(question.derived?(log)).to be true
end
end
end
context "with person 2 age >= 16" do
let(:log) { build(:lettings_log, age2: 20) }
context "and in 2025", metadata: { year: 25 } do
let(:year) { 2025 }
it "is not marked as derived" do
expect(question.derived?(log)).to be false
end
end
context "and in 2026", metadata: { year: 26 } do
let(:year) { 2026 }
it "is not marked as derived" do
expect(question.derived?(log)).to be false
end
end
end
end
context "with person 3" do

76
spec/models/form/lettings/subsections/household_characteristics_spec.rb

@ -17,15 +17,15 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
expect(household_characteristics.section).to eq(section)
end
context "with start year before 2024" do
context "with start year 2024" do
before do
allow(form).to receive(:start_year_2024_or_later?).and_return(false)
allow(form).to receive(:start_year_2024_or_later?).and_return(true)
allow(form).to receive(:start_year_2026_or_later?).and_return(false)
end
it "has correct pages" do
expect(household_characteristics.pages.map(&:id)).to eq(
%w[
declaration
household_members
no_females_pregnant_household_lead_hhmemb_value_check
females_in_soft_age_range_in_pregnant_household_lead_hhmemb_value_check
@ -50,11 +50,14 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
working_situation_lead_tenant_over_retirement_value_check
person_2_known
person_2_relationship_to_lead
relationship_2_partner_under_16_value_check
relationship_2_multiple_partners_value_check
person_2_age
no_females_pregnant_household_person_2_age_value_check
females_in_soft_age_range_in_pregnant_household_person_2_age_value_check
age_2_under_retirement_value_check
age_2_over_retirement_value_check
age_2_partner_under_16_value_check
person_2_gender_identity
no_females_pregnant_household_person_2_value_check
females_in_soft_age_range_in_pregnant_household_person_2_value_check
@ -64,11 +67,14 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
working_situation_2_over_retirement_value_check
person_3_known
person_3_relationship_to_lead
relationship_3_partner_under_16_value_check
relationship_3_multiple_partners_value_check
person_3_age
no_females_pregnant_household_person_3_age_value_check
females_in_soft_age_range_in_pregnant_household_person_3_age_value_check
age_3_under_retirement_value_check
age_3_over_retirement_value_check
age_3_partner_under_16_value_check
person_3_gender_identity
no_females_pregnant_household_person_3_value_check
females_in_soft_age_range_in_pregnant_household_person_3_value_check
@ -78,11 +84,14 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
working_situation_3_over_retirement_value_check
person_4_known
person_4_relationship_to_lead
relationship_4_partner_under_16_value_check
relationship_4_multiple_partners_value_check
person_4_age
no_females_pregnant_household_person_4_age_value_check
females_in_soft_age_range_in_pregnant_household_person_4_age_value_check
age_4_under_retirement_value_check
age_4_over_retirement_value_check
age_4_partner_under_16_value_check
person_4_gender_identity
no_females_pregnant_household_person_4_value_check
females_in_soft_age_range_in_pregnant_household_person_4_value_check
@ -92,11 +101,14 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
working_situation_4_over_retirement_value_check
person_5_known
person_5_relationship_to_lead
relationship_5_partner_under_16_value_check
relationship_5_multiple_partners_value_check
person_5_age
no_females_pregnant_household_person_5_age_value_check
females_in_soft_age_range_in_pregnant_household_person_5_age_value_check
age_5_under_retirement_value_check
age_5_over_retirement_value_check
age_5_partner_under_16_value_check
person_5_gender_identity
no_females_pregnant_household_person_5_value_check
females_in_soft_age_range_in_pregnant_household_person_5_value_check
@ -106,11 +118,14 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
working_situation_5_over_retirement_value_check
person_6_known
person_6_relationship_to_lead
relationship_6_partner_under_16_value_check
relationship_6_multiple_partners_value_check
person_6_age
no_females_pregnant_household_person_6_age_value_check
females_in_soft_age_range_in_pregnant_household_person_6_age_value_check
age_6_under_retirement_value_check
age_6_over_retirement_value_check
age_6_partner_under_16_value_check
person_6_gender_identity
no_females_pregnant_household_person_6_value_check
females_in_soft_age_range_in_pregnant_household_person_6_value_check
@ -120,11 +135,14 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
working_situation_6_over_retirement_value_check
person_7_known
person_7_relationship_to_lead
relationship_7_partner_under_16_value_check
relationship_7_multiple_partners_value_check
person_7_age
no_females_pregnant_household_person_7_age_value_check
females_in_soft_age_range_in_pregnant_household_person_7_age_value_check
age_7_under_retirement_value_check
age_7_over_retirement_value_check
age_7_partner_under_16_value_check
person_7_gender_identity
no_females_pregnant_household_person_7_value_check
females_in_soft_age_range_in_pregnant_household_person_7_value_check
@ -134,11 +152,14 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
working_situation_7_over_retirement_value_check
person_8_known
person_8_relationship_to_lead
relationship_8_partner_under_16_value_check
relationship_8_multiple_partners_value_check
person_8_age
no_females_pregnant_household_person_8_age_value_check
females_in_soft_age_range_in_pregnant_household_person_8_age_value_check
age_8_under_retirement_value_check
age_8_over_retirement_value_check
age_8_partner_under_16_value_check
person_8_gender_identity
no_females_pregnant_household_person_8_value_check
females_in_soft_age_range_in_pregnant_household_person_8_value_check
@ -151,9 +172,11 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
end
end
context "with start year >= 2024" do
context "with start year 2025" do
before do
allow(form).to receive(:start_year_2024_or_later?).and_return(true)
allow(form).to receive(:start_year_2025_or_later?).and_return(true)
allow(form).to receive(:start_year_2026_or_later?).and_return(false)
end
it "has correct pages" do
@ -182,7 +205,7 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
working_situation_lead_tenant_under_retirement_value_check
working_situation_lead_tenant_over_retirement_value_check
person_2_known
person_2_relationship_to_lead
person_2_lead_partner
relationship_2_partner_under_16_value_check
relationship_2_multiple_partners_value_check
person_2_age
@ -199,7 +222,7 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
working_situation_2_under_retirement_value_check
working_situation_2_over_retirement_value_check
person_3_known
person_3_relationship_to_lead
person_3_lead_partner
relationship_3_partner_under_16_value_check
relationship_3_multiple_partners_value_check
person_3_age
@ -216,7 +239,7 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
working_situation_3_under_retirement_value_check
working_situation_3_over_retirement_value_check
person_4_known
person_4_relationship_to_lead
person_4_lead_partner
relationship_4_partner_under_16_value_check
relationship_4_multiple_partners_value_check
person_4_age
@ -233,7 +256,7 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
working_situation_4_under_retirement_value_check
working_situation_4_over_retirement_value_check
person_5_known
person_5_relationship_to_lead
person_5_lead_partner
relationship_5_partner_under_16_value_check
relationship_5_multiple_partners_value_check
person_5_age
@ -250,7 +273,7 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
working_situation_5_under_retirement_value_check
working_situation_5_over_retirement_value_check
person_6_known
person_6_relationship_to_lead
person_6_lead_partner
relationship_6_partner_under_16_value_check
relationship_6_multiple_partners_value_check
person_6_age
@ -267,7 +290,7 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
working_situation_6_under_retirement_value_check
working_situation_6_over_retirement_value_check
person_7_known
person_7_relationship_to_lead
person_7_lead_partner
relationship_7_partner_under_16_value_check
relationship_7_multiple_partners_value_check
person_7_age
@ -284,7 +307,7 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
working_situation_7_under_retirement_value_check
working_situation_7_over_retirement_value_check
person_8_known
person_8_relationship_to_lead
person_8_lead_partner
relationship_8_partner_under_16_value_check
relationship_8_multiple_partners_value_check
person_8_age
@ -305,10 +328,11 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
end
end
context "with start year >= 2025" do
context "with start year >= 2026" do
before do
allow(form).to receive(:start_year_2024_or_later?).and_return(true)
allow(form).to receive(:start_year_2025_or_later?).and_return(true)
allow(form).to receive(:start_year_2026_or_later?).and_return(true)
end
it "has correct pages" do
@ -337,15 +361,13 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
working_situation_lead_tenant_under_retirement_value_check
working_situation_lead_tenant_over_retirement_value_check
person_2_known
person_2_age
person_2_lead_partner
relationship_2_partner_under_16_value_check
relationship_2_multiple_partners_value_check
person_2_age
no_females_pregnant_household_person_2_age_value_check
females_in_soft_age_range_in_pregnant_household_person_2_age_value_check
age_2_under_retirement_value_check
age_2_over_retirement_value_check
age_2_partner_under_16_value_check
person_2_gender_identity
no_females_pregnant_household_person_2_value_check
females_in_soft_age_range_in_pregnant_household_person_2_value_check
@ -354,15 +376,13 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
working_situation_2_under_retirement_value_check
working_situation_2_over_retirement_value_check
person_3_known
person_3_age
person_3_lead_partner
relationship_3_partner_under_16_value_check
relationship_3_multiple_partners_value_check
person_3_age
no_females_pregnant_household_person_3_age_value_check
females_in_soft_age_range_in_pregnant_household_person_3_age_value_check
age_3_under_retirement_value_check
age_3_over_retirement_value_check
age_3_partner_under_16_value_check
person_3_gender_identity
no_females_pregnant_household_person_3_value_check
females_in_soft_age_range_in_pregnant_household_person_3_value_check
@ -371,15 +391,13 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
working_situation_3_under_retirement_value_check
working_situation_3_over_retirement_value_check
person_4_known
person_4_age
person_4_lead_partner
relationship_4_partner_under_16_value_check
relationship_4_multiple_partners_value_check
person_4_age
no_females_pregnant_household_person_4_age_value_check
females_in_soft_age_range_in_pregnant_household_person_4_age_value_check
age_4_under_retirement_value_check
age_4_over_retirement_value_check
age_4_partner_under_16_value_check
person_4_gender_identity
no_females_pregnant_household_person_4_value_check
females_in_soft_age_range_in_pregnant_household_person_4_value_check
@ -388,15 +406,13 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
working_situation_4_under_retirement_value_check
working_situation_4_over_retirement_value_check
person_5_known
person_5_age
person_5_lead_partner
relationship_5_partner_under_16_value_check
relationship_5_multiple_partners_value_check
person_5_age
no_females_pregnant_household_person_5_age_value_check
females_in_soft_age_range_in_pregnant_household_person_5_age_value_check
age_5_under_retirement_value_check
age_5_over_retirement_value_check
age_5_partner_under_16_value_check
person_5_gender_identity
no_females_pregnant_household_person_5_value_check
females_in_soft_age_range_in_pregnant_household_person_5_value_check
@ -405,15 +421,13 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
working_situation_5_under_retirement_value_check
working_situation_5_over_retirement_value_check
person_6_known
person_6_age
person_6_lead_partner
relationship_6_partner_under_16_value_check
relationship_6_multiple_partners_value_check
person_6_age
no_females_pregnant_household_person_6_age_value_check
females_in_soft_age_range_in_pregnant_household_person_6_age_value_check
age_6_under_retirement_value_check
age_6_over_retirement_value_check
age_6_partner_under_16_value_check
person_6_gender_identity
no_females_pregnant_household_person_6_value_check
females_in_soft_age_range_in_pregnant_household_person_6_value_check
@ -422,15 +436,13 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
working_situation_6_under_retirement_value_check
working_situation_6_over_retirement_value_check
person_7_known
person_7_age
person_7_lead_partner
relationship_7_partner_under_16_value_check
relationship_7_multiple_partners_value_check
person_7_age
no_females_pregnant_household_person_7_age_value_check
females_in_soft_age_range_in_pregnant_household_person_7_age_value_check
age_7_under_retirement_value_check
age_7_over_retirement_value_check
age_7_partner_under_16_value_check
person_7_gender_identity
no_females_pregnant_household_person_7_value_check
females_in_soft_age_range_in_pregnant_household_person_7_value_check
@ -439,15 +451,13 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod
working_situation_7_under_retirement_value_check
working_situation_7_over_retirement_value_check
person_8_known
person_8_age
person_8_lead_partner
relationship_8_partner_under_16_value_check
relationship_8_multiple_partners_value_check
person_8_age
no_females_pregnant_household_person_8_age_value_check
females_in_soft_age_range_in_pregnant_household_person_8_age_value_check
age_8_under_retirement_value_check
age_8_over_retirement_value_check
age_8_partner_under_16_value_check
person_8_gender_identity
no_females_pregnant_household_person_8_value_check
females_in_soft_age_range_in_pregnant_household_person_8_value_check

220
spec/models/lettings_log_derived_fields_spec.rb

@ -2,9 +2,12 @@ require "rails_helper"
require "shared/shared_examples_for_derived_fields"
RSpec.describe LettingsLog, type: :model do
include CollectionTimeHelper
let(:organisation) { build(:organisation, name: "derived fields org") }
let(:user) { build(:user, organisation:) }
let(:log) { build(:lettings_log, :startdate_today, assigned_to: user) }
let(:startdate) { current_collection_start_date }
let(:log) { build(:lettings_log, startdate:, assigned_to: user) }
include_examples "shared examples for derived fields", :lettings_log
@ -108,6 +111,9 @@ RSpec.describe LettingsLog, type: :model do
end
describe "deriving household member fields" do
context "when it is 2024", metadata: { year: 24 } do
let(:startdate) { collection_start_date_for_year(2024) }
before do
log.assign_attributes(
relat2: "X",
@ -144,6 +150,93 @@ RSpec.describe LettingsLog, type: :model do
end
end
context "when it is 2025", metadata: { year: 25 } do
let(:startdate) { collection_start_date_for_year(2025) }
before do
log.assign_attributes(
relat2: "X",
relat3: "X",
relat4: "X",
relat5: "X",
# relat7 is derived
relat8: "X",
age1: 22,
age2: 16,
age4: 60,
age6: 88,
age7: 14,
age8: 42,
)
log.set_derived_fields!
end
it "correctly derives totchild" do
expect(log.totchild).to eq 1
end
it "correctly derives totelder" do
expect(log.totelder).to eq 2
end
it "correctly derives totadult" do
expect(log.totadult).to eq 3
end
it "correctly derives economic status for tenants under 16" do
expect(log.ecstat7).to eq 9
end
it "does not derive relationship for tenants under 16" do
expect(log.relat7).to be_nil
end
end
context "when it is 2026", metadata: { year: 26 } do
let(:startdate) { collection_start_date_for_year(2026) }
before do
log.assign_attributes(
relat2: "X",
relat3: "X",
relat4: "X",
relat5: "X",
# relat7 is derived
relat8: "X",
age1: 22,
age2: 16,
age4: 60,
age6: 88,
age7: 14,
age8: 42,
)
log.set_derived_fields!
end
it "correctly derives totchild" do
expect(log.totchild).to eq 1
end
it "correctly derives totelder" do
expect(log.totelder).to eq 2
end
it "correctly derives totadult" do
expect(log.totadult).to eq 3
end
it "correctly derives economic status for tenants under 16" do
expect(log.ecstat7).to eq 9
end
it "derives relationship for tenants under 16" do
expect(log.relat7).to eq "X"
end
end
end
describe "deriving lettype" do
context "when the owning organisation is a PRP" do
before do
@ -1213,24 +1306,129 @@ RSpec.describe LettingsLog, type: :model do
end
end
describe "#clear_child_ecstat_for_age_changes!" do
it "clears the working situation of a person that was previously a child under 16" do
log = create(:lettings_log, :completed, age2: 13)
log.age2 = 17
describe "#clear_child_constraints_for_age_changes!" do
let(:startdate) { current_collection_start_date }
let(:log) { create(:lettings_log, :completed, startdate:, age2: initial_age2) }
before do
log.age2 = updated_age2
end
context "when person was previously a child under 16" do
let(:initial_age2) { 13 }
let(:updated_age2) { 16 }
it "clears the working situation" do
expect { log.set_derived_fields! }.to change(log, :ecstat2).from(9).to(nil)
end
it "does not clear the working situation of a person that had an age change but is still a child under 16" do
log = create(:lettings_log, :completed, age2: 13)
log.age2 = 15
context "and it is 2025", metadata: { year: 25 } do
let(:startdate) { collection_start_date_for_year(2025) }
around do |example|
Timecop.freeze(collection_start_date_for_year(2025)) do
example.run
end
end
it "does not clear the relationship" do
expect { log.set_derived_fields! }.to not_change(log, :relat2)
end
end
context "and it is 2026", metadata: { year: 26 } do
let(:startdate) { collection_start_date_for_year(2026) }
around do |example|
Timecop.freeze(collection_start_date_for_year(2026)) do
Singleton.__init__(FormHandler)
example.run
end
end
it "clears the relationship" do
expect { log.set_derived_fields! }.to change(log, :relat2).from("X").to(nil)
end
end
end
context "when person had an age change but is still a child under 16" do
let(:initial_age2) { 13 }
let(:updated_age2) { 15 }
it "does not clear the working situation" do
expect { log.set_derived_fields! }.to not_change(log, :ecstat2)
end
it "does not clear the working situation of a person that had an age change but is still an adult" do
log = create(:lettings_log, :completed, age2: 45)
log.age2 = 46
context "and it is 2025", metadata: { year: 25 } do
let(:startdate) { collection_start_date_for_year(2025) }
around do |example|
Timecop.freeze(collection_start_date_for_year(2025)) do
Singleton.__init__(FormHandler)
example.run
end
end
it "does not clear the relationship" do
expect { log.set_derived_fields! }.to not_change(log, :relat2)
end
end
context "and it is 2026", metadata: { year: 26 } do
let(:startdate) { collection_start_date_for_year(2026) }
around do |example|
Timecop.freeze(collection_start_date_for_year(2026)) do
Singleton.__init__(FormHandler)
example.run
end
end
it "does not clear the relationship" do
expect { log.set_derived_fields! }.to not_change(log, :relat2)
end
end
end
context "when person had an age change but is still an adult" do
let(:initial_age2) { 45 }
let(:updated_age2) { 46 }
it "does not clear the working situation" do
expect { log.set_derived_fields! }.to not_change(log, :ecstat2)
end
context "and it is 2025", metadata: { year: 25 } do
let(:startdate) { collection_start_date_for_year(2025) }
around do |example|
Timecop.freeze(collection_start_date_for_year(2025)) do
Singleton.__init__(FormHandler)
example.run
end
end
it "does not clear the relationship" do
expect { log.set_derived_fields! }.to not_change(log, :relat2)
end
end
context "and it is 2026", metadata: { year: 26 } do
let(:startdate) { collection_start_date_for_year(2026) }
around do |example|
Timecop.freeze(collection_start_date_for_year(2026)) do
Singleton.__init__(FormHandler)
example.run
end
end
it "does not clear the relationship" do
expect { log.set_derived_fields! }.to not_change(log, :relat2)
end
end
end
end
describe "deriving num of bedrooms from whether property is bedsit" do

17
spec/services/merge/merge_organisations_service_spec.rb

@ -546,9 +546,12 @@ RSpec.describe Merge::MergeOrganisationsService do
merging_organisation.reload
expect(absorbing_organisation.owned_lettings_logs.count).to eq(2)
expect(absorbing_organisation.managed_lettings_logs.count).to eq(1)
expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log.id).scheme).to eq(absorbing_organisation.owned_schemes.first)
expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log.id).location).to eq(absorbing_organisation.owned_schemes.first.locations.first)
expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log_no_location.id).scheme).to eq(absorbing_organisation.owned_schemes.first)
absorbed_active_scheme = absorbing_organisation.owned_schemes.find_by(service_name: scheme.service_name)
absorbed_active_location = absorbed_active_scheme.locations.find_by(postcode: location.postcode)
expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log.id).scheme).to eq(absorbed_active_scheme)
expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log.id).location).to eq(absorbed_active_location)
expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log_no_location.id).scheme).to eq(absorbed_active_scheme)
expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log_no_location.id).location).to eq(nil)
end
@ -814,12 +817,12 @@ RSpec.describe Merge::MergeOrganisationsService do
it "moves active schemes and locations to absorbing organisation" do
expect(absorbing_organisation.owned_schemes.count).to eq(2)
expect(absorbing_organisation.owned_schemes.first.locations.map(&:postcode)).to match_array([location, deactivated_location, location_without_startdate, location_with_past_startdate, location_with_future_startdate].map(&:postcode))
expect(absorbing_organisation.owned_schemes.first.locations.find_by(postcode: location_without_startdate.postcode).startdate).to eq(Time.zone.yesterday)
expect(absorbing_organisation.owned_schemes.first.locations.find_by(postcode: location_with_past_startdate.postcode).startdate).to eq(Time.zone.yesterday)
expect(absorbing_organisation.owned_schemes.first.locations.find_by(postcode: location_with_future_startdate.postcode).startdate.to_date).to eq(Time.zone.today + 2.months)
absorbed_active_scheme = absorbing_organisation.owned_schemes.find_by(service_name: scheme.service_name)
absorbed_active_location = absorbed_active_scheme.locations.find_by(postcode: location.postcode)
expect(absorbed_active_scheme.locations.map(&:postcode)).to match_array([location, deactivated_location, location_without_startdate, location_with_past_startdate, location_with_future_startdate].map(&:postcode))
expect(absorbed_active_scheme.locations.find_by(postcode: location_without_startdate.postcode).startdate).to eq(Time.zone.yesterday)
expect(absorbed_active_scheme.locations.find_by(postcode: location_with_past_startdate.postcode).startdate).to eq(Time.zone.yesterday)
expect(absorbed_active_scheme.locations.find_by(postcode: location_with_future_startdate.postcode).startdate.to_date).to eq(Time.zone.today + 2.months)
expect(absorbed_active_scheme.service_name).to eq(scheme.service_name)
expect(absorbed_active_scheme.old_id).to be_nil
expect(absorbed_active_scheme.old_visible_id).to be_nil

Loading…
Cancel
Save