From 6204088f485c686c9eaef53ad6e3e542885c037d Mon Sep 17 00:00:00 2001 From: Matthew Phelan Date: Fri, 22 Oct 2021 11:57:26 +0100 Subject: [PATCH 1/4] reason_for_leaving_last_settled_home validation added --- app/models/case_log.rb | 6 ++++++ config/forms/2021_2022.json | 2 +- db/schema.rb | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index 5ad7e515e..16c08bc0b 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -38,6 +38,12 @@ class CaseLogValidator < ActiveModel::Validator record.errors.add :other_reason_for_leaving_last_settled_home, "The other reason must not be provided if the reason for leaving settled home was not other" end end + + def validate_reason_for_leaving_last_settled_home(record) + if record.reason_for_leaving_last_settled_home == "Do not know" && record.benefit_cap_spare_room_subsidy != "Do not know" + record.errors.add :benefit_cap_spare_room_subsidy, "must be do not know if tenant’s main reason for leaving is do not know" + end + end def validate(record) # If we've come from the form UI we only want to validate the specific fields diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 47378e9f0..1d2d72b57 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -612,7 +612,7 @@ "header": "Leaving their last settled home", "description": "", "questions": { - "last_settled_home": { + "reason_for_leaving_last_settled_home": { "header": "What is the tenant’s main reason for leaving?", "hint_text": "", "type": "radio", diff --git a/db/schema.rb b/db/schema.rb index 03a612ecd..42b14adc9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -130,8 +130,8 @@ ActiveRecord::Schema.define(version: 2021_10_15_090040) do t.boolean "reasonable_preference_reason_medical_grounds" t.boolean "reasonable_preference_reason_avoid_hardship" t.boolean "reasonable_preference_reason_do_not_know" - t.datetime "discarded_at" t.integer "property_number_of_times_relet" + t.datetime "discarded_at" t.index ["discarded_at"], name: "index_case_logs_on_discarded_at" end From b724c99985719c8d89cbbfc60b88a55eba4b1c7c Mon Sep 17 00:00:00 2001 From: Matthew Phelan Date: Mon, 25 Oct 2021 08:45:40 +0100 Subject: [PATCH 2/4] CLDC/477 Code review updates --- db/schema.rb | 1 - spec/models/case_log_spec.rb | 8 ++++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index 7c9383cf0..20dbfc383 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -131,7 +131,6 @@ ActiveRecord::Schema.define(version: 2021_10_15_090040) do t.boolean "reasonable_preference_reason_medical_grounds" t.boolean "reasonable_preference_reason_avoid_hardship" t.boolean "reasonable_preference_reason_do_not_know" - t.integer "property_number_of_times_relet" t.datetime "discarded_at" t.index ["discarded_at"], name: "index_case_logs_on_discarded_at" end diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index d3e4d74a9..132705e67 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -57,6 +57,14 @@ RSpec.describe Form, type: :model do }.to raise_error(ActiveRecord::RecordInvalid) end end + 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", + benefit_cap_spare_room_subsidy: "Yes - benefit cap") + }.to raise_error(ActiveRecord::RecordInvalid) + end + end 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 { From 2b82c56c195b83ae89b7281e7abd98a5aa08906f Mon Sep 17 00:00:00 2001 From: Matthew Phelan Date: Mon, 25 Oct 2021 10:50:24 +0100 Subject: [PATCH 3/4] API documentation added --- docs/api/DLUHC-CORE-Data.v1.json | 50 ++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/docs/api/DLUHC-CORE-Data.v1.json b/docs/api/DLUHC-CORE-Data.v1.json index 015e98a07..506180df9 100644 --- a/docs/api/DLUHC-CORE-Data.v1.json +++ b/docs/api/DLUHC-CORE-Data.v1.json @@ -781,11 +781,55 @@ }, "reason_for_leaving_last_settled_home": { "type": "string", - "minLength": 1 + "minLength": 1, + "enum": [ + "Permanently decanted from another property owned by this landlord", + "Left home country as a refugee", + "Loss of tied accommodation", + "Domestic abuse", + "(Non violent) relationship breakdown with partner", + "Asked to leave by family or friends", + "Racial harassment", + "Other problems with neighbours", + "Property unsuitable because of overcrowding", + "End of assured shorthold tenancy - no fault", + "End of assured shorthold tenancy - tenant's fault", + "End of fixed term tenancy - no fault", + "End of fixed term tenancy - tenant's fault", + "Repossession", + "Under occupation - offered incentive to downsize", + "Under occupation - no incentive", + "Property unsuitable because of ill health / disability", + "Property unsuitable because of poor condition", + "Couldn't afford fees attached to renewing the tenancy", + "Couldn't afford increase in rent", + "Couldn't afford rent or mortgage - welfare reforms", + "Couldn't afford rent or mortgage - employment", + "Couldn't afford rent or mortgage - other", + "To move nearer to family / friends / school", + "To move nearer to work", + "To move to accomodation with support", + "To move to independent accomodation", + "Hate crime", + "Death of household member in last settled accomodation", + "Discharged from prison", + "Discharged from long stay hospital or similar institution", + "Other", + "Do not know", + "Prefer not to say" + ] }, "benefit_cap_spare_room_subsidy": { "type": "string", - "minLength": 1 + "minLength": 1, + "enum": [ + "Yes - benefit cap", + "Yes - removal of the spare room subsidy", + "Yes - both the benefit cap and the removal of the spare room subsidy", + "No", + "Do not know", + "Prefer not to say" + ] }, "armed_forces_active": { "type": "string", @@ -1158,4 +1202,4 @@ }, "securitySchemes": {} } -} +} \ No newline at end of file From d2623da0add54114140b6419115f1485baee9f60 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Mon, 25 Oct 2021 10:53:45 +0100 Subject: [PATCH 4/4] Updated Created http code --- docs/api/DLUHC-CORE-Data.v1.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api/DLUHC-CORE-Data.v1.json b/docs/api/DLUHC-CORE-Data.v1.json index 015e98a07..b900a1e4c 100644 --- a/docs/api/DLUHC-CORE-Data.v1.json +++ b/docs/api/DLUHC-CORE-Data.v1.json @@ -193,7 +193,7 @@ "summary": "Create New Case Log", "operationId": "post-caselog", "responses": { - "200": { + "201": { "description": "Case Log Created", "content": { "application/json": { @@ -1158,4 +1158,4 @@ }, "securitySchemes": {} } -} +} \ No newline at end of file