Browse Source

Cldc 591/further data changes (#83)

* Remove condition_effects_prefer_not_to_say field

* Change reason type

* Remove prefer not to say from illness

* add majorrepairs,propcode and infer postcode

* Update previous location and la

* Update majorrepairs, national and reasonpref

* Update housing benefits fields

* rename file

* Add previous postcode

* Move inferred postcode to model

* refactor infered poscode method

* Remove unneeded import

* update miration and some mappings

* Remove duplicate migration command
pull/85/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
15bbe798df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      Gemfile
  2. 2
      Gemfile.lock
  3. 2
      app/admin/case_logs.rb
  4. 448
      app/constants/db_enums.rb
  5. 35
      app/models/case_log.rb
  6. 8
      app/validations/financial_validations.rb
  7. 4
      app/validations/household_validations.rb
  8. 63
      config/forms/2021_2022.json
  9. 57
      db/migrate/20211108134601_further_core_migrations.rb
  10. 25
      db/schema.rb
  11. 36
      docs/api/DLUHC-CORE-Data.v1.json
  12. 27
      spec/controllers/case_logs_controller_spec.rb
  13. 4
      spec/factories/case_log.rb
  14. 6
      spec/features/case_log_spec.rb
  15. 23
      spec/fixtures/complete_case_log.json
  16. 12
      spec/fixtures/forms/test_form.json
  17. 2
      spec/helpers/check_answers_helper_spec.rb
  18. 2
      spec/helpers/tasklist_helper_spec.rb
  19. 14
      spec/models/case_log_spec.rb
  20. 2
      spec/models/form_spec.rb

1
Gemfile

@ -29,6 +29,7 @@ gem "discard"
gem "activeadmin"
# Admin charts
gem "chartkick"
gem "uk_postcode"
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console

2
Gemfile.lock

@ -358,6 +358,7 @@ GEM
rails (>= 6.0.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
uk_postcode (2.1.6)
unicode-display_width (2.1.0)
view_component (2.39.0)
activesupport (>= 5.0.0, < 8.0)
@ -417,6 +418,7 @@ DEPENDENCIES
selenium-webdriver
simplecov
tzinfo-data
uk_postcode
web-console (>= 4.1.0)
webpacker (~> 5.0)

2
app/admin/case_logs.rb

@ -2,7 +2,7 @@ ActiveAdmin.register CaseLog do
# See permitted parameters documentation:
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
permit_params do
permitted = %i[status tenant_code age1 sex1 tenant_ethnic_group tenant_nationality previous_housing_situation armed_forces ecstat1 hhmemb relat2 age2 sex2 ecstat2 relat3 age3 sex3 ecstat3 relat4 age4 sex4 ecstat4 relat5 age5 sex5 ecstat5 relat6 age6 sex6 ecstat6 relat7 age7 person_7_gender ecstat7 relat8 age8 sex8 ecstat8 homelessness reason_for_leaving_last_settled_home benefit_cap_spare_room_subsidy armed_forces_active armed_forces_injured armed_forces_partner medical_conditions pregnancy accessibility_requirements condition_effects tenancy_code tenancy_start_date starter_tenancy fixed_term_tenancy tenancy_type letting_type letting_provider property_location previous_postcode property_relet property_vacancy_reason property_reference property_unit_type property_building_type property_number_of_bedrooms property_void_date property_major_repairs property_major_repairs_date property_number_of_times_relet property_wheelchair_accessible net_income net_income_frequency net_income_uc_proportion housing_benefit rent_frequency basic_rent service_charge personal_service_charge support_charge total_charge outstanding_amount time_lived_in_la time_on_la_waiting_list previous_la property_postcode reasonable_preference reasonable_preference_reason cbl_letting chr_letting cap_letting outstanding_rent_or_charges other_reason_for_leaving_last_settled_home accessibility_requirements_fully_wheelchair_accessible_housing accessibility_requirements_wheelchair_access_to_essential_rooms accessibility_requirements_level_access_housing accessibility_requirements_other_disability_requirements accessibility_requirements_no_disability_requirements accessibility_requirements_do_not_know accessibility_requirements_prefer_not_to_say condition_effects_vision condition_effects_hearing condition_effects_mobility condition_effects_dexterity condition_effects_stamina condition_effects_learning condition_effects_memory condition_effects_mental_health condition_effects_social_or_behavioral condition_effects_other condition_effects_prefer_not_to_say reasonable_preference_reason_homeless reasonable_preference_reason_unsatisfactory_housing reasonable_preference_reason_medical_grounds reasonable_preference_reason_avoid_hardship reasonable_preference_reason_do_not_know other_tenancy_type override_net_income_validation net_income_known]
permitted = %i[status tenant_code age1 sex1 tenant_ethnic_group tenant_nationality previous_housing_situation armed_forces ecstat1 hhmemb relat2 age2 sex2 ecstat2 relat3 age3 sex3 ecstat3 relat4 age4 sex4 ecstat4 relat5 age5 sex5 ecstat5 relat6 age6 sex6 ecstat6 relat7 age7 person_7_gender ecstat7 relat8 age8 sex8 ecstat8 homelessness reason benefit_cap_spare_room_subsidy armed_forces_active armed_forces_injured armed_forces_partner medical_conditions pregnancy accessibility_requirements condition_effects tenancy_code tenancy_start_date starter_tenancy fixed_term_tenancy tenancy_type letting_type letting_provider la previous_postcode property_relet property_vacancy_reason property_reference property_unit_type property_building_type property_number_of_bedrooms property_void_date property_major_repairs property_major_repairs_date property_number_of_times_relet property_wheelchair_accessible net_income net_income_frequency net_income_uc_proportion hb rent_frequency basic_rent service_charge personal_service_charge support_charge total_charge tshortfall time_lived_in_la time_on_la_waiting_list prevloc property_postcode reasonable_preference reasonable_preference_reason cbl_letting chr_letting cap_letting hbrentshortfall other_reason accessibility_requirements_fully_wheelchair_accessible_housing accessibility_requirements_wheelchair_access_to_essential_rooms accessibility_requirements_level_access_housing accessibility_requirements_other_disability_requirements accessibility_requirements_no_disability_requirements accessibility_requirements_do_not_know accessibility_requirements_prefer_not_to_say condition_effects_vision condition_effects_hearing condition_effects_mobility condition_effects_dexterity condition_effects_stamina condition_effects_learning condition_effects_memory condition_effects_mental_health condition_effects_social_or_behavioral condition_effects_other condition_effects_prefer_not_to_say reasonable_preference_reason_homeless reasonable_preference_reason_unsatisfactory_housing reasonable_preference_reason_medical_grounds reasonable_preference_reason_avoid_hardship reasonable_preference_reason_do_not_know other_tenancy_type override_net_income_validation net_income_known]
permitted
end

448
app/constants/db_enums.rb

@ -20,7 +20,7 @@ module DbEnums
"Not seeking work" => 6,
"Full-time student" => 7,
"Unable to work because of long term sick or disability" => 8,
"Child under 16" => 100,
"Child under 16" => 9,
"Other" => 0,
"Prefer not to say" => 10,
}
@ -63,7 +63,6 @@ module DbEnums
"Yes" => 1,
"No" => 2,
"Do not know" => 3,
"Prefer not to say" => 100,
}
end
@ -91,6 +90,8 @@ module DbEnums
"Bulgaria" => 14,
"Romania" => 15,
"Ireland" => 17,
"Slovenia" => 10,
"Croatia" => 16,
"Other EU Economic Area (EEA country)" => 11,
"Any other country" => 12,
"Prefer not to say" => 13,
@ -155,6 +156,14 @@ module DbEnums
}
end
def self.polar_with_unknown
{
"No" => 2,
"Yes" => 1,
"Do not know" => 3,
}
end
def self.tenancy
{
"Fixed term – Secure" => 1,
@ -256,4 +265,439 @@ module DbEnums
"Do not know" => 6,
}
end
def self.housing_benefit
{
"Housing Benefit, but not Universal Credit" => 1,
"Universal Credit with housing element, but not Housing Benefit" => 6,
"Universal Credit without housing element and no Housing Benefit" => 7,
"Universal Credit and Housing Benefit" => 8,
"Not Housing Benefit or Universal Credit" => 9,
"Do not know" => 3,
"Prefer not to say" => 100,
}
end
def self.reason
{
"Permanently decanted from another property owned by this landlord" => 1,
"Left home country as a refugee" => 2,
"Loss of tied accommodation" => 4,
"Domestic abuse" => 7,
"(Non violent) relationship breakdown with partner" => 8,
"Asked to leave by family or friends" => 9,
"Racial harassment" => 10,
"Other problems with neighbours" => 11,
"Property unsuitable because of overcrowding" => 12,
"End of assured shorthold tenancy - no fault" => 40,
"End of assured shorthold tenancy - tenant's fault" => 41,
"End of fixed term tenancy - no fault" => 42,
"End of fixed term tenancy - tenant's fault" => 43,
"Repossession" => 34,
"Under occupation - offered incentive to downsize" => 29,
"Under occupation - no incentive" => 30,
"Property unsuitable because of ill health / disability" => 13,
"Property unsuitable because of poor condition" => 14,
"Couldn't afford fees attached to renewing the tenancy" => 35,
"Couldn't afford increase in rent" => 36,
"Couldn't afford rent or mortgage - welfare reforms" => 37,
"Couldn't afford rent or mortgage - employment" => 38,
"Couldn't afford rent or mortgage - other" => 39,
"To move nearer to family / friends / school" => 16,
"To move nearer to work" => 17,
"To move to accomodation with support" => 18,
"To move to independent accomodation" => 19,
"Hate crime" => 31,
"Death of household member in last settled accomodation" => 46,
"Discharged from prison" => 44,
"Discharged from long stay hospital or similar institution" => 45,
"Other" => 20,
"Do not know" => 28,
"Prefer not to say" => 100,
}
end
def self.la
{
"Hartlepool" => "E06000001",
"Na h-Eileanan Siar" => "S12000013",
"Middlesbrough" => "E06000002",
"Redcar and Cleveland" => "E06000003",
"Stockton-on-Tees" => "E06000004",
"Darlington" => "E06000005",
"Halton" => "E06000006",
"Warrington" => "E06000007",
"Blackburn with Darwen" => "E06000008",
"Blackpool" => "E06000009",
"Kingston upon Hull, City of" => "E06000010",
"East Riding of Yorkshire" => "E06000011",
"North East Lincolnshire" => "E06000012",
"North Lincolnshire" => "E06000013",
"York" => "E06000014",
"Derby" => "E06000015",
"Leicester" => "E06000016",
"Rutland" => "E06000017",
"Nottingham" => "E06000018",
"Herefordshire, County of" => "E06000019",
"Telford and Wrekin" => "E06000020",
"Stoke-on-Trent" => "E06000021",
"Bath and North East Somerset" => "E06000022",
"Bristol, City of" => "E06000023",
"North Somerset" => "E06000024",
"South Gloucestershire" => "E06000025",
"Plymouth" => "E06000026",
"Torbay" => "E06000027",
"Swindon" => "E06000030",
"Peterborough" => "E06000031",
"Luton" => "E06000032",
"Southend-on-Sea" => "E06000033",
"Thurrock" => "E06000034",
"Medway" => "E06000035",
"Bracknell Forest" => "E06000036",
"West Berkshire" => "E06000037",
"Reading" => "E06000038",
"Slough" => "E06000039",
"Windsor and Maidenhead" => "E06000040",
"Wokingham" => "E06000041",
"Milton Keynes" => "E06000042",
"Brighton and Hove" => "E06000043",
"Portsmouth" => "E06000044",
"Southampton" => "E06000045",
"Isle of Wight" => "E06000046",
"County Durham" => "E06000047",
"Cheshire East" => "E06000049",
"Cheshire West and Chester" => "E06000050",
"Shropshire" => "E06000051",
"Cornwall" => "E06000052",
"Isles of Scilly" => "E06000053",
"Wiltshire" => "E06000054",
"Bedford" => "E06000055",
"Central Bedfordshire" => "E06000056",
"Northumberland" => "E06000057",
"Bournemouth, Christchurch and Poole" => "E06000058",
"North Warwickshire" => "E07000218",
"Nuneaton and Bedworth" => "E07000219",
"Rugby" => "E07000220",
"Stratford-on-Avon" => "E07000221",
"Warwick" => "E07000222",
"Adur" => "E07000223",
"Arun" => "E07000224",
"Chichester" => "E07000225",
"Crawley" => "E07000226",
"Horsham" => "E07000227",
"Mid Sussex" => "E07000228",
"Worthing" => "E07000229",
"Bromsgrove" => "E07000234",
"Malvern Hills" => "E07000235",
"Redditch" => "E07000236",
"Worcester" => "E07000237",
"Wychavon" => "E07000238",
"Wyre Forest" => "E07000239",
"St Albans" => "E07000240",
"Welwyn Hatfield" => "E07000241",
"East Hertfordshire" => "E07000242",
"Stevenage" => "E07000243",
"East Suffolk" => "E07000244",
"West Suffolk" => "E07000245",
"Somerset West and Taunton" => "E07000246",
"Bolton" => "E08000001",
"Bury" => "E08000002",
"Manchester" => "E08000003",
"Oldham" => "E08000004",
"Rochdale" => "E08000005",
"Salford" => "E08000006",
"Stockport" => "E08000007",
"Tameside" => "E08000008",
"Trafford" => "E08000009",
"Wigan" => "E08000010",
"Knowsley" => "E08000011",
"Liverpool" => "E08000012",
"St. Helens" => "E08000013",
"Sefton" => "E08000014",
"Wirral" => "E08000015",
"Barnsley" => "E08000016",
"Doncaster" => "E08000017",
"Rotherham" => "E08000018",
"Sheffield" => "E08000019",
"Newcastle upon Tyne" => "E08000021",
"North Tyneside" => "E08000022",
"South Tyneside" => "E08000023",
"Sunderland" => "E08000024",
"Birmingham" => "E08000025",
"Coventry" => "E08000026",
"Dudley" => "E08000027",
"Sandwell" => "E08000028",
"Solihull" => "E08000029",
"Walsall" => "E08000030",
"Dorset" => "E06000059",
"Wolverhampton" => "E08000031",
"Falkirk" => "S12000014",
"Highland" => "S12000017",
"Inverclyde" => "S12000018",
"Midlothian" => "S12000019",
"Moray" => "S12000020",
"North Ayrshire" => "S12000021",
"Orkney Islands" => "S12000023",
"Scottish Borders" => "S12000026",
"Shetland Islands" => "S12000027",
"South Ayrshire" => "S12000028",
"South Lanarkshire" => "S12000029",
"Stirling" => "S12000030",
"Aberdeen City" => "S12000033",
"Aberdeenshire" => "S12000034",
"Argyll and Bute" => "S12000035",
"City of Edinburgh" => "S12000036",
"Renfrewshire" => "S12000038",
"West Dunbartonshire" => "S12000039",
"West Lothian" => "S12000040",
"Angus" => "S12000041",
"Dundee City" => "S12000042",
"East Dunbartonshire" => "S12000045",
"Buckinghamshire" => "E06000060",
"Fife" => "S12000047",
"Cambridge" => "E07000008",
"Perth and Kinross" => "S12000048",
"East Cambridgeshire" => "E07000009",
"Glasgow City" => "S12000049",
"Fenland" => "E07000010",
"North Lanarkshire" => "S12000050",
"Huntingdonshire" => "E07000011",
"Isle of Anglesey" => "W06000001",
"South Cambridgeshire" => "E07000012",
"Gwynedd" => "W06000002",
"Allerdale" => "E07000026",
"Conwy" => "W06000003",
"Barrow-in-Furness" => "E07000027",
"Denbighshire" => "W06000004",
"Carlisle" => "E07000028",
"Flintshire" => "W06000005",
"Copeland" => "E07000029",
"Wrexham" => "W06000006",
"Eden" => "E07000030",
"Ceredigion" => "W06000008",
"South Lakeland" => "E07000031",
"Pembrokeshire" => "W06000009",
"Amber Valley" => "E07000032",
"Carmarthenshire" => "W06000010",
"Bolsover" => "E07000033",
"Swansea" => "W06000011",
"Chesterfield" => "E07000034",
"Neath Port Talbot" => "W06000012",
"Derbyshire Dales" => "E07000035",
"Bridgend" => "W06000013",
"Erewash" => "E07000036",
"Vale of Glamorgan" => "W06000014",
"High Peak" => "E07000037",
"Cardiff" => "W06000015",
"North East Derbyshire" => "E07000038",
"Rhondda Cynon Taf" => "W06000016",
"South Derbyshire" => "E07000039",
"Caerphilly" => "W06000018",
"East Devon" => "E07000040",
"Blaenau Gwent" => "W06000019",
"Exeter" => "E07000041",
"Torfaen" => "W06000020",
"Mid Devon" => "E07000042",
"Monmouthshire" => "W06000021",
"North Devon" => "E07000043",
"Newport" => "W06000022",
"South Hams" => "E07000044",
"Powys" => "W06000023",
"Teignbridge" => "E07000045",
"Merthyr Tydfil" => "W06000024",
"Torridge" => "E07000046",
"West Devon" => "E07000047",
"Eastbourne" => "E07000061",
"Hastings" => "E07000062",
"Lewes" => "E07000063",
"Rother" => "E07000064",
"Wealden" => "E07000065",
"Basildon" => "E07000066",
"Braintree" => "E07000067",
"Brentwood" => "E07000068",
"Castle Point" => "E07000069",
"Chelmsford" => "E07000070",
"Colchester" => "E07000071",
"Epping Forest" => "E07000072",
"Harlow" => "E07000073",
"Maldon" => "E07000074",
"Rochford" => "E07000075",
"Tendring" => "E07000076",
"Uttlesford" => "E07000077",
"Cheltenham" => "E07000078",
"Cotswold" => "E07000079",
"Forest of Dean" => "E07000080",
"Gloucester" => "E07000081",
"Stroud" => "E07000082",
"Tewkesbury" => "E07000083",
"Basingstoke and Deane" => "E07000084",
"East Hampshire" => "E07000085",
"King’s Lynn and West Norfolk" => "E07000146",
"Eastleigh" => "E07000086",
"North Norfolk" => "E07000147",
"Norwich" => "E07000148",
"South Norfolk" => "E07000149",
"Corby" => "E07000150",
"Daventry" => "E07000151",
"East Northamptonshire" => "E07000152",
"Kettering" => "E07000153",
"Northampton" => "E07000154",
"South Northamptonshire" => "E07000155",
"Wellingborough" => "E07000156",
"Craven" => "E07000163",
"Hambleton" => "E07000164",
"Harrogate" => "E07000165",
"Richmondshire" => "E07000166",
"Ryedale" => "E07000167",
"Scarborough" => "E07000168",
"Selby" => "E07000169",
"Ashfield" => "E07000170",
"Bassetlaw" => "E07000171",
"Broxtowe" => "E07000172",
"Gedling" => "E07000173",
"Mansfield" => "E07000174",
"Newark and Sherwood" => "E07000175",
"Rushcliffe" => "E07000176",
"Cherwell" => "E07000177",
"Oxford" => "E07000178",
"South Oxfordshire" => "E07000179",
"Vale of White Horse" => "E07000180",
"West Oxfordshire" => "E07000181",
"Mendip" => "E07000187",
"Sedgemoor" => "E07000188",
"South Somerset" => "E07000189",
"Cannock Chase" => "E07000192",
"East Staffordshire" => "E07000193",
"Lichfield" => "E07000194",
"Newcastle-under-Lyme" => "E07000195",
"South Staffordshire" => "E07000196",
"Stafford" => "E07000197",
"Staffordshire Moorlands" => "E07000198",
"Tamworth" => "E07000199",
"Babergh" => "E07000200",
"Ipswich" => "E07000202",
"Mid Suffolk" => "E07000203",
"Elmbridge" => "E07000207",
"Epsom and Ewell" => "E07000208",
"Guildford" => "E07000209",
"Mole Valley" => "E07000210",
"Reigate and Banstead" => "E07000211",
"Runnymede" => "E07000212",
"Spelthorne" => "E07000213",
"Surrey Heath" => "E07000214",
"Tandridge" => "E07000215",
"Waverley" => "E07000216",
"Woking" => "E07000217",
"Fareham" => "E07000087",
"Gosport" => "E07000088",
"Hart" => "E07000089",
"Havant" => "E07000090",
"New Forest" => "E07000091",
"Rushmoor" => "E07000092",
"Test Valley" => "E07000093",
"Winchester" => "E07000094",
"Broxbourne" => "E07000095",
"Dacorum" => "E07000096",
"Hertsmere" => "E07000098",
"North Hertfordshire" => "E07000099",
"Three Rivers" => "E07000102",
"Watford" => "E07000103",
"Ashford" => "E07000105",
"Canterbury" => "E07000106",
"Dartford" => "E07000107",
"Dover" => "E07000108",
"Gravesham" => "E07000109",
"Maidstone" => "E07000110",
"Sevenoaks" => "E07000111",
"Folkestone and Hythe" => "E07000112",
"Swale" => "E07000113",
"Thanet" => "E07000114",
"Tonbridge and Malling" => "E07000115",
"Tunbridge Wells" => "E07000116",
"Burnley" => "E07000117",
"Chorley" => "E07000118",
"Fylde" => "E07000119",
"Hyndburn" => "E07000120",
"Lancaster" => "E07000121",
"Pendle" => "E07000122",
"Preston" => "E07000123",
"Ribble Valley" => "E07000124",
"Rossendale" => "E07000125",
"South Ribble" => "E07000126",
"West Lancashire" => "E07000127",
"Wyre" => "E07000128",
"Blaby" => "E07000129",
"Charnwood" => "E07000130",
"Harborough" => "E07000131",
"Hinckley and Bosworth" => "E07000132",
"Melton" => "E07000133",
"North West Leicestershire" => "E07000134",
"Oadby and Wigston" => "E07000135",
"Boston" => "E07000136",
"East Lindsey" => "E07000137",
"Lincoln" => "E07000138",
"North Kesteven" => "E07000139",
"South Holland" => "E07000140",
"South Kesteven" => "E07000141",
"West Lindsey" => "E07000142",
"Breckland" => "E07000143",
"Broadland" => "E07000144",
"Great Yarmouth" => "E07000145",
"Bradford" => "E08000032",
"Calderdale" => "E08000033",
"Kirklees" => "E08000034",
"Leeds" => "E08000035",
"Wakefield" => "E08000036",
"Gateshead" => "E08000037",
"City of London" => "E09000001",
"Barking and Dagenham" => "E09000002",
"Barnet" => "E09000003",
"Bexley" => "E09000004",
"Brent" => "E09000005",
"Bromley" => "E09000006",
"Camden" => "E09000007",
"Croydon" => "E09000008",
"Ealing" => "E09000009",
"Enfield" => "E09000010",
"Greenwich" => "E09000011",
"Hackney" => "E09000012",
"Hammersmith and Fulham" => "E09000013",
"Haringey" => "E09000014",
"Harrow" => "E09000015",
"Havering" => "E09000016",
"Hillingdon" => "E09000017",
"Hounslow" => "E09000018",
"Islington" => "E09000019",
"Kensington and Chelsea" => "E09000020",
"Kingston upon Thames" => "E09000021",
"Lambeth" => "E09000022",
"Lewisham" => "E09000023",
"Merton" => "E09000024",
"Newham" => "E09000025",
"Redbridge" => "E09000026",
"Richmond upon Thames" => "E09000027",
"Southwark" => "E09000028",
"Sutton" => "E09000029",
"Tower Hamlets" => "E09000030",
"Waltham Forest" => "E09000031",
"Wandsworth" => "E09000032",
"Westminster" => "E09000033",
"Antrim and Newtownabbey" => "N09000001",
"Armagh City, Banbridge and Craigavon" => "N09000002",
"Belfast" => "N09000003",
"Causeway Coast and Glens" => "N09000004",
"Derry City and Strabane" => "N09000005",
"Fermanagh and Omagh" => "N09000006",
"Lisburn and Castlereagh" => "N09000007",
"Mid and East Antrim" => "N09000008",
"Mid Ulster" => "N09000009",
"Newry, Mourne and Down" => "N09000010",
"Ards and North Down" => "N09000011",
"Clackmannanshire" => "S12000005",
"Dumfries and Galloway" => "S12000006",
"East Ayrshire" => "S12000008",
"East Lothian" => "S12000010",
"East Renfrewshire" => "S12000011",
}
end
end

