Browse Source

Change accessibility requirements question (#826)

* wip

* add missing values to factory bot and lint

* remove irrelevand methods

* dont infer housingneeds

* typo

* update method name

* Remove housingneeds_present? method

* move set housing needs fields to case log variables file

* Only set all housing needs values to 1 if there are no housingneeds

* update json form fixture

* link

* update csv test

Co-authored-by: Dushan Despotovic <dushan@madetech.com>
pull/840/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
0334ee8134
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 52
      app/models/case_log.rb
  2. 22
      app/models/derived_variables/case_log_variables.rb
  3. 10
      app/models/validations/household_validations.rb
  4. 9
      app/services/imports/case_logs_import_service.rb
  5. 67
      config/forms/2021_2022.json
  6. 67
      config/forms/2022_2023.json
  7. 8
      db/migrate/20220809100723_add_accessibility_requirements_fields.rb
  8. 2
      db/schema.rb
  9. 3
      spec/factories/case_log.rb
  10. 16
      spec/features/form/checkboxes_spec.rb
  11. 11
      spec/fixtures/complete_case_log.json
  12. 4
      spec/fixtures/files/case_logs_download.csv
  13. 4
      spec/fixtures/files/case_logs_download_non_support.csv
  14. 58
      spec/fixtures/forms/2021_2022.json
  15. 125
      spec/models/case_log_spec.rb
  16. 40
      spec/models/validations/household_validations_spec.rb
  17. 16
      spec/services/csv/case_log_csv_service_spec.rb

52
app/models/case_log.rb

@ -692,30 +692,6 @@ private
end
end
def get_housingneeds
return 1 if has_housingneeds?
return 2 if no_housingneeds?
return 3 if unknown_housingneeds?
end
def has_housingneeds?
if [housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f].any?(1)
1
end
end
def no_housingneeds?
if housingneeds_g == 1
1
end
end
def unknown_housingneeds?
if housingneeds_h == 1
1
end
end
def all_fields_completed?
subsection_statuses = form.subsections.map { |subsection| subsection.status(self) }.uniq
subsection_statuses == [:completed]
@ -753,4 +729,32 @@ private
def upcase_and_remove_whitespace(string)
string.present? ? string.upcase.gsub(/\s+/, "") : string
end
def fully_wheelchair_accessible?
housingneeds_type.present? && housingneeds_type.zero?
end
def essential_wheelchair_access?
housingneeds_type == 1
end
def level_access_housing?
housingneeds_type == 2
end
def other_housingneeds?
housingneeds_other == 1
end
def has_housingneeds?
housingneeds == 1
end
def no_housingneeds?
housingneeds == 2
end
def unknown_housingneeds?
housingneeds == 3
end
end

22
app/models/derived_variables/case_log_variables.rb

@ -43,7 +43,6 @@ module DerivedVariables::CaseLogVariables
self.has_benefits = get_has_benefits
self.tshortfall_known = 0 if tshortfall
self.nocharge = household_charge&.zero? ? 1 : 0
self.housingneeds = get_housingneeds
if is_renewal?
self.underoccupation_benefitcap = 2 if collection_start_year == 2021
self.referral = 0
@ -69,6 +68,8 @@ module DerivedVariables::CaseLogVariables
self.voiddate = startdate
end
end
set_housingneeds_fields if housingneeds?
end
private
@ -185,4 +186,23 @@ private
self.location = scheme.locations.first
end
end
def set_housingneeds_fields
self.housingneeds_a = fully_wheelchair_accessible? ? 1 : 0
self.housingneeds_b = essential_wheelchair_access? ? 1 : 0
self.housingneeds_c = level_access_housing? ? 1 : 0
self.housingneeds_f = other_housingneeds? ? 1 : 0
set_housingneeds_values_to_zero unless has_housingneeds?
self.housingneeds_g = no_housingneeds? ? 1 : 0
self.housingneeds_h = unknown_housingneeds? ? 1 : 0
end
def set_housingneeds_values_to_zero
self.housingneeds_a = 0
self.housingneeds_b = 0
self.housingneeds_c = 0
self.housingneeds_f = 0
self.housingneeds_g = 0
self.housingneeds_h = 0
end
end

10
app/models/validations/household_validations.rb

@ -54,16 +54,6 @@ module Validations::HouseholdValidations
validate_person_age_matches_economic_status(record, 1)
end
def validate_accessibility_requirements(record)
all_options = [record.housingneeds_a, record.housingneeds_b, record.housingneeds_c, record.housingneeds_f, record.housingneeds_g, record.housingneeds_h]
if all_options.count(1) > 1
mobility_accessibility_options = [record.housingneeds_a, record.housingneeds_b, record.housingneeds_c]
unless all_options.count(1) == 2 && record.housingneeds_f == 1 && mobility_accessibility_options.any? { |x| x == 1 }
record.errors.add :accessibility_requirements, I18n.t("validations.household.housingneeds_a.one_or_two_choices")
end
end
end
def validate_condition_effects(record)
all_options = [record.illness_type_1, record.illness_type_2, record.illness_type_3, record.illness_type_4, record.illness_type_5, record.illness_type_6, record.illness_type_7, record.illness_type_8, record.illness_type_9, record.illness_type_10]
if all_options.count(1) >= 1 && household_no_illness?(record)

9
app/services/imports/case_logs_import_service.rb

@ -107,6 +107,13 @@ module Imports
%w[a b c f g h].each do |letter|
attributes["housingneeds_#{letter}"] = housing_needs(xml_doc, letter)
end
attributes["housingneeds"] = 1 if [attributes["housingneeds_a"], attributes["housingneeds_b"], attributes["housingneeds_c"], attributes["housingneeds_f"]].any? { |housingneed| housingneed == 1 }
attributes["housingneeds"] = 2 if attributes["housingneeds_g"] == 1
attributes["housingneeds"] = 3 if attributes["housingneeds_h"] == 1
attributes["housingneeds_type"] = 0 if attributes["housingneeds_a"] == 1
attributes["housingneeds_type"] = 1 if attributes["housingneeds_b"] == 1
attributes["housingneeds_type"] = 2 if attributes["housingneeds_c"] == 1
attributes["housingneeds_other"] = attributes["housingneeds_f"] == 1 ? 1 : 0
attributes["illness"] = unsafe_string_as_integer(xml_doc, "Q10ia")
(1..10).each do |index|
@ -275,7 +282,7 @@ module Imports
end
def fields_not_present_in_softwire_data
%w[majorrepairs illness_type_0 tshortfall_known pregnancy_value_check retirement_value_check rent_value_check net_income_value_check major_repairs_date_value_check void_date_value_check]
%w[majorrepairs illness_type_0 tshortfall_known pregnancy_value_check retirement_value_check rent_value_check net_income_value_check major_repairs_date_value_check void_date_value_check housingneeds_type housingneeds_other]
end
def check_status_completed(case_log, previous_status)

67
config/forms/2021_2022.json

@ -5667,40 +5667,79 @@
}
}
},
"access_needs": {
"access_needs_exist": {
"header": "",
"description": "",
"questions": {
"accessibility_requirements": {
"housingneeds": {
"header": "Does anybody in the household have any disabled access needs?",
"hint_text": "",
"type": "checkbox",
"check_answer_label": "Anybody in household with disabled access needs",
"type": "radio",
"check_answer_label": "Anybody with disabled access needs",
"answer_options": {
"housingneeds_a": {
"1": {
"value": "Yes"
},
"2": {
"value": "No"
},
"divider": {
"value": true
},
"3": {
"value": "Don’t know"
}
}
}
}
},
"type_of_access_needs": {
"header": "Disabled access needs",
"description": "",
"questions": {
"housingneeds_type": {
"header": "What type of access need do they have?",
"hint_text": "",
"type": "radio",
"check_answer_label": "Disabled access needs",
"answer_options": {
"0": {
"value": "Fully wheelchair accessible housing"
},
"housingneeds_b": {
"1": {
"value": "Wheelchair access to essential rooms"
},
"housingneeds_c": {
"2": {
"value": "Level access housing"
},
"housingneeds_f": {
"value": "Other disabled access needs"
},
"divider": {
"value": true
},
"housingneeds_g": {
"value": "No disabled access needs"
"3": {
"value": "None of the above"
}
}
},
"housingneeds_h": {
"value": "Don’t know"
"housingneeds_other": {
"header": "Do they have any other access needs?",
"hint_text": "",
"type": "radio",
"check_answer_label": "Other disabled access needs",
"answer_options": {
"1": {
"value": "Yes"
},
"0": {
"value": "No"
}
}
}
},
"depends_on": [
{
"housingneeds": 1
}
]
},
"health_conditions": {
"header": "",

67
config/forms/2022_2023.json

@ -5669,40 +5669,79 @@
}
}
},
"access_needs": {
"access_needs_exist": {
"header": "",
"description": "",
"questions": {
"accessibility_requirements": {
"housingneeds": {
"header": "Does anybody in the household have any disabled access needs?",
"hint_text": "",
"type": "checkbox",
"check_answer_label": "Anybody in household with disabled access needs",
"type": "radio",
"check_answer_label": "Anybody with disabled access needs",
"answer_options": {
"housingneeds_a": {
"1": {
"value": "Yes"
},
"2": {
"value": "No"
},
"divider": {
"value": true
},
"3": {
"value": "Don’t know"
}
}
}
}
},
"type_of_access_needs": {
"header": "Disabled access needs",
"description": "",
"questions": {
"housingneeds_type": {
"header": "What type of access need do they have?",
"hint_text": "",
"type": "radio",
"check_answer_label": "Disabled access needs",
"answer_options": {
"0": {
"value": "Fully wheelchair accessible housing"
},
"housingneeds_b": {
"1": {
"value": "Wheelchair access to essential rooms"
},
"housingneeds_c": {
"2": {
"value": "Level access housing"
},
"housingneeds_f": {
"value": "Other disabled access needs"
},
"divider": {
"value": true
},
"housingneeds_g": {
"value": "No disabled access needs"
"3": {
"value": "None of the above"
}
}
},
"housingneeds_h": {
"value": "Don’t know"
"housingneeds_other": {
"header": "Do they have any other access needs?",
"hint_text": "",
"type": "radio",
"check_answer_label": "Other disabled access needs",
"answer_options": {
"1": {
"value": "Yes"
},
"0": {
"value": "No"
}
}
}
},
"depends_on": [
{
"housingneeds": 1
}
]
},
"health_conditions": {
"header": "",

8
db/migrate/20220809100723_add_accessibility_requirements_fields.rb

@ -0,0 +1,8 @@
class AddAccessibilityRequirementsFields < ActiveRecord::Migration[7.0]
def change
change_table :case_logs, bulk: true do |t|
t.column :housingneeds_type, :integer
t.column :housingneeds_other, :integer
end
end
end

2
db/schema.rb

@ -202,6 +202,8 @@ ActiveRecord::Schema[7.0].define(version: 2022_08_10_152340) do
t.bigint "location_id"
t.integer "major_repairs_date_value_check"
t.integer "void_date_value_check"
t.integer "housingneeds_type"
t.integer "housingneeds_other"
t.index ["created_by_id"], name: "index_case_logs_on_created_by_id"
t.index ["location_id"], name: "index_case_logs_on_location_id"
t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id"

3
spec/factories/case_log.rb

@ -87,6 +87,9 @@ FactoryBot.define do
chr { 1 }
cap { 0 }
reasonother { nil }
housingneeds { 1 }
housingneeds_type { 0 }
housingneeds_other { 0 }
housingneeds_a { 1 }
housingneeds_b { 0 }
housingneeds_c { 0 }

16
spec/features/form/checkboxes_spec.rb

@ -41,24 +41,24 @@ RSpec.describe "Checkboxes" do
context "when a checkbox question is submitted with invalid answers" do
before do
case_log.update!(illness: 100)
allow(case_log).to receive(:update).and_return(false)
end
it "shows an error summary" do
visit("/logs/#{id}/accessibility-requirements")
page.check("case-log-accessibility-requirements-housingneeds-a-field")
page.check("case-log-accessibility-requirements-housingneeds-c-field")
visit("/logs/#{id}/condition-effects")
page.check("case-log-condition-effects-illness-type-1-field")
page.check("case-log-condition-effects-illness-type-2-field")
click_button("Save and continue")
expect(page).to have_title("Error")
end
it "persists the original selections" do
visit("/logs/#{id}/accessibility-requirements")
page.check("case-log-accessibility-requirements-housingneeds-a-field")
page.check("case-log-accessibility-requirements-housingneeds-c-field")
visit("/logs/#{id}/condition-effects")
page.check("case-log-condition-effects-illness-type-1-field")
page.check("case-log-condition-effects-illness-type-2-field")
click_button("Save and continue")
expect(page).to have_checked_field("case-log-accessibility-requirements-housingneeds-a-field")
expect(page).to have_checked_field("case-log-accessibility-requirements-housingneeds-c-field")
expect(page).to have_checked_field("case-log-condition-effects-illness-type-2-field")
end
end
end

11
spec/fixtures/complete_case_log.json vendored

@ -56,12 +56,10 @@
"chr":0,
"cap":0,
"reasonother":"",
"housingneeds_a":0,
"housingneeds_b":0,
"housingneeds_c":1,
"housingneeds_f":0,
"housingneeds_g":0,
"housingneeds_h":0,
"housingneeds": 1,
"housingneeds_type": 2,
"housingneeds_other": 0,
"housingneeds_c": 1,
"illness_type_1":null,
"illness_type_2":null,
"illness_type_3":null,
@ -155,7 +153,6 @@
"wtcharge":"93.0",
"wtshortfall":null,
"refused":1,
"housingneeds":2,
"wchchrg":null,
"newprop":2,
"relat2":"P",

4
spec/fixtures/files/case_logs_download.csv vendored

@ -1,2 +1,2 @@
id,status,created_at,updated_at,created_by_name,is_dpo,owning_organisation_name,managing_organisation_name,needstype,renewal,startdate,rent_type,irproduct_other,tenancycode,propcode,age1,sex1,ecstat1,hhmemb,relat2,age2,sex2,retirement_value_check,ecstat2,armedforces,leftreg,illness,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_h,is_previous_la_inferred,prevloc,illness_type_1,illness_type_2,is_la_inferred,la,postcode_known,postcode_full,previous_la_known,wchair,preg_occ,cbl,earnings,incfreq,net_income_value_check,benefits,hb,period,brent,scharge,pscharge,supcharg,tcharge,offered,layear,ppostcode_full,mrcdate,declaration,ethnic,national,prevten,age3,sex3,ecstat3,age4,sex4,ecstat4,age5,sex5,ecstat5,age6,sex6,ecstat6,age7,sex7,ecstat7,age8,sex8,ecstat8,homeless,underoccupation_benefitcap,reservist,startertenancy,tenancylength,tenancy,rsnvac,unittype_gn,beds,waityear,reasonpref,chr,cap,reasonother,housingneeds_f,housingneeds_g,illness_type_3,illness_type_4,illness_type_8,illness_type_5,illness_type_6,illness_type_7,illness_type_9,illness_type_10,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,tenancyother,property_owner_organisation,property_manager_organisation,sale_or_letting,purchaser_code,reason,majorrepairs,hbrentshortfall,property_relet,incref,sale_completion_date,first_time_property_let_as_social_housing,unitletas,builtype,voiddate,renttype,lettype,totchild,totelder,totadult,net_income_known,nocharge,is_carehome,household_charge,referral,tshortfall,chcharge,ppcodenk,age1_known,age2_known,age3_known,age4_known,age5_known,age6_known,age7_known,age8_known,ethnic_group,ethnic_other,letting_allocation_unknown,details_known_2,details_known_3,details_known_4,details_known_5,details_known_6,details_known_7,details_known_8,has_benefits,wrent,wscharge,wpschrge,wsupchrg,wtcharge,wtshortfall,refused,housingneeds,wchchrg,newprop,relat3,relat4,relat5,relat6,relat7,relat8,rent_value_check,old_form_id,lar,irproduct,old_id,joint,illness_type_0,tshortfall_known,sheltered,pregnancy_value_check,hhtype,new_old,vacdays,major_repairs_date_value_check,void_date_value_check,unittype_sh,scheme_id,location_id,scheme_code,scheme_service_name,scheme_sensitive,scheme_type,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_managing_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_admin_district,location_startdate
{id},in_progress,2022-02-08 16:52:15 +0000,2022-02-08 16:52:15 +0000,Danny Rojas,No,DLUHC,DLUHC,Supported housing,,,,,,,,,,,,,,,,,,,,,,,No,,,,No,Westminster,,SE1 1TE,,2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0,0,0,,0,,,,,,,,,,,,,,,,,,,,,,,,,0,,,,,,,0,,,,,,,,,,,,,,,,,,,,9,,,,,6,{scheme_id},SE1 1TE,{scheme_code},{scheme_service_name},{scheme_sensitive},Missing,No,DLUHC,DLUHC,{scheme_primary_client_group},,{scheme_secondary_client_group},{scheme_support_type},{scheme_intended_stay},2022-06-05 01:00:00 +0100,{location_code},SE1 1TE,Downing Street,20,Bungalow,Fitted with equipment and adaptations,Westminster,{location_startdate}
id,status,created_at,updated_at,created_by_name,is_dpo,owning_organisation_name,managing_organisation_name,needstype,renewal,startdate,rent_type,irproduct_other,tenancycode,propcode,age1,sex1,ecstat1,hhmemb,relat2,age2,sex2,retirement_value_check,ecstat2,armedforces,leftreg,illness,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_h,is_previous_la_inferred,prevloc,illness_type_1,illness_type_2,is_la_inferred,la,postcode_known,postcode_full,previous_la_known,wchair,preg_occ,cbl,earnings,incfreq,net_income_value_check,benefits,hb,period,brent,scharge,pscharge,supcharg,tcharge,offered,layear,ppostcode_full,mrcdate,declaration,ethnic,national,prevten,age3,sex3,ecstat3,age4,sex4,ecstat4,age5,sex5,ecstat5,age6,sex6,ecstat6,age7,sex7,ecstat7,age8,sex8,ecstat8,homeless,underoccupation_benefitcap,reservist,startertenancy,tenancylength,tenancy,rsnvac,unittype_gn,beds,waityear,reasonpref,chr,cap,reasonother,housingneeds_f,housingneeds_g,illness_type_3,illness_type_4,illness_type_8,illness_type_5,illness_type_6,illness_type_7,illness_type_9,illness_type_10,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,tenancyother,property_owner_organisation,property_manager_organisation,sale_or_letting,purchaser_code,reason,majorrepairs,hbrentshortfall,property_relet,incref,sale_completion_date,first_time_property_let_as_social_housing,unitletas,builtype,voiddate,renttype,lettype,totchild,totelder,totadult,net_income_known,nocharge,is_carehome,household_charge,referral,tshortfall,chcharge,ppcodenk,age1_known,age2_known,age3_known,age4_known,age5_known,age6_known,age7_known,age8_known,ethnic_group,ethnic_other,letting_allocation_unknown,details_known_2,details_known_3,details_known_4,details_known_5,details_known_6,details_known_7,details_known_8,has_benefits,wrent,wscharge,wpschrge,wsupchrg,wtcharge,wtshortfall,refused,housingneeds,wchchrg,newprop,relat3,relat4,relat5,relat6,relat7,relat8,rent_value_check,old_form_id,lar,irproduct,old_id,joint,illness_type_0,tshortfall_known,sheltered,pregnancy_value_check,hhtype,new_old,vacdays,major_repairs_date_value_check,void_date_value_check,housingneeds_type,housingneeds_other,unittype_sh,scheme_id,location_id,scheme_code,scheme_service_name,scheme_sensitive,scheme_type,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_managing_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_admin_district,location_startdate
{id},in_progress,2022-02-08 16:52:15 +0000,2022-02-08 16:52:15 +0000,Danny Rojas,No,DLUHC,DLUHC,Supported housing,,,,,,,,,,,,,,,,,,,,,,,No,,,,No,Westminster,,SE1 1TE,,2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0,0,0,,0,,,,,,,,,,,,,,,,,,,,,,,,,0,,,,,,,0,,,,,,,,,,,,,,,,,,,,9,,,,,,,6,{scheme_id},SE1 1TE,{scheme_code},{scheme_service_name},{scheme_sensitive},Missing,No,DLUHC,DLUHC,{scheme_primary_client_group},,{scheme_secondary_client_group},{scheme_support_type},{scheme_intended_stay},2022-06-05 01:00:00 +0100,{location_code},SE1 1TE,Downing Street,20,Bungalow,Fitted with equipment and adaptations,Westminster,{location_startdate}

1 id status created_at updated_at created_by_name is_dpo owning_organisation_name managing_organisation_name needstype renewal startdate rent_type irproduct_other tenancycode propcode age1 sex1 ecstat1 hhmemb relat2 age2 sex2 retirement_value_check ecstat2 armedforces leftreg illness housingneeds_a housingneeds_b housingneeds_c housingneeds_h is_previous_la_inferred prevloc illness_type_1 illness_type_2 is_la_inferred la postcode_known postcode_full previous_la_known wchair preg_occ cbl earnings incfreq net_income_value_check benefits hb period brent scharge pscharge supcharg tcharge offered layear ppostcode_full mrcdate declaration ethnic national prevten age3 sex3 ecstat3 age4 sex4 ecstat4 age5 sex5 ecstat5 age6 sex6 ecstat6 age7 sex7 ecstat7 age8 sex8 ecstat8 homeless underoccupation_benefitcap reservist startertenancy tenancylength tenancy rsnvac unittype_gn beds waityear reasonpref chr cap reasonother housingneeds_f housingneeds_g illness_type_3 illness_type_4 illness_type_8 illness_type_5 illness_type_6 illness_type_7 illness_type_9 illness_type_10 rp_homeless rp_insan_unsat rp_medwel rp_hardship rp_dontknow tenancyother property_owner_organisation property_manager_organisation sale_or_letting purchaser_code reason majorrepairs hbrentshortfall property_relet incref sale_completion_date first_time_property_let_as_social_housing unitletas builtype voiddate renttype lettype totchild totelder totadult net_income_known nocharge is_carehome household_charge referral tshortfall chcharge ppcodenk age1_known age2_known age3_known age4_known age5_known age6_known age7_known age8_known ethnic_group ethnic_other letting_allocation_unknown details_known_2 details_known_3 details_known_4 details_known_5 details_known_6 details_known_7 details_known_8 has_benefits wrent wscharge wpschrge wsupchrg wtcharge wtshortfall refused housingneeds wchchrg newprop relat3 relat4 relat5 relat6 relat7 relat8 rent_value_check old_form_id lar irproduct old_id joint illness_type_0 tshortfall_known sheltered pregnancy_value_check hhtype new_old vacdays major_repairs_date_value_check void_date_value_check housingneeds_type housingneeds_other unittype_sh scheme_id location_id scheme_code scheme_service_name scheme_sensitive scheme_type scheme_registered_under_care_act scheme_owning_organisation_name scheme_managing_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_admin_district location_startdate
2 {id} in_progress 2022-02-08 16:52:15 +0000 2022-02-08 16:52:15 +0000 Danny Rojas No DLUHC DLUHC Supported housing No No Westminster SE1 1TE 2 0 0 0 0 0 0 9 6 {scheme_id} SE1 1TE {scheme_code} {scheme_service_name} {scheme_sensitive} Missing No DLUHC DLUHC {scheme_primary_client_group} {scheme_secondary_client_group} {scheme_support_type} {scheme_intended_stay} 2022-06-05 01:00:00 +0100 {location_code} SE1 1TE Downing Street 20 Bungalow Fitted with equipment and adaptations Westminster {location_startdate}

4
spec/fixtures/files/case_logs_download_non_support.csv vendored

@ -1,2 +1,2 @@
id,status,created_at,updated_at,created_by_name,is_dpo,owning_organisation_name,managing_organisation_name,renewal,startdate,irproduct_other,tenancycode,propcode,age1,sex1,ecstat1,relat2,age2,sex2,ecstat2,armedforces,leftreg,illness,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_h,prevloc,illness_type_1,illness_type_2,la,postcode_full,wchair,preg_occ,cbl,earnings,incfreq,benefits,hb,period,brent,scharge,pscharge,supcharg,tcharge,offered,layear,ppostcode_full,mrcdate,declaration,ethnic,national,prevten,age3,sex3,ecstat3,age4,sex4,ecstat4,age5,sex5,ecstat5,age6,sex6,ecstat6,age7,sex7,ecstat7,age8,sex8,ecstat8,homeless,underoccupation_benefitcap,reservist,startertenancy,tenancylength,tenancy,rsnvac,unittype_gn,beds,waityear,reasonpref,chr,cap,reasonother,housingneeds_f,housingneeds_g,illness_type_3,illness_type_4,illness_type_8,illness_type_5,illness_type_6,illness_type_7,illness_type_9,illness_type_10,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,tenancyother,property_owner_organisation,property_manager_organisation,purchaser_code,reason,majorrepairs,hbrentshortfall,property_relet,incref,sale_completion_date,unitletas,builtype,voiddate,lettype,nocharge,household_charge,referral,tshortfall,chcharge,ppcodenk,ethnic_group,ethnic_other,has_benefits,refused,housingneeds,wchchrg,newprop,relat3,relat4,relat5,relat6,relat7,relat8,lar,irproduct,joint,illness_type_0,sheltered,major_repairs_date_value_check,void_date_value_check,unittype_sh,scheme_code,scheme_service_name,scheme_sensitive,scheme_type,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_managing_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_admin_district,location_startdate
{id},in_progress,2022-02-08 16:52:15 +0000,2022-02-08 16:52:15 +0000,Danny Rojas,No,DLUHC,DLUHC,,,,,,,,,,,,,,,,,,,,,,,Westminster,SE1 1TE,2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0,,,,,,,,0,0,,,,,,,,,,,,,,,,,6,{scheme_code},{scheme_service_name},{scheme_sensitive},Missing,No,DLUHC,DLUHC,{scheme_primary_client_group},,{scheme_secondary_client_group},{scheme_support_type},{scheme_intended_stay},2022-06-05 01:00:00 +0100,{location_code},SE1 1TE,Downing Street,20,Bungalow,Fitted with equipment and adaptations,Westminster,{location_startdate}
id,status,created_at,updated_at,created_by_name,is_dpo,owning_organisation_name,managing_organisation_name,renewal,startdate,irproduct_other,tenancycode,propcode,age1,sex1,ecstat1,relat2,age2,sex2,ecstat2,armedforces,leftreg,illness,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_h,prevloc,illness_type_1,illness_type_2,la,postcode_full,wchair,preg_occ,cbl,earnings,incfreq,benefits,hb,period,brent,scharge,pscharge,supcharg,tcharge,offered,layear,ppostcode_full,mrcdate,declaration,ethnic,national,prevten,age3,sex3,ecstat3,age4,sex4,ecstat4,age5,sex5,ecstat5,age6,sex6,ecstat6,age7,sex7,ecstat7,age8,sex8,ecstat8,homeless,underoccupation_benefitcap,reservist,startertenancy,tenancylength,tenancy,rsnvac,unittype_gn,beds,waityear,reasonpref,chr,cap,reasonother,housingneeds_f,housingneeds_g,illness_type_3,illness_type_4,illness_type_8,illness_type_5,illness_type_6,illness_type_7,illness_type_9,illness_type_10,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,tenancyother,property_owner_organisation,property_manager_organisation,purchaser_code,reason,majorrepairs,hbrentshortfall,property_relet,incref,sale_completion_date,unitletas,builtype,voiddate,lettype,nocharge,household_charge,referral,tshortfall,chcharge,ppcodenk,ethnic_group,ethnic_other,has_benefits,refused,housingneeds,wchchrg,newprop,relat3,relat4,relat5,relat6,relat7,relat8,lar,irproduct,joint,illness_type_0,sheltered,major_repairs_date_value_check,void_date_value_check,housingneeds_type,housingneeds_other,unittype_sh,scheme_code,scheme_service_name,scheme_sensitive,scheme_type,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_managing_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_admin_district,location_startdate
{id},in_progress,2022-02-08 16:52:15 +0000,2022-02-08 16:52:15 +0000,Danny Rojas,No,DLUHC,DLUHC,,,,,,,,,,,,,,,,,,,,,,,Westminster,SE1 1TE,2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0,,,,,,,,0,0,,,,,,,,,,,,,,,,,,,6,{scheme_code},{scheme_service_name},{scheme_sensitive},Missing,No,DLUHC,DLUHC,{scheme_primary_client_group},,{scheme_secondary_client_group},{scheme_support_type},{scheme_intended_stay},2022-06-05 01:00:00 +0100,{location_code},SE1 1TE,Downing Street,20,Bungalow,Fitted with equipment and adaptations,Westminster,{location_startdate}

1 id status created_at updated_at created_by_name is_dpo owning_organisation_name managing_organisation_name renewal startdate irproduct_other tenancycode propcode age1 sex1 ecstat1 relat2 age2 sex2 ecstat2 armedforces leftreg illness housingneeds_a housingneeds_b housingneeds_c housingneeds_h prevloc illness_type_1 illness_type_2 la postcode_full wchair preg_occ cbl earnings incfreq benefits hb period brent scharge pscharge supcharg tcharge offered layear ppostcode_full mrcdate declaration ethnic national prevten age3 sex3 ecstat3 age4 sex4 ecstat4 age5 sex5 ecstat5 age6 sex6 ecstat6 age7 sex7 ecstat7 age8 sex8 ecstat8 homeless underoccupation_benefitcap reservist startertenancy tenancylength tenancy rsnvac unittype_gn beds waityear reasonpref chr cap reasonother housingneeds_f housingneeds_g illness_type_3 illness_type_4 illness_type_8 illness_type_5 illness_type_6 illness_type_7 illness_type_9 illness_type_10 rp_homeless rp_insan_unsat rp_medwel rp_hardship rp_dontknow tenancyother property_owner_organisation property_manager_organisation purchaser_code reason majorrepairs hbrentshortfall property_relet incref sale_completion_date unitletas builtype voiddate lettype nocharge household_charge referral tshortfall chcharge ppcodenk ethnic_group ethnic_other has_benefits refused housingneeds wchchrg newprop relat3 relat4 relat5 relat6 relat7 relat8 lar irproduct joint illness_type_0 sheltered major_repairs_date_value_check void_date_value_check housingneeds_type housingneeds_other unittype_sh scheme_code scheme_service_name scheme_sensitive scheme_type scheme_registered_under_care_act scheme_owning_organisation_name scheme_managing_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_admin_district location_startdate
2 {id} in_progress 2022-02-08 16:52:15 +0000 2022-02-08 16:52:15 +0000 Danny Rojas No DLUHC DLUHC Westminster SE1 1TE 2 0 0 0 6 {scheme_code} {scheme_service_name} {scheme_sensitive} Missing No DLUHC DLUHC {scheme_primary_client_group} {scheme_secondary_client_group} {scheme_support_type} {scheme_intended_stay} 2022-06-05 01:00:00 +0100 {location_code} SE1 1TE Downing Street 20 Bungalow Fitted with equipment and adaptations Westminster {location_startdate}

58
spec/fixtures/forms/2021_2022.json vendored

@ -390,6 +390,9 @@
"depends_on": [
{
"illness": 1
},
{
"illness": 100
}
]
}
@ -634,10 +637,12 @@
"label": true,
"i18n_template": "ecstat1"
},
{"key": "earnings",
{
"key": "earnings",
"label": true,
"i18n_template": "earnings"
}]
}
]
},
"questions": {
"net_income_value_check": {
@ -664,10 +669,10 @@
"type": "radio",
"answer_options": {
"0": {
"value":"All"
"value": "All"
},
"1": {
"value":"Some"
"value": "Some"
}
}
}
@ -752,12 +757,7 @@
"min": 0,
"step": 1,
"width": 4,
"fields-to-add": [
"brent",
"scharge",
"pscharge",
"supcharg"
],
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
},
"scharge": {
@ -768,12 +768,7 @@
"min": 0,
"step": 1,
"width": 4,
"fields-to-add": [
"brent",
"scharge",
"pscharge",
"supcharg"
],
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
},
"pscharge": {
@ -784,12 +779,7 @@
"min": 0,
"step": 1,
"width": 4,
"fields-to-add": [
"brent",
"scharge",
"pscharge",
"supcharg"
],
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
},
"supcharg": {
@ -801,12 +791,7 @@
"max": 300,
"step": 1,
"width": 4,
"fields-to-add": [
"brent",
"scharge",
"pscharge",
"supcharg"
],
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
},
"tcharge": {
@ -851,7 +836,7 @@
"width": 4
}
},
"depends_on": [{"period": 3}]
"depends_on": [{ "period": 3 }]
},
"care_home_charge_bi_weekly": {
"questions": {
@ -865,7 +850,7 @@
"width": 4
}
},
"depends_on": [{"period": 2}]
"depends_on": [{ "period": 2 }]
}
}
}
@ -913,10 +898,7 @@
}
},
"hidden_in_check_answers": {
"depends_on": [
{ "layear": 0 },
{ "layear": 1 }
]
"depends_on": [{ "layear": 0 }, { "layear": 1 }]
}
}
},
@ -998,11 +980,13 @@
"subsections": {
"declaration": {
"label": "Declaration",
"depends_on": [{
"depends_on": [
{
"household_characteristics": "completed",
"household_needs": "completed",
"property_information": "completed"
}],
}
],
"pages": {
"declaration": {
"questions": {
@ -1023,4 +1007,4 @@
}
}
}
}
}

