diff --git a/app/models/derived_variables/lettings_log_variables.rb b/app/models/derived_variables/lettings_log_variables.rb index 1c7f161c1..1f81f61c6 100644 --- a/app/models/derived_variables/lettings_log_variables.rb +++ b/app/models/derived_variables/lettings_log_variables.rb @@ -75,6 +75,10 @@ module DerivedVariables::LettingsLogVariables self.beds = nil end + if form.start_year_2026_or_later? + infer_at_most_one_relationship! + end + clear_child_constraints_for_age_changes! child_under_16_constraints! @@ -243,6 +247,9 @@ private if form.start_year_2024_or_later? && (unittype_gn_changed? && unittype_gn_was == 2) self.beds = nil end + if form.start_year_2026_or_later? + reset_partner_fields! + end end def get_totelder @@ -295,6 +302,37 @@ private end end + def infer_at_most_one_relationship! + if partner_numbers.any? + infer_only_partner!(partner_numbers.first) + end + end + + def infer_only_partner!(partner_number) + return unless hhmemb + + (2..hhmemb).each do |i| + next if i == partner_number + + if ["P", nil].include?(public_send("relat#{i}")) + self["relat#{i}"] = "X" + end + end + end + + def reset_partner_fields! + person_count = hhmemb || 8 + (2..person_count).each do |i| + next unless send("relat#{i}_changed?") && send("relat#{i}_was") == "P" + + ((i + 1)..person_count).each do |j| + if self["relat#{j}"] == "X" + self["relat#{j}"] = nil + end + end + end + end + def household_type return unless totelder && totadult && totchild diff --git a/app/models/form.rb b/app/models/form.rb index e86596288..8370b7dbb 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -323,7 +323,12 @@ class Form if value.is_a?(Hash) && value.key?("operator") operator = value["operator"] operand = value["operand"] - log[question]&.send(operator, operand) + + if operator == "!=" # This branch is needed as `nil` does not behave as expected with the default logic (`nil&.send("!=", operand)` => `nil` i.e., `false`). + log[question] != operand + else + log[question]&.send(operator, operand) + end else parts = question.split(".") log_value = send_chain(parts, log) diff --git a/app/models/form/lettings/pages/person_lead_partner.rb b/app/models/form/lettings/pages/person_lead_partner.rb index 36f2e9b11..17d63149c 100644 --- a/app/models/form/lettings/pages/person_lead_partner.rb +++ b/app/models/form/lettings/pages/person_lead_partner.rb @@ -18,8 +18,11 @@ class Form::Lettings::Pages::PersonLeadPartner < ::Form::Page "operator" => ">=", "operand" => 16, }, + **(2...@person_index).map { |i| ["relat#{i}", { "operator" => "!=", "operand" => "P" }] }.to_h, }, - { "details_known_#{@person_index}" => 0, "age#{@person_index}" => nil }, + { "details_known_#{@person_index}" => 0, + "age#{@person_index}" => nil, + **(2...@person_index).map { |i| ["relat#{i}", { "operator" => "!=", "operand" => "P" }] }.to_h }, ] else [{ "details_known_#{@person_index}" => 0 }] diff --git a/app/models/form/lettings/questions/person_partner.rb b/app/models/form/lettings/questions/person_partner.rb index 98a22a448..cb6071614 100644 --- a/app/models/form/lettings/questions/person_partner.rb +++ b/app/models/form/lettings/questions/person_partner.rb @@ -7,6 +7,7 @@ class Form::Lettings::Questions::PersonPartner < ::Form::Question @answer_options = answer_options @person_index = person_index @question_number = question_number + @disable_clearing_if_not_routed_or_dynamic_answer_options = form.start_year_2026_or_later? end def answer_options @@ -31,4 +32,12 @@ class Form::Lettings::Questions::PersonPartner < ::Form::Question def derived?(log) form.start_year_2026_or_later? && log.is_partner_inferred?(@person_index) end + + def hidden_in_check_answers?(log, _current_user = nil) + if form.start_year_2026_or_later? + log.is_an_earlier_person_partner(@person_index) + else + false + end + end end diff --git a/app/models/form/lettings/subsections/household_characteristics.rb b/app/models/form/lettings/subsections/household_characteristics.rb index cfc53603e..ea9d6d78a 100644 --- a/app/models/form/lettings/subsections/household_characteristics.rb +++ b/app/models/form/lettings/subsections/household_characteristics.rb @@ -36,8 +36,8 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection 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.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::PartnerUnder16ValueCheck.new("relationship_2_partner_under_16_value_check", nil, self, person_index: 2) unless form.start_year_2026_or_later?), + (Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_2_multiple_partners_value_check", nil, self, person_index: 2) unless form.start_year_2026_or_later?), (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), @@ -45,7 +45,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection 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.start_year_2026_or_later?), + (Form::Lettings::Pages::PartnerUnder16ValueCheck.new("age_2_partner_under_16_value_check", nil, self, person_index: 2) unless form.start_year_2026_or_later?), (Form::Lettings::Pages::PersonSexRegisteredAtBirth.new(nil, nil, self, person_index: 2) if 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), @@ -59,8 +59,8 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection 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.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::PartnerUnder16ValueCheck.new("relationship_3_partner_under_16_value_check", nil, self, person_index: 3) unless form.start_year_2026_or_later?), + (Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_3_multiple_partners_value_check", nil, self, person_index: 3) unless form.start_year_2026_or_later?), (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), @@ -68,7 +68,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection 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.start_year_2026_or_later?), + (Form::Lettings::Pages::PartnerUnder16ValueCheck.new("age_3_partner_under_16_value_check", nil, self, person_index: 3) unless form.start_year_2026_or_later?), (Form::Lettings::Pages::PersonSexRegisteredAtBirth.new(nil, nil, self, person_index: 3) if 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), @@ -82,8 +82,8 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection 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.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::PartnerUnder16ValueCheck.new("relationship_4_partner_under_16_value_check", nil, self, person_index: 4) unless form.start_year_2026_or_later?), + (Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_4_multiple_partners_value_check", nil, self, person_index: 4) unless form.start_year_2026_or_later?), (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), @@ -91,7 +91,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection 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.start_year_2026_or_later?), + (Form::Lettings::Pages::PartnerUnder16ValueCheck.new("age_4_partner_under_16_value_check", nil, self, person_index: 4) unless form.start_year_2026_or_later?), (Form::Lettings::Pages::PersonSexRegisteredAtBirth.new(nil, nil, self, person_index: 4) if 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), @@ -105,8 +105,8 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection 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.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::PartnerUnder16ValueCheck.new("relationship_5_partner_under_16_value_check", nil, self, person_index: 5) unless form.start_year_2026_or_later?), + (Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_5_multiple_partners_value_check", nil, self, person_index: 5) unless form.start_year_2026_or_later?), (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), @@ -114,7 +114,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection 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.start_year_2026_or_later?), + (Form::Lettings::Pages::PartnerUnder16ValueCheck.new("age_5_partner_under_16_value_check", nil, self, person_index: 5) unless form.start_year_2026_or_later?), (Form::Lettings::Pages::PersonSexRegisteredAtBirth.new(nil, nil, self, person_index: 5) if 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), @@ -128,8 +128,8 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection 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.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::PartnerUnder16ValueCheck.new("relationship_6_partner_under_16_value_check", nil, self, person_index: 6) unless form.start_year_2026_or_later?), + (Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_6_multiple_partners_value_check", nil, self, person_index: 6) unless form.start_year_2026_or_later?), (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), @@ -137,7 +137,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection 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.start_year_2026_or_later?), + (Form::Lettings::Pages::PartnerUnder16ValueCheck.new("age_6_partner_under_16_value_check", nil, self, person_index: 6) unless form.start_year_2026_or_later?), (Form::Lettings::Pages::PersonSexRegisteredAtBirth.new(nil, nil, self, person_index: 6) if 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), @@ -151,8 +151,8 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection 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.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::PartnerUnder16ValueCheck.new("relationship_7_partner_under_16_value_check", nil, self, person_index: 7) unless form.start_year_2026_or_later?), + (Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_7_multiple_partners_value_check", nil, self, person_index: 7) unless form.start_year_2026_or_later?), (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), @@ -160,7 +160,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection 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.start_year_2026_or_later?), + (Form::Lettings::Pages::PartnerUnder16ValueCheck.new("age_7_partner_under_16_value_check", nil, self, person_index: 7) unless form.start_year_2026_or_later?), (Form::Lettings::Pages::PersonSexRegisteredAtBirth.new(nil, nil, self, person_index: 7) if 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), @@ -174,8 +174,8 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection 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.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::PartnerUnder16ValueCheck.new("relationship_8_partner_under_16_value_check", nil, self, person_index: 8) unless form.start_year_2026_or_later?), + (Form::Lettings::Pages::MultiplePartnersValueCheck.new("relationship_8_multiple_partners_value_check", nil, self, person_index: 8) unless form.start_year_2026_or_later?), (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), @@ -183,7 +183,7 @@ class Form::Lettings::Subsections::HouseholdCharacteristics < ::Form::Subsection 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.start_year_2026_or_later?), + (Form::Lettings::Pages::PartnerUnder16ValueCheck.new("age_8_partner_under_16_value_check", nil, self, person_index: 8) unless form.start_year_2026_or_later?), (Form::Lettings::Pages::PersonSexRegisteredAtBirth.new(nil, nil, self, person_index: 8) if 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), diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index f2230c4e5..e7e37b7b6 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -403,9 +403,19 @@ class LettingsLog < Log end def is_partner_inferred?(person_index) + is_person_under_16(person_index) || is_an_earlier_person_partner(person_index) + end + + def is_person_under_16(person_index) public_send("age#{person_index}") && public_send("age#{person_index}") < 16 end + def is_an_earlier_person_partner(person_index) + (2...person_index).any? do |i| + public_send("relat#{i}") == "P" + end + end + def age_changed_from_below_16(person_index) public_send("age#{person_index}_was") && public_send("age#{person_index}_was") < 16 end @@ -876,6 +886,10 @@ private end end + def partner_numbers + (2..8).select { |i| public_send("relat#{i}") == "P" } + end + def age_refused? [age1_known, age2_known, age3_known, age4_known, age5_known, age6_known, age7_known, age8_known].any?(1) end diff --git a/spec/features/form/page_routing_spec.rb b/spec/features/form/page_routing_spec.rb index 470a2f8ed..6e903ded3 100644 --- a/spec/features/form/page_routing_spec.rb +++ b/spec/features/form/page_routing_spec.rb @@ -270,6 +270,78 @@ RSpec.describe "Form Page Routing" do expect(lettings_log.form.depends_on_met(depends_on, lettings_log)).to eq(true) end + + describe "using the 'not equal to' operator" do + it "returns true if both values are non-nil and different" do + depends_on = [ + { + "relat2" => { + "operator" => "!=", + "operand" => "P", + }, + }, + ] + lettings_log.relat2 = "X" + + expect(lettings_log.form.depends_on_met(depends_on, lettings_log)).to eq(true) + end + + it "returns false if both values are non-nil and the same" do + depends_on = [ + { + "relat2" => { + "operator" => "!=", + "operand" => "P", + }, + }, + ] + lettings_log.relat2 = "P" + + expect(lettings_log.form.depends_on_met(depends_on, lettings_log)).to eq(false) + end + + it "returns true if the being tested is nil and the operand is non-nil" do + depends_on = [ + { + "relat2" => { + "operator" => "!=", + "operand" => "P", + }, + }, + ] + lettings_log.relat2 = nil + + expect(lettings_log.form.depends_on_met(depends_on, lettings_log)).to eq(true) + end + + it "returns true if the being tested is non-nil and the operand is nil" do + depends_on = [ + { + "relat2" => { + "operator" => "!=", + "operand" => nil, + }, + }, + ] + lettings_log.relat2 = "P" + + expect(lettings_log.form.depends_on_met(depends_on, lettings_log)).to eq(true) + end + + it "returns false if both values are nil" do + depends_on = [ + { + "relat2" => { + "operator" => "!=", + "operand" => nil, + }, + }, + ] + lettings_log.relat2 = nil + + expect(lettings_log.form.depends_on_met(depends_on, lettings_log)).to eq(false) + end + end end end diff --git a/spec/fixtures/files/lettings_log_csv_export_codes_26.csv b/spec/fixtures/files/lettings_log_csv_export_codes_26.csv index 2c2bb616a..bfd414d76 100644 --- a/spec/fixtures/files/lettings_log_csv_export_codes_26.csv +++ b/spec/fixtures/files/lettings_log_csv_export_codes_26.csv @@ -1,3 +1,3 @@ -Log ID,Status of log,ID of a set of duplicate logs,User the log is created by,User the log is assigned to,Is the user in the assigned_to column the data protection officer?,Time and date the log was created,User who last updated the log,Time and date the log was last updated,Was the log submitted in-service or via bulk upload?,Year collection period opened,ID of a set of bulk uploaded logs,Which organisation owns this property?,Which organisation manages this letting?,What is the needs type?,What is the letting type?,Is this letting a renewal?,What is the tenancy start date?,"What is the rent type? (grouped into SR, IR or AR)",What is the rent type?,Which type of Intermediate Rent is this letting?,Which 'Other' type of Intermediate Rent is this letting?,Is this a London Affordable Rent letting?,What is the tenant code?,What is the property reference?,Has the tenant seen the MHCLG privacy notice?,Is this the first time the property has been let as social housing?,What rent product was the property most recently let as?,What is the reason for the property being vacant?,Is this property new to the social rented sector?,"If known, property's UPRN",Address line 1,Address line 2,Town or City,County,Postcode,The internal value to indicate if the LA was inferred from the postcode,What is the property's local authority?,Local authority code,Is the UPRN known?,UPRN of the address selected,Was the 'No address found' page seen?,Address line 1 input from address matching feature,Postcode input from address matching feature,Address line 1 entered in bulk upload file,Address line 2 entered in bulk upload file,Town or city entered in bulk upload file,County entered in bulk upload file,Postcode entered in bulk upload file,Local authority entered in bulk upload file,What type of unit is the property?,Is the property built or adapted to wheelchair-user standards?,How many bedrooms does the property have?,What is the void date?,Number of days the property was vacant,The following soft validation was confirmed: You told us that the property has been vacant for more than 2 years. This is higher than we would expect.,Were any major repairs carried out during the void period?,What date were any major repairs completed on?,The following soft validation was confirmed: You told us the property has been vacant for 2 years. This is higher than we would expect.,Is this letting in sheltered accommodation?,Is this a joint tenancy?,Is this a starter tenancy?,What is the type of tenancy?,"If 'Other', what is the type of tenancy?",What is the length of the fixed-term tenancy to the nearest year?,How many people live in the household at this letting?,The following soft validation was confirmed: You told us somebody in the household is pregnant. You also told us there are no female tenants living at the property.,"Where household characteristics have a 'Refused' option for some or all of: AGE1-AGE8, SEX1-SEX8, RELAT2-RELAT8, ECSTAT1-ECSTAT8","Type of household 1 = 1 elder; 2 = 2 adults, including elder(s); 3 = 1 adult; 4 = 2 adults; 5 = 1 adult & 1+ children; 6 = 2+ adults & 1+ children; 9 = Other",Total number of dependent children in the household (Sum of when RELAT2-8 = C),Total number of elders in household (Sum of when AGE1-8 >= 60),Total number of adults in household,What is the lead tenant's age?,The following soft validation was confirmed: You told us this person is aged %{age} years and retired. The minimum expected retirement age for %{gender} in England is %{age}.,What was the lead tenant's sex at birth?,Which of these best describes the lead tenant's gender identity?,What is the lead tenant's ethnic group?,Which of these best describes the lead tenant's ethnic background?,What is the lead tenant's nationality?,Which of these best describes the lead tenant's working situation?,The following soft validation was confirmed: You have said that at least one person's situation is 'Unable to work because of long-term sickness or disability'.,Are the details of tenant 2 known?,What is person 2's age?,What is person 2's relationship to the lead tenant?,The following soft validation was confirmed: You said that more than one person in the household is the partner of the lead tenant. Are you sure this is correct?,What was person 2's sex at birth?,Which of these best describes person 2's gender identity?,Which of these best describes person 2's working situation?,Are the details of tenant 3 known?,What is person 3's age?,What is person 3's relationship to the lead tenant?,What was person 3's sex at birth?,Which of these best describes person 3's gender identity?,Which of these best describes person 3's working situation?,Are the details of tenant 4 known?,What is person 4's age?,What is person 4's relationship to the lead tenant?,What was person 4's sex at birth?,Which of these best describes person 4's gender identity?,Which of these best describes person 4's working situation?,Are the details of tenant 5 known?,What is person 5's age?,What is person 5's relationship to the lead tenant?,What was person 5's sex at birth?,Which of these best describes person 5's gender identity?,Which of these best describes person 5's working situation?,Are the details of tenant 6 known?,What is person 6's age?,What is person 6's relationship to the lead tenant?,What was person 6's sex at birth?,Which of these best describes person 6's gender identity?,Which of these best describes person 6's working situation?,Are the details of tenant 7 known?,What is person 7's age?,What is person 7's relationship to the lead tenant?,What was person 7's sex at birth?,Which of these best describes person 7's gender identity?,Which of these best describes person 7's working situation?,Are the details of tenant 8 known?,What is person 8's age?,What is person 8's relationship to the lead tenant?,What was person 8's sex at birth?,Which of these best describes person 8's gender identity?,Which of these best describes person 8's working situation?,Does anybody in the household have links to the UK armed forces?,Is this person still serving in the UK armed forces?,Was this person seriously injured or ill as a result of serving in the UK armed forces?,Is anybody in the household pregnant?,Does anybody in the household have any disabled access needs?,"What access needs do they have? (Fully wheelchair-accessible housing, Level access housing or Wheelchair access to essential rooms)",Disabled access needs a) Fully wheelchair-accessible housing,Disabled access needs b) Wheelchair access to essential rooms,Disabled access needs c) Level access housing,Disabled access needs f) Other disabled access needs,Disabled access needs g) No disabled access needs,Disabled access needs h) Don't know,Do they have any other disabled access needs?,Does anybody in the household have a physical or mental health condition (or other illness) expected to last 12 months or more?,Does this person's condition affect their dexterity?,Does this person's condition affect their learning or understanding or concentrating?,Does this person's condition affect their hearing?,Does this person's condition affect their memory?,Does this person's condition affect their mental health?,Does this person's condition affect their mobility?,Does this person's condition affect them socially or behaviourally?,Does this person's condition affect their stamina or breathing or fatigue?,Does this person's condition affect their vision?,Does this person's condition affect them in another way?,How long has the household continuously lived in the local authority area of the new letting?,How long has the household been on the local authority waiting list for the new letting?,What is the tenant's main reason for the household leaving their last settled home?,"If 'Other', what was the main reason for leaving their last settled home?",The soft validation was confirmed,Where was the household immediately before this letting?,Did the household experience homelessness immediately before this letting?,Previous postcode unknown or previous accommodation was temporary,What is the postcode of the household's last settled home?,Was the local authority of the household's last settled home known?,The internal value to indicate if the previous LA was inferred from the postcode,Previous location LA name,Previous location's ONS LA Code,Was the household given reasonable preference by the local authority?,Reasonable preference reason - They were homeless or about to lose their home (within 56 days),"Reasonable preference reason - They were living in insanitary, overcrowded or unisatisfactory housing",Reasonable preference reason - They needed to move on medical and welfare reasons (including disability),Reasonable preference reason - They needed to move to avoid hardship to themselves or others,Reasonable preference reason - Don't Know,Was the letting made under Choice-Based Lettings (CBL)?,Was the letting made under the Common Allocation Policy (CAP)?,Was the letting made under the Common Housing Register (CHR)?,Was the letting made under the Accessible Register?,"The letting was not allocated under CBL, CAP, CHR or Accessible Register.",,What was the source of referral for this letting?,"The following soft validation was confirmed: Are you sure? This is a general needs log, and this referral type is for supported housing.",Do you know the household's combined income after tax?,Was the household income refused?,How often does the household receive income?,How much income does the household have in total?,Populated when someone hits the soft validation and confirmed in the service,Is the tenant likely to be receiving any of these housing-related benefits?,"Does the tenant receive housing-related benefits? Yes if hb = Universal Credit housing element or Housing benefit, No if hb = Don't Know, Neither, Tenant prefers not to say or blank","How much of the household's income is from Universal Credit, state pensions or benefits?",Does the household pay rent or other charges for the accommodation?,Does the household pay rent or other charges for the accommodation? - flag for when household_charge is answered no,How often does the household pay rent and other charges?,What is the basic rent?,Weekly rent,Populated when the soft validation and confirmed in the service,What is the service charge?,Weekly service charge,What is the personal service charge?,Weekly personal service charge,What is the support charge?,Weekly support charge,Total charge to the tenant,Weekly total charge to the tenant,Populated when the soft validation and confirmed in the service,Populated when the soft validation and confirmed in the service,Populated when the soft validation and confirmed in the service,"After the household has received any housing-related benefits, will they still need to pay for rent and charges?",Can you estimate the outstanding amount?,Estimated outstanding amount,Weekly total rent shortfall charge for tenant receiving housing benefit,What scheme does this letting belong to?,"From scheme code, we map to the scheme name",Does the scheme contain confidential information?,"What is this type of scheme? (Direct access hostel), Foyer, Housing for older people or Other supported housing",Is this scheme registered under the Care Standards Act 2000?,Which organisation owns the housing stock for this scheme?,What client group is this scheme intended for?,Does this scheme provide for another client group?,What is the other client group?,What support does this scheme provide?,Intended length of stay,Date scheme was created,Which location is this letting for?,What is the postcode for this location?,What is the name of this location?,How many units are at this location?,What is the most common type of unit at this location?,What are the mobility standards for the majority of the units in this location?,What is the local authority of this postcode?,When did the first property in this location become available under this scheme? -id,status,duplicate_set_id,created_by,assigned_to,is_dpo,created_at,updated_by,updated_at,creation_method,collection_start_year,bulk_upload_id,owning_organisation_name,managing_organisation_name,needstype,lettype,renewal,startdate,renttype,renttype_detail,irproduct,irproduct_other,lar,tenancycode,propcode,declaration,first_time_property_let_as_social_housing,unitletas,rsnvac,newprop,uprn,address_line1,address_line2,town_or_city,county,postcode_full,is_la_inferred,la_label,la,uprn_known,uprn_selection,address_search_value_check,address_line1_input,postcode_full_input,address_line1_as_entered,address_line2_as_entered,town_or_city_as_entered,county_as_entered,postcode_full_as_entered,la_as_entered,unittype_gn,wchair,beds,voiddate,vacdays,void_date_value_check,majorrepairs,mrcdate,major_repairs_date_value_check,sheltered,joint,startertenancy,tenancy,tenancyother,tenancylength,hhmemb,pregnancy_value_check,refused,hhtype,totchild,totelder,totadult,age1,retirement_value_check,sexrab1,sex1,ethnic_group,ethnic,nationality_all,ecstat1,working_situation_illness_check,details_known_2,age2,relat2,multiple_partners_value_check,sexrab2,sex2,ecstat2,details_known_3,age3,relat3,sexrab3,sex3,ecstat3,details_known_4,age4,relat4,sexrab4,sex4,ecstat4,details_known_5,age5,relat5,sexrab5,sex5,ecstat5,details_known_6,age6,relat6,sexrab6,sex6,ecstat6,details_known_7,age7,relat7,sexrab7,sex7,ecstat7,details_known_8,age8,relat8,sexrab8,sex8,ecstat8,armedforces,leftreg,reservist,preg_occ,housingneeds,housingneeds_type,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,housingneeds_other,illness,illness_type_4,illness_type_5,illness_type_2,illness_type_6,illness_type_7,illness_type_3,illness_type_9,illness_type_8,illness_type_1,illness_type_10,layear,waityear,reason,reasonother,reasonother_value_check,prevten,homeless,ppcodenk,ppostcode_full,previous_la_known,is_previous_la_inferred,prevloc_label,prevloc,reasonpref,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,cbl,cap,chr,accessible_register,letting_allocation_none,referral_type,referral,referral_value_check,net_income_known,incref,incfreq,earnings,net_income_value_check,hb,has_benefits,benefits,household_charge,nocharge,period,brent,wrent,rent_value_check,scharge,wscharge,pscharge,wpschrge,supcharg,wsupchrg,tcharge,wtcharge,scharge_value_check,pscharge_value_check,supcharg_value_check,hbrentshortfall,tshortfall_known,tshortfall,wtshortfall,scheme_code,scheme_service_name,scheme_confidential,SCHTYPE,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,location_code,location_postcode,location_name,location_units,location_type_of_unit,location_mobility_type,location_local_authority,location_startdate -,in_progress,,s.port@jeemayle.com,s.port@jeemayle.com,false,2026-04-01T00:00:00+01:00,,2026-04-01T00:00:00+01:00,1,2026,,MHCLG,MHCLG,1,7,0,2026-04-01,2,2,,,2,HIJKLMN,ABCDEFG,1,0,2,6,2,,Address line 1,,London,,NW9 5LL,false,Barnet,E09000003,0,,,,,address line 1 as entered,address line 2 as entered,town or city as entered,county as entered,AB1 2CD,la as entered,7,1,3,2026-03-30,1,,1,2026-03-31,,,3,1,4,,2,4,,1,4,0,0,2,35,,F,F,0,2,36,0,,0,32,P,,M,M,6,1,-9,R,R,R,10,0,-9,R,R,R,10,,,,,,,,,,,,,,,,,,,,,,,,,1,4,1,2,1,0,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,2,7,4,,,6,1,0,TN23 6LZ,1,false,Ashford,E07000105,1,0,1,0,0,0,0,0,1,0,0,,,,0,0,1,268,,6,1,1,,,2,200.0,100.0,,50.0,25.0,40.0,20.0,35.0,17.5,325.0,162.5,,,,1,0,12.0,6.0,,,,,,,,,,,,,,,,,,,, +Log ID,Status of log,ID of a set of duplicate logs,User the log is created by,User the log is assigned to,Is the user in the assigned_to column the data protection officer?,Time and date the log was created,User who last updated the log,Time and date the log was last updated,Was the log submitted in-service or via bulk upload?,Year collection period opened,ID of a set of bulk uploaded logs,Which organisation owns this property?,Which organisation manages this letting?,What is the needs type?,What is the letting type?,Is this letting a renewal?,What is the tenancy start date?,"What is the rent type? (grouped into SR, IR or AR)",What is the rent type?,Which type of Intermediate Rent is this letting?,Which 'Other' type of Intermediate Rent is this letting?,Is this a London Affordable Rent letting?,What is the tenant code?,What is the property reference?,Has the tenant seen the MHCLG privacy notice?,Is this the first time the property has been let as social housing?,What rent product was the property most recently let as?,What is the reason for the property being vacant?,Is this property new to the social rented sector?,"If known, property's UPRN",Address line 1,Address line 2,Town or City,County,Postcode,The internal value to indicate if the LA was inferred from the postcode,What is the property's local authority?,Local authority code,Is the UPRN known?,UPRN of the address selected,Was the 'No address found' page seen?,Address line 1 input from address matching feature,Postcode input from address matching feature,Address line 1 entered in bulk upload file,Address line 2 entered in bulk upload file,Town or city entered in bulk upload file,County entered in bulk upload file,Postcode entered in bulk upload file,Local authority entered in bulk upload file,What type of unit is the property?,Is the property built or adapted to wheelchair-user standards?,How many bedrooms does the property have?,What is the void date?,Number of days the property was vacant,The following soft validation was confirmed: You told us that the property has been vacant for more than 2 years. This is higher than we would expect.,Were any major repairs carried out during the void period?,What date were any major repairs completed on?,The following soft validation was confirmed: You told us the property has been vacant for 2 years. This is higher than we would expect.,Is this letting in sheltered accommodation?,Is this a joint tenancy?,Is this a starter tenancy?,What is the type of tenancy?,"If 'Other', what is the type of tenancy?",What is the length of the fixed-term tenancy to the nearest year?,How many people live in the household at this letting?,The following soft validation was confirmed: You told us somebody in the household is pregnant. You also told us there are no female tenants living at the property.,"Where household characteristics have a 'Refused' option for some or all of: AGE1-AGE8, SEX1-SEX8, RELAT2-RELAT8, ECSTAT1-ECSTAT8","Type of household 1 = 1 elder; 2 = 2 adults, including elder(s); 3 = 1 adult; 4 = 2 adults; 5 = 1 adult & 1+ children; 6 = 2+ adults & 1+ children; 9 = Other",Total number of dependent children in the household (Sum of when RELAT2-8 = C),Total number of elders in household (Sum of when AGE1-8 >= 60),Total number of adults in household,What is the lead tenant's age?,The following soft validation was confirmed: You told us this person is aged %{age} years and retired. The minimum expected retirement age for %{gender} in England is %{age}.,What was the lead tenant's sex at birth?,Which of these best describes the lead tenant's gender identity?,What is the lead tenant's ethnic group?,Which of these best describes the lead tenant's ethnic background?,What is the lead tenant's nationality?,Which of these best describes the lead tenant's working situation?,The following soft validation was confirmed: You have said that at least one person's situation is 'Unable to work because of long-term sickness or disability'.,Are the details of tenant 2 known?,What is person 2's age?,What is person 2's relationship to the lead tenant?,What was person 2's sex at birth?,Which of these best describes person 2's gender identity?,Which of these best describes person 2's working situation?,Are the details of tenant 3 known?,What is person 3's age?,What is person 3's relationship to the lead tenant?,What was person 3's sex at birth?,Which of these best describes person 3's gender identity?,Which of these best describes person 3's working situation?,Are the details of tenant 4 known?,What is person 4's age?,What is person 4's relationship to the lead tenant?,What was person 4's sex at birth?,Which of these best describes person 4's gender identity?,Which of these best describes person 4's working situation?,Are the details of tenant 5 known?,What is person 5's age?,What is person 5's relationship to the lead tenant?,What was person 5's sex at birth?,Which of these best describes person 5's gender identity?,Which of these best describes person 5's working situation?,Are the details of tenant 6 known?,What is person 6's age?,What is person 6's relationship to the lead tenant?,What was person 6's sex at birth?,Which of these best describes person 6's gender identity?,Which of these best describes person 6's working situation?,Are the details of tenant 7 known?,What is person 7's age?,What is person 7's relationship to the lead tenant?,What was person 7's sex at birth?,Which of these best describes person 7's gender identity?,Which of these best describes person 7's working situation?,Are the details of tenant 8 known?,What is person 8's age?,What is person 8's relationship to the lead tenant?,What was person 8's sex at birth?,Which of these best describes person 8's gender identity?,Which of these best describes person 8's working situation?,Does anybody in the household have links to the UK armed forces?,Is this person still serving in the UK armed forces?,Was this person seriously injured or ill as a result of serving in the UK armed forces?,Is anybody in the household pregnant?,Does anybody in the household have any disabled access needs?,"What access needs do they have? (Fully wheelchair-accessible housing, Level access housing or Wheelchair access to essential rooms)",Disabled access needs a) Fully wheelchair-accessible housing,Disabled access needs b) Wheelchair access to essential rooms,Disabled access needs c) Level access housing,Disabled access needs f) Other disabled access needs,Disabled access needs g) No disabled access needs,Disabled access needs h) Don't know,Do they have any other disabled access needs?,Does anybody in the household have a physical or mental health condition (or other illness) expected to last 12 months or more?,Does this person's condition affect their dexterity?,Does this person's condition affect their learning or understanding or concentrating?,Does this person's condition affect their hearing?,Does this person's condition affect their memory?,Does this person's condition affect their mental health?,Does this person's condition affect their mobility?,Does this person's condition affect them socially or behaviourally?,Does this person's condition affect their stamina or breathing or fatigue?,Does this person's condition affect their vision?,Does this person's condition affect them in another way?,How long has the household continuously lived in the local authority area of the new letting?,How long has the household been on the local authority waiting list for the new letting?,What is the tenant's main reason for the household leaving their last settled home?,"If 'Other', what was the main reason for leaving their last settled home?",The soft validation was confirmed,Where was the household immediately before this letting?,Did the household experience homelessness immediately before this letting?,Previous postcode unknown or previous accommodation was temporary,What is the postcode of the household's last settled home?,Was the local authority of the household's last settled home known?,The internal value to indicate if the previous LA was inferred from the postcode,Previous location LA name,Previous location's ONS LA Code,Was the household given reasonable preference by the local authority?,Reasonable preference reason - They were homeless or about to lose their home (within 56 days),"Reasonable preference reason - They were living in insanitary, overcrowded or unisatisfactory housing",Reasonable preference reason - They needed to move on medical and welfare reasons (including disability),Reasonable preference reason - They needed to move to avoid hardship to themselves or others,Reasonable preference reason - Don't Know,Was the letting made under Choice-Based Lettings (CBL)?,Was the letting made under the Common Allocation Policy (CAP)?,Was the letting made under the Common Housing Register (CHR)?,Was the letting made under the Accessible Register?,"The letting was not allocated under CBL, CAP, CHR or Accessible Register.",,What was the source of referral for this letting?,"The following soft validation was confirmed: Are you sure? This is a general needs log, and this referral type is for supported housing.",Do you know the household's combined income after tax?,Was the household income refused?,How often does the household receive income?,How much income does the household have in total?,Populated when someone hits the soft validation and confirmed in the service,Is the tenant likely to be receiving any of these housing-related benefits?,"Does the tenant receive housing-related benefits? Yes if hb = Universal Credit housing element or Housing benefit, No if hb = Don't Know, Neither, Tenant prefers not to say or blank","How much of the household's income is from Universal Credit, state pensions or benefits?",Does the household pay rent or other charges for the accommodation?,Does the household pay rent or other charges for the accommodation? - flag for when household_charge is answered no,How often does the household pay rent and other charges?,What is the basic rent?,Weekly rent,Populated when the soft validation and confirmed in the service,What is the service charge?,Weekly service charge,What is the personal service charge?,Weekly personal service charge,What is the support charge?,Weekly support charge,Total charge to the tenant,Weekly total charge to the tenant,Populated when the soft validation and confirmed in the service,Populated when the soft validation and confirmed in the service,Populated when the soft validation and confirmed in the service,"After the household has received any housing-related benefits, will they still need to pay for rent and charges?",Can you estimate the outstanding amount?,Estimated outstanding amount,Weekly total rent shortfall charge for tenant receiving housing benefit,What scheme does this letting belong to?,"From scheme code, we map to the scheme name",Does the scheme contain confidential information?,"What is this type of scheme? (Direct access hostel), Foyer, Housing for older people or Other supported housing",Is this scheme registered under the Care Standards Act 2000?,Which organisation owns the housing stock for this scheme?,What client group is this scheme intended for?,Does this scheme provide for another client group?,What is the other client group?,What support does this scheme provide?,Intended length of stay,Date scheme was created,Which location is this letting for?,What is the postcode for this location?,What is the name of this location?,How many units are at this location?,What is the most common type of unit at this location?,What are the mobility standards for the majority of the units in this location?,What is the local authority of this postcode?,When did the first property in this location become available under this scheme? +id,status,duplicate_set_id,created_by,assigned_to,is_dpo,created_at,updated_by,updated_at,creation_method,collection_start_year,bulk_upload_id,owning_organisation_name,managing_organisation_name,needstype,lettype,renewal,startdate,renttype,renttype_detail,irproduct,irproduct_other,lar,tenancycode,propcode,declaration,first_time_property_let_as_social_housing,unitletas,rsnvac,newprop,uprn,address_line1,address_line2,town_or_city,county,postcode_full,is_la_inferred,la_label,la,uprn_known,uprn_selection,address_search_value_check,address_line1_input,postcode_full_input,address_line1_as_entered,address_line2_as_entered,town_or_city_as_entered,county_as_entered,postcode_full_as_entered,la_as_entered,unittype_gn,wchair,beds,voiddate,vacdays,void_date_value_check,majorrepairs,mrcdate,major_repairs_date_value_check,sheltered,joint,startertenancy,tenancy,tenancyother,tenancylength,hhmemb,pregnancy_value_check,refused,hhtype,totchild,totelder,totadult,age1,retirement_value_check,sexrab1,sex1,ethnic_group,ethnic,nationality_all,ecstat1,working_situation_illness_check,details_known_2,age2,relat2,sexrab2,sex2,ecstat2,details_known_3,age3,relat3,sexrab3,sex3,ecstat3,details_known_4,age4,relat4,sexrab4,sex4,ecstat4,details_known_5,age5,relat5,sexrab5,sex5,ecstat5,details_known_6,age6,relat6,sexrab6,sex6,ecstat6,details_known_7,age7,relat7,sexrab7,sex7,ecstat7,details_known_8,age8,relat8,sexrab8,sex8,ecstat8,armedforces,leftreg,reservist,preg_occ,housingneeds,housingneeds_type,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,housingneeds_other,illness,illness_type_4,illness_type_5,illness_type_2,illness_type_6,illness_type_7,illness_type_3,illness_type_9,illness_type_8,illness_type_1,illness_type_10,layear,waityear,reason,reasonother,reasonother_value_check,prevten,homeless,ppcodenk,ppostcode_full,previous_la_known,is_previous_la_inferred,prevloc_label,prevloc,reasonpref,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,cbl,cap,chr,accessible_register,letting_allocation_none,referral_type,referral,referral_value_check,net_income_known,incref,incfreq,earnings,net_income_value_check,hb,has_benefits,benefits,household_charge,nocharge,period,brent,wrent,rent_value_check,scharge,wscharge,pscharge,wpschrge,supcharg,wsupchrg,tcharge,wtcharge,scharge_value_check,pscharge_value_check,supcharg_value_check,hbrentshortfall,tshortfall_known,tshortfall,wtshortfall,scheme_code,scheme_service_name,scheme_confidential,SCHTYPE,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,location_code,location_postcode,location_name,location_units,location_type_of_unit,location_mobility_type,location_local_authority,location_startdate +,in_progress,,s.port@jeemayle.com,s.port@jeemayle.com,false,2026-04-01T00:00:00+01:00,,2026-04-01T00:00:00+01:00,1,2026,,MHCLG,MHCLG,1,7,0,2026-04-01,2,2,,,2,HIJKLMN,ABCDEFG,1,0,2,6,2,,Address line 1,,London,,NW9 5LL,false,Barnet,E09000003,0,,,,,address line 1 as entered,address line 2 as entered,town or city as entered,county as entered,AB1 2CD,la as entered,7,1,3,2026-03-30,1,,1,2026-03-31,,,3,1,4,,2,4,,1,4,0,0,2,35,,F,F,0,2,36,0,,0,32,P,M,M,6,1,-9,R,R,R,10,0,-9,R,R,R,10,,,,,,,,,,,,,,,,,,,,,,,,,1,4,1,2,1,0,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,2,7,4,,,6,1,0,TN23 6LZ,1,false,Ashford,E07000105,1,0,1,0,0,0,0,0,1,0,0,,,,0,0,1,268,,6,1,1,,,2,200.0,100.0,,50.0,25.0,40.0,20.0,35.0,17.5,325.0,162.5,,,,1,0,12.0,6.0,,,,,,,,,,,,,,,,,,,, diff --git a/spec/fixtures/files/lettings_log_csv_export_labels_26.csv b/spec/fixtures/files/lettings_log_csv_export_labels_26.csv index f771b4d60..969b38560 100644 --- a/spec/fixtures/files/lettings_log_csv_export_labels_26.csv +++ b/spec/fixtures/files/lettings_log_csv_export_labels_26.csv @@ -1,3 +1,3 @@ -Log ID,Status of log,ID of a set of duplicate logs,User the log is created by,User the log is assigned to,Is the user in the assigned_to column the data protection officer?,Time and date the log was created,User who last updated the log,Time and date the log was last updated,Was the log submitted in-service or via bulk upload?,Year collection period opened,ID of a set of bulk uploaded logs,Which organisation owns this property?,Which organisation manages this letting?,What is the needs type?,What is the letting type?,Is this letting a renewal?,What is the tenancy start date?,"What is the rent type? (grouped into SR, IR or AR)",What is the rent type?,Which type of Intermediate Rent is this letting?,Which 'Other' type of Intermediate Rent is this letting?,Is this a London Affordable Rent letting?,What is the tenant code?,What is the property reference?,Has the tenant seen the MHCLG privacy notice?,Is this the first time the property has been let as social housing?,What rent product was the property most recently let as?,What is the reason for the property being vacant?,Is this property new to the social rented sector?,"If known, property's UPRN",Address line 1,Address line 2,Town or City,County,Postcode,The internal value to indicate if the LA was inferred from the postcode,What is the property's local authority?,Local authority code,Is the UPRN known?,UPRN of the address selected,Was the 'No address found' page seen?,Address line 1 input from address matching feature,Postcode input from address matching feature,Address line 1 entered in bulk upload file,Address line 2 entered in bulk upload file,Town or city entered in bulk upload file,County entered in bulk upload file,Postcode entered in bulk upload file,Local authority entered in bulk upload file,What type of unit is the property?,Is the property built or adapted to wheelchair-user standards?,How many bedrooms does the property have?,What is the void date?,Number of days the property was vacant,The following soft validation was confirmed: You told us that the property has been vacant for more than 2 years. This is higher than we would expect.,Were any major repairs carried out during the void period?,What date were any major repairs completed on?,The following soft validation was confirmed: You told us the property has been vacant for 2 years. This is higher than we would expect.,Is this letting in sheltered accommodation?,Is this a joint tenancy?,Is this a starter tenancy?,What is the type of tenancy?,"If 'Other', what is the type of tenancy?",What is the length of the fixed-term tenancy to the nearest year?,How many people live in the household at this letting?,The following soft validation was confirmed: You told us somebody in the household is pregnant. You also told us there are no female tenants living at the property.,"Where household characteristics have a 'Refused' option for some or all of: AGE1-AGE8, SEX1-SEX8, RELAT2-RELAT8, ECSTAT1-ECSTAT8","Type of household 1 = 1 elder; 2 = 2 adults, including elder(s); 3 = 1 adult; 4 = 2 adults; 5 = 1 adult & 1+ children; 6 = 2+ adults & 1+ children; 9 = Other",Total number of dependent children in the household (Sum of when RELAT2-8 = C),Total number of elders in household (Sum of when AGE1-8 >= 60),Total number of adults in household,What is the lead tenant's age?,The following soft validation was confirmed: You told us this person is aged %{age} years and retired. The minimum expected retirement age for %{gender} in England is %{age}.,What was the lead tenant's sex at birth?,Which of these best describes the lead tenant's gender identity?,What is the lead tenant's ethnic group?,Which of these best describes the lead tenant's ethnic background?,What is the lead tenant's nationality?,Which of these best describes the lead tenant's working situation?,The following soft validation was confirmed: You have said that at least one person's situation is 'Unable to work because of long-term sickness or disability'.,Are the details of tenant 2 known?,What is person 2's age?,What is person 2's relationship to the lead tenant?,The following soft validation was confirmed: You said that more than one person in the household is the partner of the lead tenant. Are you sure this is correct?,What was person 2's sex at birth?,Which of these best describes person 2's gender identity?,Which of these best describes person 2's working situation?,Are the details of tenant 3 known?,What is person 3's age?,What is person 3's relationship to the lead tenant?,What was person 3's sex at birth?,Which of these best describes person 3's gender identity?,Which of these best describes person 3's working situation?,Are the details of tenant 4 known?,What is person 4's age?,What is person 4's relationship to the lead tenant?,What was person 4's sex at birth?,Which of these best describes person 4's gender identity?,Which of these best describes person 4's working situation?,Are the details of tenant 5 known?,What is person 5's age?,What is person 5's relationship to the lead tenant?,What was person 5's sex at birth?,Which of these best describes person 5's gender identity?,Which of these best describes person 5's working situation?,Are the details of tenant 6 known?,What is person 6's age?,What is person 6's relationship to the lead tenant?,What was person 6's sex at birth?,Which of these best describes person 6's gender identity?,Which of these best describes person 6's working situation?,Are the details of tenant 7 known?,What is person 7's age?,What is person 7's relationship to the lead tenant?,What was person 7's sex at birth?,Which of these best describes person 7's gender identity?,Which of these best describes person 7's working situation?,Are the details of tenant 8 known?,What is person 8's age?,What is person 8's relationship to the lead tenant?,What was person 8's sex at birth?,Which of these best describes person 8's gender identity?,Which of these best describes person 8's working situation?,Does anybody in the household have links to the UK armed forces?,Is this person still serving in the UK armed forces?,Was this person seriously injured or ill as a result of serving in the UK armed forces?,Is anybody in the household pregnant?,Does anybody in the household have any disabled access needs?,"What access needs do they have? (Fully wheelchair-accessible housing, Level access housing or Wheelchair access to essential rooms)",Disabled access needs a) Fully wheelchair-accessible housing,Disabled access needs b) Wheelchair access to essential rooms,Disabled access needs c) Level access housing,Disabled access needs f) Other disabled access needs,Disabled access needs g) No disabled access needs,Disabled access needs h) Don't know,Do they have any other disabled access needs?,Does anybody in the household have a physical or mental health condition (or other illness) expected to last 12 months or more?,Does this person's condition affect their dexterity?,Does this person's condition affect their learning or understanding or concentrating?,Does this person's condition affect their hearing?,Does this person's condition affect their memory?,Does this person's condition affect their mental health?,Does this person's condition affect their mobility?,Does this person's condition affect them socially or behaviourally?,Does this person's condition affect their stamina or breathing or fatigue?,Does this person's condition affect their vision?,Does this person's condition affect them in another way?,How long has the household continuously lived in the local authority area of the new letting?,How long has the household been on the local authority waiting list for the new letting?,What is the tenant's main reason for the household leaving their last settled home?,"If 'Other', what was the main reason for leaving their last settled home?",The soft validation was confirmed,Where was the household immediately before this letting?,Did the household experience homelessness immediately before this letting?,Previous postcode unknown or previous accommodation was temporary,What is the postcode of the household's last settled home?,Was the local authority of the household's last settled home known?,The internal value to indicate if the previous LA was inferred from the postcode,Previous location LA name,Previous location's ONS LA Code,Was the household given reasonable preference by the local authority?,Reasonable preference reason - They were homeless or about to lose their home (within 56 days),"Reasonable preference reason - They were living in insanitary, overcrowded or unisatisfactory housing",Reasonable preference reason - They needed to move on medical and welfare reasons (including disability),Reasonable preference reason - They needed to move to avoid hardship to themselves or others,Reasonable preference reason - Don't Know,Was the letting made under Choice-Based Lettings (CBL)?,Was the letting made under the Common Allocation Policy (CAP)?,Was the letting made under the Common Housing Register (CHR)?,Was the letting made under the Accessible Register?,"The letting was not allocated under CBL, CAP, CHR or Accessible Register.",,What was the source of referral for this letting?,"The following soft validation was confirmed: Are you sure? This is a general needs log, and this referral type is for supported housing.",Do you know the household's combined income after tax?,Was the household income refused?,How often does the household receive income?,How much income does the household have in total?,Populated when someone hits the soft validation and confirmed in the service,Is the tenant likely to be receiving any of these housing-related benefits?,"Does the tenant receive housing-related benefits? Yes if hb = Universal Credit housing element or Housing benefit, No if hb = Don't Know, Neither, Tenant prefers not to say or blank","How much of the household's income is from Universal Credit, state pensions or benefits?",Does the household pay rent or other charges for the accommodation?,Does the household pay rent or other charges for the accommodation? - flag for when household_charge is answered no,How often does the household pay rent and other charges?,What is the basic rent?,Weekly rent,Populated when the soft validation and confirmed in the service,What is the service charge?,Weekly service charge,What is the personal service charge?,Weekly personal service charge,What is the support charge?,Weekly support charge,Total charge to the tenant,Weekly total charge to the tenant,Populated when the soft validation and confirmed in the service,Populated when the soft validation and confirmed in the service,Populated when the soft validation and confirmed in the service,"After the household has received any housing-related benefits, will they still need to pay for rent and charges?",Can you estimate the outstanding amount?,Estimated outstanding amount,Weekly total rent shortfall charge for tenant receiving housing benefit,What scheme does this letting belong to?,"From scheme code, we map to the scheme name",Does the scheme contain confidential information?,"What is this type of scheme? (Direct access hostel), Foyer, Housing for older people or Other supported housing",Is this scheme registered under the Care Standards Act 2000?,Which organisation owns the housing stock for this scheme?,What client group is this scheme intended for?,Does this scheme provide for another client group?,What is the other client group?,What support does this scheme provide?,Intended length of stay,Date scheme was created,Which location is this letting for?,What is the postcode for this location?,What is the name of this location?,How many units are at this location?,What is the most common type of unit at this location?,What are the mobility standards for the majority of the units in this location?,What is the local authority of this postcode?,When did the first property in this location become available under this scheme? -id,status,duplicate_set_id,created_by,assigned_to,is_dpo,created_at,updated_by,updated_at,creation_method,collection_start_year,bulk_upload_id,owning_organisation_name,managing_organisation_name,needstype,lettype,renewal,startdate,renttype,renttype_detail,irproduct,irproduct_other,lar,tenancycode,propcode,declaration,first_time_property_let_as_social_housing,unitletas,rsnvac,newprop,uprn,address_line1,address_line2,town_or_city,county,postcode_full,is_la_inferred,la_label,la,uprn_known,uprn_selection,address_search_value_check,address_line1_input,postcode_full_input,address_line1_as_entered,address_line2_as_entered,town_or_city_as_entered,county_as_entered,postcode_full_as_entered,la_as_entered,unittype_gn,wchair,beds,voiddate,vacdays,void_date_value_check,majorrepairs,mrcdate,major_repairs_date_value_check,sheltered,joint,startertenancy,tenancy,tenancyother,tenancylength,hhmemb,pregnancy_value_check,refused,hhtype,totchild,totelder,totadult,age1,retirement_value_check,sexrab1,sex1,ethnic_group,ethnic,nationality_all,ecstat1,working_situation_illness_check,details_known_2,age2,relat2,multiple_partners_value_check,sexrab2,sex2,ecstat2,details_known_3,age3,relat3,sexrab3,sex3,ecstat3,details_known_4,age4,relat4,sexrab4,sex4,ecstat4,details_known_5,age5,relat5,sexrab5,sex5,ecstat5,details_known_6,age6,relat6,sexrab6,sex6,ecstat6,details_known_7,age7,relat7,sexrab7,sex7,ecstat7,details_known_8,age8,relat8,sexrab8,sex8,ecstat8,armedforces,leftreg,reservist,preg_occ,housingneeds,housingneeds_type,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,housingneeds_other,illness,illness_type_4,illness_type_5,illness_type_2,illness_type_6,illness_type_7,illness_type_3,illness_type_9,illness_type_8,illness_type_1,illness_type_10,layear,waityear,reason,reasonother,reasonother_value_check,prevten,homeless,ppcodenk,ppostcode_full,previous_la_known,is_previous_la_inferred,prevloc_label,prevloc,reasonpref,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,cbl,cap,chr,accessible_register,letting_allocation_none,referral_type,referral,referral_value_check,net_income_known,incref,incfreq,earnings,net_income_value_check,hb,has_benefits,benefits,household_charge,nocharge,period,brent,wrent,rent_value_check,scharge,wscharge,pscharge,wpschrge,supcharg,wsupchrg,tcharge,wtcharge,scharge_value_check,pscharge_value_check,supcharg_value_check,hbrentshortfall,tshortfall_known,tshortfall,wtshortfall,scheme_code,scheme_service_name,scheme_confidential,SCHTYPE,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,location_code,location_postcode,location_name,location_units,location_type_of_unit,location_mobility_type,location_local_authority,location_startdate -,in_progress,,s.port@jeemayle.com,s.port@jeemayle.com,false,2026-04-01T00:00:00+01:00,,2026-04-01T00:00:00+01:00,single log,2026,,MHCLG,MHCLG,General needs,Affordable rent general needs local authority,No,2026-04-01,Affordable Rent,Affordable Rent,,,No,HIJKLMN,ABCDEFG,Yes,No,Affordable rent basis,Tenant abandoned property,No,,Address line 1,,London,,NW9 5LL,No,Barnet,E09000003,No,,,,,address line 1 as entered,address line 2 as entered,town or city as entered,county as entered,AB1 2CD,la as entered,House,Yes,3,2026-03-30,1,,Yes,2026-03-31,,,Don’t know,Yes,Assured Shorthold Tenancy (AST) – Fixed term,,2,4,,Yes,4,0,0,2,35,,Female,Female,White,Irish,Australia,Other,,Yes,32,Yes,,Male,Male,Not seeking work,No,Not known,Prefers not to say,Prefers not to say,Prefers not to say,Prefers not to say,Yes,Not known,Tenant prefers not to say,Person prefers not to say,Person prefers not to say,Person prefers not to say,,,,,,,,,,,,,,,,,,,,,,,,,Yes – the person is a current or former regular,No – they left up to and including 5 years ago,Yes,No,Yes,Fully wheelchair accessible housing,Yes,No,No,No,No,No,No,Yes,No,No,Yes,No,No,No,No,No,No,No,Less than 1 year,1 year but under 2 years,Loss of tied accommodation,,,Other supported housing,No,Yes,TN23 6LZ,Yes,No,Ashford,E07000105,Yes,,Yes,,,,No,No,Yes,No,No,,,,Yes,No,Weekly,268,,Universal Credit housing element,Yes,All,,,Every 2 weeks,200.0,100.0,,50.0,25.0,40.0,20.0,35.0,17.5,325.0,162.5,,,,Yes,Yes,12.0,6.0,,,,,,,,,,,,,,,,,,,, +Log ID,Status of log,ID of a set of duplicate logs,User the log is created by,User the log is assigned to,Is the user in the assigned_to column the data protection officer?,Time and date the log was created,User who last updated the log,Time and date the log was last updated,Was the log submitted in-service or via bulk upload?,Year collection period opened,ID of a set of bulk uploaded logs,Which organisation owns this property?,Which organisation manages this letting?,What is the needs type?,What is the letting type?,Is this letting a renewal?,What is the tenancy start date?,"What is the rent type? (grouped into SR, IR or AR)",What is the rent type?,Which type of Intermediate Rent is this letting?,Which 'Other' type of Intermediate Rent is this letting?,Is this a London Affordable Rent letting?,What is the tenant code?,What is the property reference?,Has the tenant seen the MHCLG privacy notice?,Is this the first time the property has been let as social housing?,What rent product was the property most recently let as?,What is the reason for the property being vacant?,Is this property new to the social rented sector?,"If known, property's UPRN",Address line 1,Address line 2,Town or City,County,Postcode,The internal value to indicate if the LA was inferred from the postcode,What is the property's local authority?,Local authority code,Is the UPRN known?,UPRN of the address selected,Was the 'No address found' page seen?,Address line 1 input from address matching feature,Postcode input from address matching feature,Address line 1 entered in bulk upload file,Address line 2 entered in bulk upload file,Town or city entered in bulk upload file,County entered in bulk upload file,Postcode entered in bulk upload file,Local authority entered in bulk upload file,What type of unit is the property?,Is the property built or adapted to wheelchair-user standards?,How many bedrooms does the property have?,What is the void date?,Number of days the property was vacant,The following soft validation was confirmed: You told us that the property has been vacant for more than 2 years. This is higher than we would expect.,Were any major repairs carried out during the void period?,What date were any major repairs completed on?,The following soft validation was confirmed: You told us the property has been vacant for 2 years. This is higher than we would expect.,Is this letting in sheltered accommodation?,Is this a joint tenancy?,Is this a starter tenancy?,What is the type of tenancy?,"If 'Other', what is the type of tenancy?",What is the length of the fixed-term tenancy to the nearest year?,How many people live in the household at this letting?,The following soft validation was confirmed: You told us somebody in the household is pregnant. You also told us there are no female tenants living at the property.,"Where household characteristics have a 'Refused' option for some or all of: AGE1-AGE8, SEX1-SEX8, RELAT2-RELAT8, ECSTAT1-ECSTAT8","Type of household 1 = 1 elder; 2 = 2 adults, including elder(s); 3 = 1 adult; 4 = 2 adults; 5 = 1 adult & 1+ children; 6 = 2+ adults & 1+ children; 9 = Other",Total number of dependent children in the household (Sum of when RELAT2-8 = C),Total number of elders in household (Sum of when AGE1-8 >= 60),Total number of adults in household,What is the lead tenant's age?,The following soft validation was confirmed: You told us this person is aged %{age} years and retired. The minimum expected retirement age for %{gender} in England is %{age}.,What was the lead tenant's sex at birth?,Which of these best describes the lead tenant's gender identity?,What is the lead tenant's ethnic group?,Which of these best describes the lead tenant's ethnic background?,What is the lead tenant's nationality?,Which of these best describes the lead tenant's working situation?,The following soft validation was confirmed: You have said that at least one person's situation is 'Unable to work because of long-term sickness or disability'.,Are the details of tenant 2 known?,What is person 2's age?,What is person 2's relationship to the lead tenant?,What was person 2's sex at birth?,Which of these best describes person 2's gender identity?,Which of these best describes person 2's working situation?,Are the details of tenant 3 known?,What is person 3's age?,What is person 3's relationship to the lead tenant?,What was person 3's sex at birth?,Which of these best describes person 3's gender identity?,Which of these best describes person 3's working situation?,Are the details of tenant 4 known?,What is person 4's age?,What is person 4's relationship to the lead tenant?,What was person 4's sex at birth?,Which of these best describes person 4's gender identity?,Which of these best describes person 4's working situation?,Are the details of tenant 5 known?,What is person 5's age?,What is person 5's relationship to the lead tenant?,What was person 5's sex at birth?,Which of these best describes person 5's gender identity?,Which of these best describes person 5's working situation?,Are the details of tenant 6 known?,What is person 6's age?,What is person 6's relationship to the lead tenant?,What was person 6's sex at birth?,Which of these best describes person 6's gender identity?,Which of these best describes person 6's working situation?,Are the details of tenant 7 known?,What is person 7's age?,What is person 7's relationship to the lead tenant?,What was person 7's sex at birth?,Which of these best describes person 7's gender identity?,Which of these best describes person 7's working situation?,Are the details of tenant 8 known?,What is person 8's age?,What is person 8's relationship to the lead tenant?,What was person 8's sex at birth?,Which of these best describes person 8's gender identity?,Which of these best describes person 8's working situation?,Does anybody in the household have links to the UK armed forces?,Is this person still serving in the UK armed forces?,Was this person seriously injured or ill as a result of serving in the UK armed forces?,Is anybody in the household pregnant?,Does anybody in the household have any disabled access needs?,"What access needs do they have? (Fully wheelchair-accessible housing, Level access housing or Wheelchair access to essential rooms)",Disabled access needs a) Fully wheelchair-accessible housing,Disabled access needs b) Wheelchair access to essential rooms,Disabled access needs c) Level access housing,Disabled access needs f) Other disabled access needs,Disabled access needs g) No disabled access needs,Disabled access needs h) Don't know,Do they have any other disabled access needs?,Does anybody in the household have a physical or mental health condition (or other illness) expected to last 12 months or more?,Does this person's condition affect their dexterity?,Does this person's condition affect their learning or understanding or concentrating?,Does this person's condition affect their hearing?,Does this person's condition affect their memory?,Does this person's condition affect their mental health?,Does this person's condition affect their mobility?,Does this person's condition affect them socially or behaviourally?,Does this person's condition affect their stamina or breathing or fatigue?,Does this person's condition affect their vision?,Does this person's condition affect them in another way?,How long has the household continuously lived in the local authority area of the new letting?,How long has the household been on the local authority waiting list for the new letting?,What is the tenant's main reason for the household leaving their last settled home?,"If 'Other', what was the main reason for leaving their last settled home?",The soft validation was confirmed,Where was the household immediately before this letting?,Did the household experience homelessness immediately before this letting?,Previous postcode unknown or previous accommodation was temporary,What is the postcode of the household's last settled home?,Was the local authority of the household's last settled home known?,The internal value to indicate if the previous LA was inferred from the postcode,Previous location LA name,Previous location's ONS LA Code,Was the household given reasonable preference by the local authority?,Reasonable preference reason - They were homeless or about to lose their home (within 56 days),"Reasonable preference reason - They were living in insanitary, overcrowded or unisatisfactory housing",Reasonable preference reason - They needed to move on medical and welfare reasons (including disability),Reasonable preference reason - They needed to move to avoid hardship to themselves or others,Reasonable preference reason - Don't Know,Was the letting made under Choice-Based Lettings (CBL)?,Was the letting made under the Common Allocation Policy (CAP)?,Was the letting made under the Common Housing Register (CHR)?,Was the letting made under the Accessible Register?,"The letting was not allocated under CBL, CAP, CHR or Accessible Register.",,What was the source of referral for this letting?,"The following soft validation was confirmed: Are you sure? This is a general needs log, and this referral type is for supported housing.",Do you know the household's combined income after tax?,Was the household income refused?,How often does the household receive income?,How much income does the household have in total?,Populated when someone hits the soft validation and confirmed in the service,Is the tenant likely to be receiving any of these housing-related benefits?,"Does the tenant receive housing-related benefits? Yes if hb = Universal Credit housing element or Housing benefit, No if hb = Don't Know, Neither, Tenant prefers not to say or blank","How much of the household's income is from Universal Credit, state pensions or benefits?",Does the household pay rent or other charges for the accommodation?,Does the household pay rent or other charges for the accommodation? - flag for when household_charge is answered no,How often does the household pay rent and other charges?,What is the basic rent?,Weekly rent,Populated when the soft validation and confirmed in the service,What is the service charge?,Weekly service charge,What is the personal service charge?,Weekly personal service charge,What is the support charge?,Weekly support charge,Total charge to the tenant,Weekly total charge to the tenant,Populated when the soft validation and confirmed in the service,Populated when the soft validation and confirmed in the service,Populated when the soft validation and confirmed in the service,"After the household has received any housing-related benefits, will they still need to pay for rent and charges?",Can you estimate the outstanding amount?,Estimated outstanding amount,Weekly total rent shortfall charge for tenant receiving housing benefit,What scheme does this letting belong to?,"From scheme code, we map to the scheme name",Does the scheme contain confidential information?,"What is this type of scheme? (Direct access hostel), Foyer, Housing for older people or Other supported housing",Is this scheme registered under the Care Standards Act 2000?,Which organisation owns the housing stock for this scheme?,What client group is this scheme intended for?,Does this scheme provide for another client group?,What is the other client group?,What support does this scheme provide?,Intended length of stay,Date scheme was created,Which location is this letting for?,What is the postcode for this location?,What is the name of this location?,How many units are at this location?,What is the most common type of unit at this location?,What are the mobility standards for the majority of the units in this location?,What is the local authority of this postcode?,When did the first property in this location become available under this scheme? +id,status,duplicate_set_id,created_by,assigned_to,is_dpo,created_at,updated_by,updated_at,creation_method,collection_start_year,bulk_upload_id,owning_organisation_name,managing_organisation_name,needstype,lettype,renewal,startdate,renttype,renttype_detail,irproduct,irproduct_other,lar,tenancycode,propcode,declaration,first_time_property_let_as_social_housing,unitletas,rsnvac,newprop,uprn,address_line1,address_line2,town_or_city,county,postcode_full,is_la_inferred,la_label,la,uprn_known,uprn_selection,address_search_value_check,address_line1_input,postcode_full_input,address_line1_as_entered,address_line2_as_entered,town_or_city_as_entered,county_as_entered,postcode_full_as_entered,la_as_entered,unittype_gn,wchair,beds,voiddate,vacdays,void_date_value_check,majorrepairs,mrcdate,major_repairs_date_value_check,sheltered,joint,startertenancy,tenancy,tenancyother,tenancylength,hhmemb,pregnancy_value_check,refused,hhtype,totchild,totelder,totadult,age1,retirement_value_check,sexrab1,sex1,ethnic_group,ethnic,nationality_all,ecstat1,working_situation_illness_check,details_known_2,age2,relat2,sexrab2,sex2,ecstat2,details_known_3,age3,relat3,sexrab3,sex3,ecstat3,details_known_4,age4,relat4,sexrab4,sex4,ecstat4,details_known_5,age5,relat5,sexrab5,sex5,ecstat5,details_known_6,age6,relat6,sexrab6,sex6,ecstat6,details_known_7,age7,relat7,sexrab7,sex7,ecstat7,details_known_8,age8,relat8,sexrab8,sex8,ecstat8,armedforces,leftreg,reservist,preg_occ,housingneeds,housingneeds_type,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,housingneeds_other,illness,illness_type_4,illness_type_5,illness_type_2,illness_type_6,illness_type_7,illness_type_3,illness_type_9,illness_type_8,illness_type_1,illness_type_10,layear,waityear,reason,reasonother,reasonother_value_check,prevten,homeless,ppcodenk,ppostcode_full,previous_la_known,is_previous_la_inferred,prevloc_label,prevloc,reasonpref,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,cbl,cap,chr,accessible_register,letting_allocation_none,referral_type,referral,referral_value_check,net_income_known,incref,incfreq,earnings,net_income_value_check,hb,has_benefits,benefits,household_charge,nocharge,period,brent,wrent,rent_value_check,scharge,wscharge,pscharge,wpschrge,supcharg,wsupchrg,tcharge,wtcharge,scharge_value_check,pscharge_value_check,supcharg_value_check,hbrentshortfall,tshortfall_known,tshortfall,wtshortfall,scheme_code,scheme_service_name,scheme_confidential,SCHTYPE,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,location_code,location_postcode,location_name,location_units,location_type_of_unit,location_mobility_type,location_local_authority,location_startdate +,in_progress,,s.port@jeemayle.com,s.port@jeemayle.com,false,2026-04-01T00:00:00+01:00,,2026-04-01T00:00:00+01:00,single log,2026,,MHCLG,MHCLG,General needs,Affordable rent general needs local authority,No,2026-04-01,Affordable Rent,Affordable Rent,,,No,HIJKLMN,ABCDEFG,Yes,No,Affordable rent basis,Tenant abandoned property,No,,Address line 1,,London,,NW9 5LL,No,Barnet,E09000003,No,,,,,address line 1 as entered,address line 2 as entered,town or city as entered,county as entered,AB1 2CD,la as entered,House,Yes,3,2026-03-30,1,,Yes,2026-03-31,,,Don’t know,Yes,Assured Shorthold Tenancy (AST) – Fixed term,,2,4,,Yes,4,0,0,2,35,,Female,Female,White,Irish,Australia,Other,,Yes,32,Yes,Male,Male,Not seeking work,No,Not known,Prefers not to say,Prefers not to say,Prefers not to say,Prefers not to say,Yes,Not known,Tenant prefers not to say,Person prefers not to say,Person prefers not to say,Person prefers not to say,,,,,,,,,,,,,,,,,,,,,,,,,Yes – the person is a current or former regular,No – they left up to and including 5 years ago,Yes,No,Yes,Fully wheelchair accessible housing,Yes,No,No,No,No,No,No,Yes,No,No,Yes,No,No,No,No,No,No,No,Less than 1 year,1 year but under 2 years,Loss of tied accommodation,,,Other supported housing,No,Yes,TN23 6LZ,Yes,No,Ashford,E07000105,Yes,,Yes,,,,No,No,Yes,No,No,,,,Yes,No,Weekly,268,,Universal Credit housing element,Yes,All,,,Every 2 weeks,200.0,100.0,,50.0,25.0,40.0,20.0,35.0,17.5,325.0,162.5,,,,Yes,Yes,12.0,6.0,,,,,,,,,,,,,,,,,,,, diff --git a/spec/models/form/lettings/pages/person_lead_partner_spec.rb b/spec/models/form/lettings/pages/person_lead_partner_spec.rb index 55ee97e1d..ff4da0bee 100644 --- a/spec/models/form/lettings/pages/person_lead_partner_spec.rb +++ b/spec/models/form/lettings/pages/person_lead_partner_spec.rb @@ -17,10 +17,6 @@ RSpec.describe Form::Lettings::Pages::PersonLeadPartner, type: :model do end context "with person 2" do - it "has correct questions" do - expect(page.questions.map(&:id)).to eq(%w[relat2]) - end - it "has the correct id" do expect(page.id).to eq("person_2_lead_partner") end @@ -30,6 +26,10 @@ RSpec.describe Form::Lettings::Pages::PersonLeadPartner, type: :model do allow(form).to receive(:start_year_2026_or_later?).and_return(false) end + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[relat2]) + end + it "has correct depends_on" do expect(page.depends_on).to eq( [{ "details_known_2" => 0 }], @@ -42,6 +42,10 @@ RSpec.describe Form::Lettings::Pages::PersonLeadPartner, type: :model do allow(form).to receive(:start_year_2026_or_later?).and_return(true) end + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[relat2]) + end + it "has correct depends_on" do expect(page.depends_on).to eq( [ @@ -62,10 +66,6 @@ RSpec.describe Form::Lettings::Pages::PersonLeadPartner, type: :model do context "with person 3" do let(:person_index) { 3 } - it "has correct questions" do - expect(page.questions.map(&:id)).to eq(%w[relat3]) - end - it "has the correct id" do expect(page.id).to eq("person_3_lead_partner") end @@ -75,6 +75,10 @@ RSpec.describe Form::Lettings::Pages::PersonLeadPartner, type: :model do allow(form).to receive(:start_year_2026_or_later?).and_return(false) end + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[relat3]) + end + it "has correct depends_on" do expect(page.depends_on).to eq( [{ "details_known_3" => 0 }], @@ -87,6 +91,10 @@ RSpec.describe Form::Lettings::Pages::PersonLeadPartner, type: :model do allow(form).to receive(:start_year_2026_or_later?).and_return(true) end + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[relat3]) + end + it "has correct depends_on" do expect(page.depends_on).to eq( [ @@ -96,8 +104,69 @@ RSpec.describe Form::Lettings::Pages::PersonLeadPartner, type: :model do "operator" => ">=", "operand" => 16, }, + "relat2" => { "operator" => "!=", "operand" => "P" }, + }, + { + "details_known_3" => 0, + "age3" => nil, + "relat2" => { "operator" => "!=", "operand" => "P" }, + }, + ], + ) + end + end + end + + context "with person 4" do + let(:person_index) { 4 } + + it "has the correct id" do + expect(page.id).to eq("person_4_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 questions" do + expect(page.questions.map(&:id)).to eq(%w[relat4]) + end + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [{ "details_known_4" => 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 questions" do + expect(page.questions.map(&:id)).to eq(%w[relat4]) + end + + it "has correct depends_on" do + expect(page.depends_on).to eq( + [ + { + "details_known_4" => 0, + "age4" => { + "operator" => ">=", + "operand" => 16, + }, + "relat2" => { "operator" => "!=", "operand" => "P" }, + "relat3" => { "operator" => "!=", "operand" => "P" }, + }, + { + "details_known_4" => 0, + "age4" => nil, + "relat2" => { "operator" => "!=", "operand" => "P" }, + "relat3" => { "operator" => "!=", "operand" => "P" }, }, - { "details_known_3" => 0, "age3" => nil }, ], ) end diff --git a/spec/models/form/lettings/questions/person_partner_spec.rb b/spec/models/form/lettings/questions/person_partner_spec.rb index 2106bc36f..435794046 100644 --- a/spec/models/form/lettings/questions/person_partner_spec.rb +++ b/spec/models/form/lettings/questions/person_partner_spec.rb @@ -45,6 +45,22 @@ RSpec.describe Form::Lettings::Questions::PersonPartner, type: :model do expect(question.hidden_in_check_answers).to be nil end + context "and in 2025", metadata: { year: 25 } do + let(:year) { 2025 } + + it "has the correct disable_clearing_if_not_routed_or_dynamic_answer_options value" do + expect(question.disable_clearing_if_not_routed_or_dynamic_answer_options).to eq(false) + end + end + + context "and in 2026", metadata: { year: 26 } do + let(:year) { 2026 } + + it "has the correct disable_clearing_if_not_routed_or_dynamic_answer_options value" do + expect(question.disable_clearing_if_not_routed_or_dynamic_answer_options).to eq(true) + end + end + context "with person 2" do it "has the correct id" do expect(question.id).to eq("relat2") @@ -105,5 +121,129 @@ 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(3) end + + context "when the log has a preceding value of `relat` as 'P'" do + let(:log) { build(:lettings_log, relat2: "P") } + + context "and in 2025", metadata: { year: 25 } do + let(:year) { 2025 } + + it "has the correct hidden_in_check_answers?" do + expect(question.hidden_in_check_answers?(log)).to eq(false) + end + + 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 "has the correct hidden_in_check_answers?" do + expect(question.hidden_in_check_answers?(log)).to eq(true) + end + + it "is marked as derived" do + expect(question.derived?(log)).to be true + end + end + end + + context "when the log does not have a preceding value of `relat` as 'P'" do + let(:log) { build(:lettings_log, relat2: "X") } + + context "and in 2025", metadata: { year: 25 } do + let(:year) { 2025 } + + it "has the correct hidden_in_check_answers?" do + expect(question.hidden_in_check_answers?(log)).to eq(false) + end + + 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 "has the correct hidden_in_check_answers?" do + expect(question.hidden_in_check_answers?(log)).to eq(false) + end + + it "is not marked as derived" do + expect(question.derived?(log)).to be false + end + end + end + end + + context "with person 4" do + let(:person_index) { 4 } + + it "has the correct id" do + expect(question.id).to eq("relat4") + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(4) + end + + context "when the log has a preceding value of `relat` as 'P'" do + let(:log) { build(:lettings_log, relat2: "P", relat3: "X") } + + context "and in 2025", metadata: { year: 25 } do + let(:year) { 2025 } + + it "has the correct hidden_in_check_answers?" do + expect(question.hidden_in_check_answers?(log)).to eq(false) + end + + 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 "has the correct hidden_in_check_answers?" do + expect(question.hidden_in_check_answers?(log)).to eq(true) + end + + it "is marked as derived" do + expect(question.derived?(log)).to be true + end + end + end + + context "when the log does not have a preceding value of `relat` as 'P'" do + let(:log) { build(:lettings_log, relat2: "R", relat3: "X") } + + context "and in 2025", metadata: { year: 25 } do + let(:year) { 2025 } + + it "has the correct hidden_in_check_answers?" do + expect(question.hidden_in_check_answers?(log)).to eq(false) + end + + 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 "has the correct hidden_in_check_answers?" do + expect(question.hidden_in_check_answers?(log)).to eq(false) + end + + it "is not marked as derived" do + expect(question.derived?(log)).to be false + end + end + end end end diff --git a/spec/models/form/lettings/subsections/household_characteristics_spec.rb b/spec/models/form/lettings/subsections/household_characteristics_spec.rb index 8a8618f3a..596ed5cb7 100644 --- a/spec/models/form/lettings/subsections/household_characteristics_spec.rb +++ b/spec/models/form/lettings/subsections/household_characteristics_spec.rb @@ -365,7 +365,6 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod person_2_known person_2_age person_2_lead_partner - relationship_2_multiple_partners_value_check 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 @@ -382,7 +381,6 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod person_3_known person_3_age person_3_lead_partner - relationship_3_multiple_partners_value_check 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 @@ -399,7 +397,6 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod person_4_known person_4_age person_4_lead_partner - relationship_4_multiple_partners_value_check 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 @@ -416,7 +413,6 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod person_5_known person_5_age person_5_lead_partner - relationship_5_multiple_partners_value_check 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 @@ -433,7 +429,6 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod person_6_known person_6_age person_6_lead_partner - relationship_6_multiple_partners_value_check 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 @@ -450,7 +445,6 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod person_7_known person_7_age person_7_lead_partner - relationship_7_multiple_partners_value_check 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 @@ -467,7 +461,6 @@ RSpec.describe Form::Lettings::Subsections::HouseholdCharacteristics, type: :mod person_8_known person_8_age person_8_lead_partner - relationship_8_multiple_partners_value_check 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 diff --git a/spec/models/lettings_log_derived_fields_spec.rb b/spec/models/lettings_log_derived_fields_spec.rb index 9cb6cf7d1..446a789cc 100644 --- a/spec/models/lettings_log_derived_fields_spec.rb +++ b/spec/models/lettings_log_derived_fields_spec.rb @@ -1588,4 +1588,245 @@ RSpec.describe LettingsLog, type: :model do end end end + + describe "At most one relationships inferences" do + context "when 2025", metadata: { year: 25 } do + before do + Timecop.freeze(Time.zone.local(2025, 5, 10)) + Singleton.__init__(FormHandler) + end + + after do + Timecop.return + Singleton.__init__(FormHandler) + end + + context "when there are no existing relationships" do + # `relat2` is "P" by default when creating a lettings log from the factory, so we explicitly set it to `nil`. + let(:log) { create(:lettings_log, :completed, hhmemb: 6, relat2: nil, relat3: "X", relat4: "X", relat5: "R") } + + it "does not infer no to any relationship answers when a new relationship is added" do + log.relat4 = "P" + expect { log.set_derived_fields! } + .to not_change(log, :relat2) + .and not_change(log, :relat3) + .and not_change(log, :relat5) + .and not_change(log, :relat6) + .and not_change(log, :relat7) + .and not_change(log, :relat8) + end + end + + context "when there is an existing relationship" do + let(:log) { create(:lettings_log, :completed, hhmemb: 6, relat2: "X", relat3: "P", relat4: "R", relat5: "X") } + + it "does not infer no to any relationship answers when a new relationship is added" do + log.relat2 = "P" + expect { log.set_derived_fields! } + .to not_change(log, :relat3) + .and not_change(log, :relat4) + .and not_change(log, :relat5) + .and not_change(log, :relat6) + .and not_change(log, :relat7) + .and not_change(log, :relat8) + end + + it "does not reset any answers when the relationship is removed" do + log.relat3 = "X" + expect { log.set_derived_fields! } + .to not_change(log, :relat2) + .and not_change(log, :relat4) + .and not_change(log, :relat5) + .and not_change(log, :relat6) + .and not_change(log, :relat7) + .and not_change(log, :relat8) + end + end + + context "when more than one relationship is set" do + let(:log) { create(:lettings_log, :completed, relat2: "X", relat3: "X", relat4: "R", relat5: "X") } + + before do + log.relat2 = "P" + log.relat3 = "P" + end + + it "does not infer no to any relationship answers" do + expect { log.set_derived_fields! } + .to not_change(log, :relat4) + .and not_change(log, :relat5) + .and not_change(log, :relat6) + .and not_change(log, :relat7) + .and not_change(log, :relat8) + end + end + end + + context "when 2026", metadata: { year: 26 } do + before do + Timecop.freeze(Time.zone.local(2026, 5, 10)) + Singleton.__init__(FormHandler) + end + + after do + Timecop.return + Singleton.__init__(FormHandler) + end + + context "when there are no existing relationships" do + # `relat2` is "P" by default when creating a lettings log from the factory, so we explicitly set it to `nil`. + let(:log) { create(:lettings_log, :completed, hhmemb: 6, relat2: nil, relat3: "X", relat4: "X", relat5: "R") } + + context "and a new relationship is added" do + before do + log.relat4 = "P" + end + + it "infers no to unanswered questions" do + expect { log.set_derived_fields! } + .to change(log, :relat2).to("X") + .and change(log, :relat6).to("X") + end + + it "does not change relationship answers for people not in the household" do + expect { log.set_derived_fields! } + .to not_change(log, :relat7) + .and not_change(log, :relat8) + end + + it "does not change relationship answers of no or prefer not to say" do + expect { log.set_derived_fields! } + .to not_change(log, :relat3) + .and not_change(log, :relat5) + end + end + + it "does not change other relationship values if no is changed to prefer not to say" do + log.relat4 = "R" + expect { log.set_derived_fields! } + .to not_change(log, :relat2) + .and not_change(log, :relat3) + .and not_change(log, :relat5) + .and not_change(log, :relat6) + .and not_change(log, :relat7) + .and not_change(log, :relat8) + end + + it "does not change other relationship values if prefer not to say is changed to no" do + log.relat5 = "X" + expect { log.set_derived_fields! } + .to not_change(log, :relat2) + .and not_change(log, :relat3) + .and not_change(log, :relat4) + .and not_change(log, :relat6) + .and not_change(log, :relat7) + .and not_change(log, :relat8) + end + end + + context "when there is an existing relationship" do + let(:log) { create(:lettings_log, :completed, hhmemb: 6, relat2: "X", relat3: "P", relat4: "R", relat5: "X") } + + context "and a new relationship is added to an earlier person than the existing one" do + before do + log.relat6 = nil # This is necessary because `log.set_derived_fields!` runs when the log is created from the factory, which sets `relat6` to "X". + log.relat2 = "P" + end + + it "infers no to the existing relationship" do + expect { log.set_derived_fields! }.to change(log, :relat3).to "X" + end + + it "infers no to unanswered questions" do + expect { log.set_derived_fields! }.to change(log, :relat6).to "X" + end + + it "does not change relationship answers for people not in the household" do + expect { log.set_derived_fields! } + .to not_change(log, :relat7) + .and not_change(log, :relat8) + end + + it "does not change relationship answers of no or prefer not to say" do + expect { log.set_derived_fields! } + .to not_change(log, :relat5) + .and not_change(log, :relat4) + end + end + + it "does not change other relationship values if no is changed to prefer not to say" do + log.relat2 = "R" + expect { log.set_derived_fields! } + .to not_change(log, :relat3) + .and not_change(log, :relat4) + .and not_change(log, :relat5) + .and not_change(log, :relat6) + .and not_change(log, :relat7) + .and not_change(log, :relat8) + end + + it "does not change other relationship values if prefer not to say is changed to no" do + log.relat4 = "X" + expect { log.set_derived_fields! } + .to not_change(log, :relat2) + .and not_change(log, :relat3) + .and not_change(log, :relat5) + .and not_change(log, :relat6) + .and not_change(log, :relat7) + .and not_change(log, :relat8) + end + + context "and the relationship is removed" do + before do + log.relat3 = "X" + end + + it "does not reset answers of no that come before the removed relationship to nil" do + expect { log.set_derived_fields! }.to not_change(log, :relat2) + end + + it "resets answers of no that come after the removed relationship to nil, regardless of whether they were inferred or not" do + expect { log.set_derived_fields! } + .to change(log, :relat5).to(nil) # `relat5` was set to "X" explicitly. + .and change(log, :relat6).to(nil) # `relat6` was inferred as "X" when we created the log from the factory. + end + + it "does not reset answers of prefer not to say" do + expect { log.set_derived_fields! }.to not_change(log, :relat4) + end + end + end + + context "when more than one relationship is set" do + let(:log) { create(:lettings_log, :completed, hhmemb: 6, relat2: "X", relat3: "X", relat4: "R", relat5: "X") } + + before do + log.relat2 = "P" + log.relat3 = "P" + end + + it "keeps the lower numbered relationship and infers the higher numbered one to false" do + expect { log.set_derived_fields! } + .to not_change(log, :relat2) + .and change(log, :relat3).to("X") + end + + it "infers no to unanswered questions" do + expect { log.set_derived_fields! }.to change(log, :relat6).to "X" + end + + it "does not change relationship answers for people not in the household" do + expect { log.set_derived_fields! } + .to not_change(log, :relat7) + .and not_change(log, :relat8) + end + + it "does not change relationship answers of no or prefer not to say" do + expect { log.set_derived_fields! } + .to not_change(log, :relat5) + .and not_change(log, :relat4) + end + end + end + end end