35
app/models/case_log.rb

@ -101,7 +101,14 @@ class CaseLog < ApplicationRecord
enum period: DbEnums.period, _suffix: true
enum layear: DbEnums.latime, _suffix: true
enum lawaitlist: DbEnums.latime, _suffix: true
enum reasonpref: DbEnums.polar2, _suffix: true
enum reasonpref: DbEnums.polar_with_unknown, _suffix: true
enum reason: DbEnums.reason, _suffix: true
enum la: DbEnums.la, _suffix: true
enum prevloc: DbEnums.la, _suffix: true
enum majorrepairs: DbEnums.polar, _suffix: true
enum hb: DbEnums.housing_benefit, _suffix: true
enum hbrentshortfall: DbEnums.polar_with_unknown, _suffix: true
enum property_relet: DbEnums.polar, _suffix: true
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze
@ -132,6 +139,30 @@ class CaseLog < ApplicationRecord
end
end
def postcode
if property_postcode.present?
UKPostcode.parse(property_postcode).outcode
end
end
def postcod2
if property_postcode.present?
UKPostcode.parse(property_postcode).incode
end
end
def ppostc1
if previous_postcode.present?
UKPostcode.parse(previous_postcode).outcode
end
end
def ppostc2
if previous_postcode.present?
UKPostcode.parse(previous_postcode).incode
end
end
def applicable_income_range
return unless ecstat1
@ -163,7 +194,7 @@ private
dynamically_not_required = []
if reason_for_leaving_last_settled_home != "Other"
if reason != "Other"
dynamically_not_required << "other_reason_for_leaving_last_settled_home"
end