125
spec/models/case_log_spec.rb

@ -139,10 +139,6 @@ RSpec.describe CaseLog do
expect(validator).to receive(:validate_rsnvac)
end
it "validates accessibility requirements" do
expect(validator).to receive(:validate_accessibility_requirements)
end
it "validates referral" do
expect(validator).to receive(:validate_referral)
end
@ -1440,34 +1436,6 @@ RSpec.describe CaseLog do
end
end
context "when the data provider is filling in household needs" do
let!(:case_log) do
described_class.create({
managing_organisation: owning_organisation,
owning_organisation:,
created_by: created_by_user,
})
end
it "correctly derives and saves housing neeeds as 1" do
case_log.update!(housingneeds_a: 1)
record_from_db = ActiveRecord::Base.connection.execute("select housingneeds from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["housingneeds"]).to eq(1)
end
it "correctly derives and saves housing neeeds as 2" do
case_log.update!(housingneeds_g: 1)
record_from_db = ActiveRecord::Base.connection.execute("select housingneeds from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["housingneeds"]).to eq(2)
end
it "correctly derives and saves housing neeeds as 3" do
case_log.update!(housingneeds_h: 1)
record_from_db = ActiveRecord::Base.connection.execute("select housingneeds from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["housingneeds"]).to eq(3)
end
end
context "when it is supported housing and a care home charge has been supplied" do
let!(:case_log) do
described_class.create({
@ -1753,6 +1721,99 @@ RSpec.describe CaseLog do
end
end
end
context "when saving accessibility needs" do
it "derives housingneeds_h as true if 'Don't know' is selected for housingneeds" do
case_log.update!({ housingneeds: 3 })
record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from case_logs where id=#{case_log.id}").to_a[0]
not_selected_housingneeds = %w[housingneeds_a housingneeds_b housingneeds_c housingneeds_f housingneeds_g]
not_selected_housingneeds.each do |housingneed|
expect(record_from_db[housingneed]).to eq(0)
expect(case_log[housingneed]).to eq(0)
end
expect(record_from_db["housingneeds_h"]).to eq(1)
expect(case_log["housingneeds_h"]).to eq(1)
end
it "derives housingneeds_g as true if 'No' is selected for housingneeds" do
case_log.update!({ housingneeds: 2 })
record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from case_logs where id=#{case_log.id}").to_a[0]
not_selected_housingneeds = %w[housingneeds_a housingneeds_b housingneeds_c housingneeds_f housingneeds_h]
not_selected_housingneeds.each do |housingneed|
expect(record_from_db[housingneed]).to eq(0)
expect(case_log[housingneed]).to eq(0)
end
expect(record_from_db["housingneeds_g"]).to eq(1)
expect(case_log["housingneeds_g"]).to eq(1)
end
it "derives housingneeds_a as true if 'Fully wheelchair accessible' is selected for housingneeds_type" do
case_log.update!({ housingneeds: 1, housingneeds_type: 0 })
record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from case_logs where id=#{case_log.id}").to_a[0]
not_selected_housingneeds = %w[housingneeds_b housingneeds_c housingneeds_f housingneeds_g housingneeds_h]
not_selected_housingneeds.each do |housingneed|
expect(record_from_db[housingneed]).to eq(0)
expect(case_log[housingneed]).to eq(0)
end
expect(record_from_db["housingneeds_a"]).to eq(1)
expect(case_log["housingneeds_a"]).to eq(1)
end
it "derives housingneeds_b as true if 'Wheelchair access to essential rooms' is selected for housingneeds_type" do
case_log.update!({ housingneeds: 1, housingneeds_type: 1 })
record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from case_logs where id=#{case_log.id}").to_a[0]
not_selected_housingneeds = %w[housingneeds_a housingneeds_c housingneeds_f housingneeds_g housingneeds_h]
not_selected_housingneeds.each do |housingneed|
expect(record_from_db[housingneed]).to eq(0)
expect(case_log[housingneed]).to eq(0)
end
expect(record_from_db["housingneeds_b"]).to eq(1)
expect(case_log["housingneeds_b"]).to eq(1)
end
it "derives housingneeds_c if 'Level access housing' is selected for housingneeds_type" do
case_log.update!({ housingneeds: 1, housingneeds_type: 2 })
record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from case_logs where id=#{case_log.id}").to_a[0]
not_selected_housingneeds = %w[housingneeds_a housingneeds_b housingneeds_f housingneeds_g housingneeds_h]
not_selected_housingneeds.each do |housingneed|
expect(record_from_db[housingneed]).to eq(0)
expect(case_log[housingneed]).to eq(0)
end
expect(record_from_db["housingneeds_c"]).to eq(1)
expect(case_log["housingneeds_c"]).to eq(1)
end
it "derives housingneeds_f if 'Yes' is selected for housingneeds_other" do
case_log.update!({ housingneeds: 1, housingneeds_other: 1 })
record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from case_logs where id=#{case_log.id}").to_a[0]
not_selected_housingneeds = %w[housingneeds_a housingneeds_b housingneeds_c housingneeds_g housingneeds_h]
not_selected_housingneeds.each do |housingneed|
expect(record_from_db[housingneed]).to eq(0)
expect(case_log[housingneed]).to eq(0)
end
expect(record_from_db["housingneeds_f"]).to eq(1)
expect(case_log["housingneeds_f"]).to eq(1)
end
it "clears previously set housingneeds if 'No' is selected for housingneeds" do
case_log.update!({ housingneeds: 1, housingneeds_type: 2, housingneeds_other: 1 })
record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["housingneeds_c"]).to eq(1)
expect(case_log["housingneeds_c"]).to eq(1)
expect(record_from_db["housingneeds_f"]).to eq(1)
expect(case_log["housingneeds_f"]).to eq(1)
case_log.update!({ housingneeds: 2 })
record_from_db = ActiveRecord::Base.connection.execute("select housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f, housingneeds_g, housingneeds_h from case_logs where id=#{case_log.id}").to_a[0]
not_selected_housingneeds = %w[housingneeds_a housingneeds_b housingneeds_c housingneeds_f housingneeds_h]
not_selected_housingneeds.each do |housingneed|
expect(record_from_db[housingneed]).to eq(0)
expect(case_log[housingneed]).to eq(0)
end
expect(record_from_db["housingneeds_g"]).to eq(1)
expect(case_log["housingneeds_g"]).to eq(1)
end
end
end
describe "optional fields" do

40
spec/models/validations/household_validations_spec.rb

@ -575,46 +575,6 @@ RSpec.describe Validations::HouseholdValidations do
end
end
describe "accessibility requirement validations" do
it "validates that mutually exclusive options can't be selected together" do
record.housingneeds_a = 1
record.housingneeds_b = 1
household_validator.validate_accessibility_requirements(record)
expect(record.errors["accessibility_requirements"])
.to include(match I18n.t("validations.household.housingneeds_a.one_or_two_choices"))
record.housingneeds_a = 0
record.housingneeds_b = 0
record.housingneeds_g = 1
record.housingneeds_f = 1
household_validator.validate_accessibility_requirements(record)
expect(record.errors["accessibility_requirements"])
.to include(match I18n.t("validations.household.housingneeds_a.one_or_two_choices"))
record.housingneeds_a = 1
record.housingneeds_g = 1
record.housingneeds_f = 1
household_validator.validate_accessibility_requirements(record)
expect(record.errors["accessibility_requirements"])
.to include(match I18n.t("validations.household.housingneeds_a.one_or_two_choices"))
end
it "validates that non-mutually exclusive options can be selected together" do
record.housingneeds_a = 1
record.housingneeds_f = 1
household_validator.validate_accessibility_requirements(record)
expect(record.errors["accessibility_requirements"]).to be_empty
record.housingneeds_a = 0
record.housingneeds_b = 1
record.housingneeds_f = 1
household_validator.validate_accessibility_requirements(record)
expect(record.errors["accessibility_requirements"]).to be_empty
record.housingneeds_b = 0
record.housingneeds_c = 1
record.housingneeds_f = 1
household_validator.validate_accessibility_requirements(record)
expect(record.errors["accessibility_requirements"]).to be_empty
end
end
describe "referral validations" do
context "when homelessness is assessed" do
it "can be internal transfer" do

16
spec/services/csv/case_log_csv_service_spec.rb

@ -105,12 +105,9 @@ RSpec.describe Csv::CaseLogCsvService do
leftreg
reservist
preg_occ
housingneeds_a
housingneeds_b
housingneeds_c
housingneeds_f
housingneeds_g
housingneeds_h
housingneeds
housingneeds_type
housingneeds_other
illness
illness_type_4
illness_type_5
@ -165,6 +162,12 @@ RSpec.describe Csv::CaseLogCsvService do
hbrentshortfall
tshortfall_known
tshortfall
housingneeds_a
housingneeds_b
housingneeds_c
housingneeds_f
housingneeds_g
housingneeds_h
property_owner_organisation
property_manager_organisation
sale_or_letting
@ -187,7 +190,6 @@ RSpec.describe Csv::CaseLogCsvService do
wtcharge
wtshortfall
refused
housingneeds
wchchrg
newprop
old_form_id

Loading…
Cancel
Save