8
app/validations/financial_validations.rb

@ -2,11 +2,11 @@ module FinancialValidations
# Validations methods need to be called 'validate_<page_name>' to run on model save
# or 'validate_' to run on submit as well
def validate_outstanding_rent_amount(record)
if record.outstanding_rent_or_charges == "Yes" && record.outstanding_amount.blank?
record.errors.add :outstanding_amount, "You must answer the oustanding amout question if you have outstanding rent or charges."
if record.hbrentshortfall == "Yes" && record.tshortfall.blank?
record.errors.add :tshortfall, "You must answer the oustanding amout question if you have outstanding rent or charges."
end
if record.outstanding_rent_or_charges == "No" && record.outstanding_amount.present?
record.errors.add :outstanding_amount, "You must not answer the oustanding amout question if you don't have outstanding rent or charges."
if record.hbrentshortfall == "No" && record.tshortfall.present?
record.errors.add :tshortfall, "You must not answer the oustanding amout question if you don't have outstanding rent or charges."
end
end

4
app/validations/household_validations.rb

@ -16,11 +16,11 @@ module HouseholdValidations
end
def validate_other_reason_for_leaving_last_settled_home(record)
validate_other_field(record, "reason_for_leaving_last_settled_home", "other_reason_for_leaving_last_settled_home")
validate_other_field(record, "reason", "other_reason_for_leaving_last_settled_home")
end
def validate_reason_for_leaving_last_settled_home(record)
if record.reason_for_leaving_last_settled_home == "Do not know" && record.underoccupation_benefitcap != "Do not know"
if record.reason == "Do not know" && record.underoccupation_benefitcap != "Do not know"
record.errors.add :underoccupation_benefitcap, "must be do not know if tenant’s main reason for leaving is do not know"
end
end

63
config/forms/2021_2022.json

@ -273,21 +273,23 @@
"type": "radio",
"answer_options": {
"0": "UK national resident in UK",
"1": "A current or former reserve in the UK Armed Forces (exc. National Service)",
"2": "UK national returning from residence overseas",
"3": "Czech Republic",
"4": "Estonia",
"5": "Hungary",
"6": "Latvia",
"7": "Lithuania",
"8": "Poland",
"9": "Slovakia",
"10": "Bulgaria",
"11": "Romania",
"12": "Ireland",
"13": "Other EU Economic Area (EEA country)",
"14": "Any other country",
"15": "Prefer not to say"
"1": "UK national returning from residence overseas",
"2": "Czech Republic",
"3": "Estonia",
"4": "Hungary",
"5": "Latvia",
"6": "Lithuania",
"7": "Poland",
"8": "Slovakia",
"9": "Bulgaria",
"10": "Romania",
"11": "Ireland",
"12": "Slovakia",
"13":"Slovenia",
"14": "Croatia",
"15": "Other EU Economic Area (EEA country)",
"16": "Any other country",
"17": "Prefer not to say"
}
}
}
@ -796,7 +798,7 @@
"header": "Leaving their last settled home",
"description": "",
"questions": {
"reason_for_leaving_last_settled_home": {
"reason": {
"header": "What is the tenant’s main reason for leaving?",
"hint_text": "",
"type": "radio",
@ -934,8 +936,7 @@
"answer_options": {
"0": "Yes",
"1": "No",
"2": "Do not know",
"3": "Prefer not to say"
"2": "Prefer not to say"
}
}
}
@ -999,9 +1000,7 @@
"illness_type_6": "Memory",
"illness_type_7": "Mental health - such as depression, anxiety, schizophrenia or bipolar",
"illness_type_9": "Socially or behaviourally - such as those associated with autism spectral disorder (ASD) including Aspergers’ or attention deficit hyperactivity disorder (ADHD))",
"illness_type_10": "Other",
"divider": true,
"condition_effects_prefer_not_to_say": "Prefer not to say"
"illness_type_10": "Other"
}
}
}
@ -1144,7 +1143,7 @@
"header": "",
"description": "",
"questions": {
"property_location": {
"la": {
"check_answer_label": "Property Location",
"header": "Property location",
"hint_text": "",
@ -1527,7 +1526,7 @@
"header": "",
"description": "",
"questions": {
"property_reference": {
"propcode": {
"check_answer_label": "What’s the property reference?",
"header": "What's the property reference?",
"hint_text": "",
@ -1576,7 +1575,7 @@
"header": "",
"description": "",
"questions": {
"property_major_repairs": {
"majorrepairs": {
"check_answer_label": "Were major repairs carried out during the void period?",
"header": "Were any major repairs completed during the void period?",
"hint_text": "",
@ -1709,7 +1708,7 @@
"header": "",
"description": "",
"questions": {
"housing_benefit": {
"hb": {
"check_answer_label": "Universal Credit & Housing Benefit",
"header": "Is the tenant likely to be in receipt of any of these housing-related benefits?",
"hint_text": "",
@ -1822,20 +1821,21 @@
"step": 1,
"readonly": true
},
"outstanding_rent_or_charges": {
"hbrentshortfall": {
"check_answer_label": "After housing benefit and/or housing element of UC payment is received, will there be an outstanding amount for basic rent and/or benefit eligible charges?",
"header": "After housing benefit and/or housing element of UC payment is received, will there be an outstanding amount for basic rent and/or benefit eligible charges?",
"hint_text": "",
"type": "radio",
"answer_options": {
"0": "Yes",
"1": "No"
"1": "No",
"2": "Do not know"
},
"conditional_for": {
"outstanding_amount": ["Yes"]
"tshortfall": ["Yes"]
}
},
"outstanding_amount": {
"tshortfall": {
"check_answer_label": "Outstanding amount",
"header": "What do you expect the amount to be?",
"hint_text": "If the amount is unknown you can estimate",
@ -1903,7 +1903,7 @@
"header": "",
"description": "",
"questions": {
"previous_la": {
"prevloc": {
"check_answer_label": "The LA in which household lived immediately before this letting\t",
"header": "Which local authority area did the household live in immediately before this letting?",
"hint_text": "Includes temporary accommodation",
@ -2249,7 +2249,8 @@
"type": "radio",
"answer_options": {
"0": "Yes",
"1": "No"
"1": "No",
"2": "Do not know"
},
"conditional_for": {
"reasonable_preference_reason": ["Yes"]

57
db/migrate/20211108134601_further_core_migrations.rb

@ -0,0 +1,57 @@
class FurtherCoreMigrations < ActiveRecord::Migration[6.1]
def up
change_table :case_logs, bulk: true do |t|
t.remove :condition_effects_prefer_not_to_say
t.remove :reason_for_leaving_last_settled_home
t.column :reason, :integer
t.remove :property_reference
t.column :propcode, :string
t.remove :property_major_repairs
t.column :majorrepairs, :integer
t.remove :property_location
t.column :la, :string
t.remove :previous_la
t.column :prevloc, :string
t.remove :housing_benefit
t.column :hb, :integer
t.remove :outstanding_rent_or_charges
t.column :hbrentshortfall, :integer
t.remove :outstanding_amount
t.column :tshortfall, :integer
t.column :postcode, :string
t.column :postcod2, :string
t.column :ppostc1, :string
t.column :ppostc2, :string
t.remove :property_relet
t.column :property_relet, :integer
end
end
def down
change_table :case_logs, bulk: true do |t|
t.column :condition_effects_prefer_not_to_say, :integer
t.column :reason_for_leaving_last_settled_home, :string
t.remove :reason
t.column :property_reference, :string
t.remove :propcode
t.column :property_major_repairs, :string
t.remove :majorrepairs
t.column :property_location, :string
t.remove :la
t.column :previous_la, :string
t.remove :prevloc
t.column :housing_benefit, :string
t.remove :hb
t.column :outstanding_rent_or_charges, :string
t.remove :hbrentshortfall
t.column :outstanding_amount, :string
t.remove :tshortfall
t.remove :postcode
t.remove :postcod2
t.remove :ppostc1
t.remove :ppostc2
t.remove :property_relet
t.column :property_relet, :string
end
end
end

25
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_11_08_091320) do
ActiveRecord::Schema.define(version: 2021_11_08_134601) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -57,7 +57,6 @@ ActiveRecord::Schema.define(version: 2021_11_08_091320) do
t.string "sex8"
t.integer "ecstat8"
t.integer "homeless"
t.string "reason_for_leaving_last_settled_home"
t.integer "underoccupation_benefitcap"
t.integer "leftreg"
t.integer "reservist"
@ -73,40 +72,32 @@ ActiveRecord::Schema.define(version: 2021_11_08_091320) do
t.integer "tenancy"
t.string "lettype"
t.integer "landlord"
t.string "property_location"
t.string "previous_postcode"
t.string "property_relet"
t.integer "rsnvac"
t.string "property_reference"
t.integer "unittype_gn"
t.string "property_building_type"
t.integer "beds"
t.string "property_void_date"
t.string "property_major_repairs"
t.string "property_major_repairs_date"
t.integer "offered"
t.integer "wchair"
t.integer "earnings"
t.integer "incfreq"
t.integer "benefits"
t.string "housing_benefit"
t.integer "period"
t.integer "brent"
t.integer "scharge"
t.integer "pscharge"
t.integer "supcharg"
t.integer "tcharge"
t.string "outstanding_amount"
t.integer "layear"
t.integer "lawaitlist"
t.string "previous_la"
t.string "property_postcode"
t.integer "reasonpref"
t.string "reasonable_preference_reason"
t.integer "cbl"
t.integer "chr"
t.integer "cap"
t.string "outstanding_rent_or_charges"
t.string "other_reason_for_leaving_last_settled_home"
t.integer "housingneeds_a"
t.integer "housingneeds_b"
@ -125,7 +116,6 @@ ActiveRecord::Schema.define(version: 2021_11_08_091320) do
t.integer "illness_type_7"
t.integer "illness_type_9"
t.integer "illness_type_10"
t.integer "condition_effects_prefer_not_to_say"
t.integer "rp_homeless"
t.integer "rp_insan_unsat"
t.integer "rp_medwel"
@ -146,6 +136,19 @@ ActiveRecord::Schema.define(version: 2021_11_08_091320) do
t.string "needs_type"
t.string "sale_completion_date"
t.string "purchaser_code"
t.integer "reason"
t.string "propcode"
t.integer "majorrepairs"
t.string "la"
t.string "prevloc"
t.integer "hb"
t.integer "hbrentshortfall"
t.integer "tshortfall"
t.string "postcode"
t.string "postcod2"
t.string "ppostc1"
t.string "ppostc2"
t.integer "property_relet"
t.index ["discarded_at"], name: "index_case_logs_on_discarded_at"
end

36
docs/api/DLUHC-CORE-Data.v1.json

@ -293,7 +293,7 @@
"sex8": "Prefer not to say",
"ecstat8": "Child under 16",
"homeless": "No",
"reason_for_leaving_last_settled_home": "Other problems with neighbours",
"reason": "Other problems with neighbours",
"underoccupation_benefitcap": "No",
"leftreg": "No",
"reservist": "No",
@ -309,7 +309,7 @@
"tenancy": "Fixed term – Secure",
"lettype": "Affordable Rent - General Needs",
"landlord": "This landlord",
"property_location": "Barnet",
"la": "Barnet",
"previous_postcode": "NW1 5TY",
"property_relet": "No",
"rsnvac": "Relet - tenant abandoned property",
@ -325,24 +325,24 @@
"earnings": 1000,
"incfreq": "Monthly",
"benefits": "Some",
"housing_benefit": "Universal Credit with housing element, but not Housing Benefit",
"hb": "Universal Credit with housing element, but not Housing Benefit",
"period": "Weekly",
"brent": 200,
"scharge": 50,
"pscharge": 40,
"supcharg": 35,
"tcharge": 325,
"outstanding_amount": "Yes",
"tshortfall": "Yes",
"layear": "1 to 2 years",
"lawaitlist": "Less than 1 year",
"previous_la": "Ashford",
"prevloc": "Ashford",
"property_postcode": "SE2 6RT",
"reasonpref": "Yes",
"reasonable_preference_reason": "dummy",
"cbl": true,
"chr": false,
"cap": false,
"outstanding_rent_or_charges": 25,
"hbrentshortfall": "Yes",
"other_reason_for_leaving_last_settled_home": "Other reason",
"housingneeds_a": true,
"housingneeds_b": false,
@ -727,7 +727,7 @@
"type": "string",
"minLength": 1
},
"reason_for_leaving_last_settled_home": {
"reason": {
"type": "string",
"minLength": 1,
"enum": [
@ -836,7 +836,7 @@
"type": "string",
"minLength": 1
},
"property_location": {
"la": {
"type": "string",
"minLength": 1
},
@ -902,7 +902,7 @@
"minLength": 1,
"enum": ["All", "Some", "None", "Do not know"]
},
"housing_benefit": {
"hb": {
"type": "string",
"minLength": 1
},
@ -925,7 +925,7 @@
"tcharge": {
"type": "number"
},
"outstanding_amount": {
"tshortfall": {
"type": "string",
"minLength": 1
},
@ -937,7 +937,7 @@
"type": "string",
"minLength": 1
},
"previous_la": {
"prevloc": {
"type": "string",
"minLength": 1
},
@ -962,7 +962,7 @@
"cap": {
"type": "boolean"
},
"outstanding_rent_or_charges": {
"hbrentshortfall": {
"type": "number"
},
"other_reason_for_leaving_last_settled_home": {
@ -1082,7 +1082,7 @@
"sex8",
"ecstat8",
"homeless",
"reason_for_leaving_last_settled_home",
"reason",
"underoccupation_benefitcap",
"leftreg",
"reservist",
@ -1098,7 +1098,7 @@
"tenancy",
"lettype",
"landlord",
"property_location",
"la",
"previous_postcode",
"property_relet",
"rsnvac",
@ -1114,24 +1114,24 @@
"earnings",
"incfreq",
"benefits",
"housing_benefit",
"hb",
"period",
"brent",
"scharge",
"pscharge",
"supcharg",
"tcharge",
"outstanding_amount",
"tshortfall",
"layear",
"lawaitlist",
"previous_la",
"prevloc",
"property_postcode",
"reasonpref",
"reasonable_preference_reason",
"cbl",
"chr",
"cap",
"outstanding_rent_or_charges",
"hbrentshortfall",
"other_reason_for_leaving_last_settled_home",
"housingneeds_a",
"housingneeds_b",

27
spec/controllers/case_logs_controller_spec.rb

@ -150,6 +150,33 @@ RSpec.describe CaseLogsController, type: :controller do
expect(response).to redirect_to("/case_logs/#{id}/conditional_question_no_page")
end
end
context "partition postcode" do
let(:case_log_with_postcode) do
{
property_postcode: "M1 1AE",
previous_postcode: "M2 2AE",
page: "property_postcode",
}
end
it "saves full and partial postcodes" do
post :submit_form, params: { id: id, case_log: case_log_with_postcode }
case_log.reload
expect(case_log.property_postcode).to eq("M1 1AE")
expect(case_log.postcode).to eq("M1")
expect(case_log.postcod2).to eq("1AE")
end
it "saves full and partial previous postcodes" do
post :submit_form, params: { id: id, case_log: case_log_with_postcode }
case_log.reload
expect(case_log.previous_postcode).to eq("M2 2AE")
expect(case_log.ppostc1).to eq("M2")
expect(case_log.ppostc2).to eq("2AE")
end
end
end
describe "get_next_page_path" do

4
spec/factories/case_log.rb

@ -4,8 +4,8 @@ FactoryBot.define do
trait :in_progress do
status { 1 }
tenant_code { "TH356" }
property_postcode { "SW2 6HI" }
previous_postcode { "P0 5ST" }
property_postcode { "P0 5ST" }
previous_postcode { "SW2 6HI" }
age1 { "17" }
end
trait :completed do

6
spec/features/case_log_spec.rb

@ -25,7 +25,7 @@ RSpec.describe "Test Features" do
click_button("Save and continue")
choose("case-log-benefits-all-field")
click_button("Save and continue")
choose("case-log-housing-benefit-housing-benefit-but-not-universal-credit-field")
choose("case-log-hb-housing-benefit-but-not-universal-credit-field")
click_button("Save and continue")
end
@ -175,8 +175,8 @@ RSpec.describe "Test Features" do
end
it "displays number answers in inputs if they are already saved" do
visit("/case_logs/#{id}/previous_postcode")
expect(page).to have_field("case-log-previous-postcode-field", with: "P0 5ST")
visit("/case_logs/#{id}/property_postcode")
expect(page).to have_field("case-log-property-postcode-field", with: "P0 5ST")
end
it "displays text answers in inputs if they are already saved" do

23
spec/fixtures/complete_case_log.json vendored

@ -38,7 +38,7 @@
"sex8": "Prefer not to say",
"ecstat8": "Child under 16",
"homeless": "Yes - other homelessness",
"reason_for_leaving_last_settled_home": "Other problems with neighbours",
"reason": 1,
"underoccupation_benefitcap": "No",
"leftreg": "No - they left up to 5 years ago",
"reservist": "No",
@ -54,8 +54,8 @@
"tenancy": "Fixed term – Secure",
"lettype": "Affordable Rent - General Needs",
"landlord": "This landlord",
"property_location": "Barnet",
"previous_postcode": "NW1 5TY",
"la": "Barnet",
"property_postcode": "NW1 5TY",
"property_relet": "No",
"rsnvac": "Relet - tenant abandoned property",
"property_reference": "P9876",
@ -71,7 +71,7 @@
"earnings": 0,
"incfreq": null,
"benefits": "Some",
"housing_benefit": "Universal Credit with housing element, but not Housing Benefit",
"hb": "Universal Credit with housing element, but not Housing Benefit",
"period": "Fortnightly",
"brent": 200,
"scharge": 50,
@ -81,14 +81,15 @@
"outstanding_amount": "Yes",
"layear": "1 to 2 years",
"lawaitlist": "Less than 1 year",
"previous_la": "Ashford",
"property_postcode": "SE2 6RT",
"prevloc": "Ashford",
"previous_postcode": "SE2 6RT",
"reasonpref": "Yes",
"reasonable_preference_reason": "dummy",
"cbl": "Yes",
"chr": "Yes",
"cap": "No",
"outstanding_rent_or_charges": 25,
"hbrentshortfall": "Yes",
"tshortfall": 12,
"other_reason_for_leaving_last_settled_home": null,
"housingneeds_a": "Yes",
"housingneeds_b": "No",
@ -125,6 +126,12 @@
"intermediate_rent_product_name": "",
"needs_type": "",
"sale_completion_date": "",
"purchaser_code": ""
"purchaser_code": "",
"propcode": "123",
"majorrepairs": "Yes",
"postcode": "a1",
"postcod2": "w3",
"ppostc1": "w3",
"ppostc2": "w3"
}
}

12
spec/fixtures/forms/test_form.json vendored

@ -348,7 +348,7 @@
},
"housing_benefit": {
"questions": {
"housing_benefit": {
"hb": {
"check_answer_label": "Universal Credit & Housing Benefit",
"header": "Is the tenant likely to be in receipt of any of these housing-related benefits?",
"type": "radio",
@ -494,14 +494,20 @@
}
}
},
"previous_postcode": {
"property_postcode": {
"questions": {
"previous_postcode": {
"property_postcode": {
"check_answer_label": "Postcode of previous accomodation if the household has moved from settled accommodation",
"header": "Postcode for the previous accommodation",
"hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed",
"type": "text",
"conditional_for": { "faake_key": "fake_condition" }
},
"previous_postcode": {
"check_answer_label": "Postcode of previous accomodation if the household has moved from settled accommodation",
"header": "Postcode for the previous accommodation",
"hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed",
"type": "text"
}
}
}

2
spec/helpers/check_answers_helper_spec.rb

@ -127,7 +127,7 @@ RSpec.describe CheckAnswersHelper do
it "returns total questions" do
result = total_questions(subsection, case_log, form)
expect(result.class).to eq(Hash)
expected_keys = %w[earnings incfreq benefits housing_benefit]
expected_keys = %w[earnings incfreq benefits hb]
expect(result.keys).to eq(expected_keys)
end

2
spec/helpers/tasklist_helper_spec.rb

@ -33,7 +33,7 @@ RSpec.describe TasklistHelper do
case_log["earnings"] = "value"
case_log["incfreq"] = "Weekly"
case_log["benefits"] = "All"
case_log["housing_benefit"] = "Do not know"
case_log["hb"] = "Do not know"
status = get_subsection_status("income_and_benefits", case_log, income_and_benefits_questions)
expect(status).to eq(:completed)

14
spec/models/case_log_spec.rb

@ -60,7 +60,7 @@ RSpec.describe Form, type: :model do
context "reason for leaving last settled home validation" do
it "Reason for leaving must be don't know if reason for leaving settled home (Q9a) is don't know." do
expect {
CaseLog.create!(reason_for_leaving_last_settled_home: "Do not know",
CaseLog.create!(reason: "Do not know",
underoccupation_benefitcap: "Yes - benefit cap")
}.to raise_error(ActiveRecord::RecordInvalid)
end
@ -68,14 +68,14 @@ RSpec.describe Form, type: :model do
context "other reason for leaving last settled home validation" do
it "must be provided if main reason for leaving last settled home was given as other" do
expect {
CaseLog.create!(reason_for_leaving_last_settled_home: "Other",
CaseLog.create!(reason: "Other",
other_reason_for_leaving_last_settled_home: nil)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "must not be provided if the main reason for leaving settled home is not other" do
expect {
CaseLog.create!(reason_for_leaving_last_settled_home: "Repossession",
CaseLog.create!(reason: "Repossession",
other_reason_for_leaving_last_settled_home: "the other reason provided")
}.to raise_error(ActiveRecord::RecordInvalid)
end
@ -139,15 +139,15 @@ RSpec.describe Form, type: :model do
context "outstanding rent or charges validation" do
it "must be anwered if answered yes to outstanding rent or charges" do
expect {
CaseLog.create!(outstanding_rent_or_charges: "Yes",
outstanding_amount: nil)
CaseLog.create!(hbrentshortfall: "Yes",
tshortfall: nil)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "must be not be anwered if answered no to outstanding rent or charges" do
expect {
CaseLog.create!(outstanding_rent_or_charges: "No",
outstanding_amount: 99)
CaseLog.create!(hbrentshortfall: "No",
tshortfall: 99)
}.to raise_error(ActiveRecord::RecordInvalid)
end
end

2
spec/models/form_spec.rb

@ -39,7 +39,7 @@ RSpec.describe Form, type: :model do
it "returns all questions for subsection" do
result = form.questions_for_subsection(subsection)
expect(result.length).to eq(4)
expect(result.keys).to eq(%w[earnings incfreq benefits housing_benefit])
expect(result.keys).to eq(%w[earnings incfreq benefits hb])
end
end
end

Loading…
Cancel
Save