Browse Source

Cldc 629 household situation (#298)

* Update household situation section questions #1

* fix typo

* update prevten content

* update homeless and benefitcap questions

* Add location questions to houshold situation

* Update reasonable preference and letting allocation questions

* Update depends on for postcode and referral

* fix content for non renewal household situation questions

* fix test

* update inferred conditions

* remove eval
pull/299/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
d77b1c3c05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 58
      app/models/case_log.rb
  2. 62
      app/models/constants/case_log.rb
  3. 9
      app/models/form/page.rb
  4. 2
      app/models/validations/local_authority_validations.rb
  5. 717
      config/forms/2021_2022.json
  6. 9
      db/migrate/20220209105333_fix_typo.rb
  7. 7
      db/migrate/20220209132411_add_previous_postcode_known.rb
  8. 7
      db/migrate/20220209155009_add_unknown_letting_allocation.rb
  9. 6
      db/schema.rb
  10. 22
      docs/api/DLUHC-CORE-Data.v1.json
  11. 6
      spec/factories/case_log.rb
  12. 2
      spec/features/form/check_answers_page_spec.rb
  13. 4
      spec/fixtures/complete_case_log.json
  14. 20
      spec/fixtures/exports/case_logs.xml
  15. 20
      spec/fixtures/forms/2021_2022.json
  16. 66
      spec/models/case_log_spec.rb
  17. 2
      spec/models/form_spec.rb
  18. 3
      spec/models/validations/local_authority_validations_spec.rb

58
app/models/case_log.rb

@ -38,8 +38,10 @@ class CaseLog < ApplicationRecord
validates_with CaseLogValidator validates_with CaseLogValidator
before_validation :process_postcode_changes!, if: :property_postcode_changed? before_validation :process_postcode_changes!, if: :property_postcode_changed?
before_validation :process_previous_postcode_changes!, if: :previous_postcode_changed?
before_validation :reset_invalidated_dependent_fields! before_validation :reset_invalidated_dependent_fields!
before_validation :reset_location_fields!, unless: :postcode_known? before_validation :reset_location_fields!, unless: :postcode_known?
before_validation :reset_previous_location_fields!, unless: :previous_postcode_known?
before_validation :set_derived_fields! before_validation :set_derived_fields!
before_save :update_status! before_save :update_status!
@ -49,7 +51,7 @@ class CaseLog < ApplicationRecord
scope :for_organisation, ->(org) { where(owning_organisation: org).or(where(managing_organisation: org)) } scope :for_organisation, ->(org) { where(owning_organisation: org).or(where(managing_organisation: org)) }
enum status: STATUS enum status: STATUS
enum letting_in_sheltered_accomodation: SHELTERED_ACCOMODATION enum letting_in_sheltered_accommodation: SHELTERED_ACCOMMODATION
enum ethnic: ETHNIC enum ethnic: ETHNIC
enum national: NATIONAL, _suffix: true enum national: NATIONAL, _suffix: true
enum ecstat1: ECSTAT, _suffix: true enum ecstat1: ECSTAT, _suffix: true
@ -109,9 +111,9 @@ class CaseLog < ApplicationRecord
enum rp_medwel: POLAR, _suffix: true enum rp_medwel: POLAR, _suffix: true
enum rp_hardship: POLAR, _suffix: true enum rp_hardship: POLAR, _suffix: true
enum rp_dontknow: POLAR, _suffix: true enum rp_dontknow: POLAR, _suffix: true
enum cbl: POLAR2, _suffix: true enum cbl: POLAR, _suffix: true
enum chr: POLAR2, _suffix: true enum chr: POLAR, _suffix: true
enum cap: POLAR2, _suffix: true enum cap: POLAR, _suffix: true
enum wchair: POLAR2, _suffix: true enum wchair: POLAR2, _suffix: true
enum incfreq: INCFREQ, _suffix: true enum incfreq: INCFREQ, _suffix: true
enum benefits: BENEFITS, _suffix: true enum benefits: BENEFITS, _suffix: true
@ -135,7 +137,9 @@ class CaseLog < ApplicationRecord
enum needstype: NEEDS_TYPE, _suffix: true enum needstype: NEEDS_TYPE, _suffix: true
enum lettype: LET_TYPE, _suffix: true enum lettype: LET_TYPE, _suffix: true
enum postcode_known: POLAR, _suffix: true enum postcode_known: POLAR, _suffix: true
enum previous_postcode_known: POLAR, _suffix: true
enum la_known: POLAR, _suffix: true enum la_known: POLAR, _suffix: true
enum previous_la_known: POLAR, _suffix: true
enum net_income_known: NET_INCOME_KNOWN, _suffix: true enum net_income_known: NET_INCOME_KNOWN, _suffix: true
enum household_charge: POLAR, _suffix: true enum household_charge: POLAR, _suffix: true
enum is_carehome: POLAR, _suffix: true enum is_carehome: POLAR, _suffix: true
@ -180,6 +184,10 @@ class CaseLog < ApplicationRecord
postcode_known == "Yes" postcode_known == "Yes"
end end
def previous_postcode_known?
previous_postcode_known == "Yes"
end
def weekly_net_income def weekly_net_income
return unless earnings && incfreq return unless earnings && incfreq
@ -264,24 +272,40 @@ private
end end
def process_postcode_changes! def process_postcode_changes!
return if property_postcode.blank? process_postcode(property_postcode, "postcode_known", "is_la_inferred", "la", "postcode", "postcod2")
end
def process_previous_postcode_changes!
process_postcode(previous_postcode, "previous_postcode_known", "is_previous_la_inferred", "prevloc", "ppostc1", "ppostc2")
end
self.postcode_known = "Yes" def process_postcode(postcode, postcode_known_key, la_inferred_key, la_key, outcode_key, incode_key)
inferred_la = get_inferred_la(property_postcode) return if postcode.blank?
self.is_la_inferred = inferred_la.present?
self.la = inferred_la if inferred_la.present? self[postcode_known_key] = "Yes"
self.postcode = UKPostcode.parse(property_postcode).outcode inferred_la = get_inferred_la(postcode)
self.postcod2 = UKPostcode.parse(property_postcode).incode self[la_inferred_key] = inferred_la.present?
self[la_key] = inferred_la if inferred_la.present?
self[outcode_key] = UKPostcode.parse(postcode).outcode
self[incode_key] = UKPostcode.parse(postcode).incode
end end
def reset_location_fields! def reset_location_fields!
if is_la_inferred == true reset_location(is_la_inferred, "la", "is_la_inferred", "property_postcode", "postcode", "postcod2")
self.la = nil end
def reset_previous_location_fields!
reset_location(is_previous_la_inferred, "prevloc", "is_previous_la_inferred", "previous_postcode", "ppostc1", "ppostc2")
end
def reset_location(is_inferred, la_key, is_inferred_key, postcode_key, incode_key, outcode_key)
if is_inferred
self[la_key] = nil
end end
self.is_la_inferred = false self[is_inferred_key] = false
self.property_postcode = nil self[postcode_key] = nil
self.postcode = nil self[incode_key] = nil
self.postcod2 = nil self[outcode_key] = nil
end end
def get_totelder def get_totelder

62
app/models/constants/case_log.rb

@ -2,7 +2,7 @@ module Constants::CaseLog
BENEFITCAP = { BENEFITCAP = {
"Yes - benefit cap" => 5, "Yes - benefit cap" => 5,
"Yes - removal of the spare room subsidy" => 4, "Yes - removal of the spare room subsidy" => 4,
"Yes - both the benefit cap and the removal of the spare room subsidy" => 6, "Yes - both" => 6,
"No" => 2, "No" => 2,
"Don’t know" => 3, "Don’t know" => 3,
"Prefer not to say" => 100, "Prefer not to say" => 100,
@ -57,8 +57,8 @@ module Constants::CaseLog
}.freeze }.freeze
HOMELESS = { HOMELESS = {
"Yes - assessed as homeless by a local authority and owed a homelessness duty. Including if threatened with homelessness within 56 days" => 11, "Assessed as homeless (or threatened with homelessness within 56 days) by a local authority and owed a homelessness duty" => 11,
"Yes - other homelessness" => 7, "Other homeless - not found statutorily homeless but considered homeless by landlord" => 7,
"No" => 1, "No" => 1,
}.freeze }.freeze
@ -104,11 +104,11 @@ module Constants::CaseLog
PREVIOUS_TENANCY = { PREVIOUS_TENANCY = {
"Owner occupation (private)" => 26, "Owner occupation (private)" => 26,
"Owner occupation (low cost home ownership)" => 27, "Owner occupation (low-cost home ownership)" => 27,
"Private sector tenancy" => 3, "Private sector tenancy" => 3,
"Tied housing or rented with job" => 4, "Tied housing or rented with job" => 4,
"Supported housing" => 6, "Supported housing" => 6,
"Sheltered accomodation" => 8, "Sheltered accommodation" => 8,
"Residential care home" => 9, "Residential care home" => 9,
"Living with friends or family" => 28, "Living with friends or family" => 28,
"Refuge" => 21, "Refuge" => 21,
@ -121,11 +121,11 @@ module Constants::CaseLog
"Home Office Asylum Support" => 24, "Home Office Asylum Support" => 24,
"Children’s home or foster care" => 13, "Children’s home or foster care" => 13,
"Rough sleeping" => 19, "Rough sleeping" => 19,
"Other" => 25, "Any other accommodation" => 25,
"Fixed term Local Authority General Needs tenancy" => 30, "Fixed-term local authority general needs tenancy" => 30,
"Lifetime Local Authority General Needs tenancy" => 31, "Lifetime local authority general needs tenancy" => 31,
"Fixed term PRP General Needs tenancy" => 32, "Fixed-term private registered provider (PRP) general needs tenancy" => 32,
"Lifetime PRP General Needs tenancy" => 33, "Lifetime private registered provider (PRP) general needs tenancy" => 33,
}.freeze }.freeze
RESERVIST = { RESERVIST = {
@ -219,10 +219,10 @@ module Constants::CaseLog
LATIME = { LATIME = {
"Just moved to local authority area" => 1, "Just moved to local authority area" => 1,
"Less than 1 year" => 2, "Less than 1 year" => 2,
"1 to 2 years" => 7, "1 year but under 2 years" => 7,
"2 to 3 years" => 8, "2 years but under 3 years" => 8,
"3 to 4 years" => 9, "3 years but under 4 years" => 9,
"4 to 5 years" => 10, "4 years but under 5 years" => 10,
"5 years or more" => 5, "5 years or more" => 5,
"Don’t know" => 6, "Don’t know" => 6,
}.freeze }.freeze
@ -242,36 +242,36 @@ module Constants::CaseLog
"Left home country as a refugee" => 2, "Left home country as a refugee" => 2,
"Loss of tied accommodation" => 4, "Loss of tied accommodation" => 4,
"Domestic abuse" => 7, "Domestic abuse" => 7,
"(Non violent) relationship breakdown with partner" => 8, "Relationship breakdown (non-violent) with partner" => 8,
"Asked to leave by family or friends" => 9, "Asked to leave by family or friends" => 9,
"Racial harassment" => 10, "Racial harassment" => 10,
"Other problems with neighbours" => 11, "Other problems with neighbours" => 11,
"Property unsuitable because of overcrowding" => 12, "Property unsuitable because of overcrowding" => 12,
"End of assured shorthold tenancy - no fault" => 40, "End of assured shorthold tenancy - no fault" => 40,
"End of assured shorthold tenancy - tenant’s fault" => 41, "End of assured shorthold tenancy - eviction or tenant at fault" => 41,
"End of fixed term tenancy - no fault" => 42, "End of fixed term tenancy - no fault" => 42,
"End of fixed term tenancy - tenant’s fault" => 43, "End of fixed term tenancy - eviction or tenant at fault" => 43,
"Repossession" => 34, "Repossession" => 34,
"Under occupation - offered incentive to downsize" => 29, "Under occupation - offered incentive to downsize" => 29,
"Under occupation - no incentive" => 30, "Under occupation - no incentive" => 30,
"Property unsuitable because of ill health / disability" => 13, "Property unsuitable because of ill health or disability" => 13,
"Property unsuitable because of poor condition" => 14, "Property unsuitable because of poor condition" => 14,
"Couldn't afford fees attached to renewing the tenancy" => 35, "Couldnt afford fees attached to renewing the tenancy" => 35,
"Couldn't afford increase in rent" => 36, "Couldnt afford increase in rent" => 36,
"Couldn't afford rent or mortgage - welfare reforms" => 37, "Couldnt afford rent or mortgage - welfare reforms" => 37,
"Couldn't afford rent or mortgage - employment" => 38, "Couldnt afford rent or mortgage - employment" => 38,
"Couldn't afford rent or mortgage - other" => 39, "Couldnt afford rent or mortgage - other" => 39,
"To move nearer to family / friends / school" => 16, "To move nearer to family, friends or school" => 16,
"To move nearer to work" => 17, "To move nearer to work" => 17,
"To move to accomodation with support" => 18, "To move to accommodation with support" => 18,
"To move to independent accomodation" => 19, "To move to independent accommodation" => 19,
"Hate crime" => 31, "Hate crime" => 31,
"Death of household member in last settled accomodation" => 46, "Death of household member in last settled accommodation" => 46,
"Discharged from prison" => 44, "Discharged from prison" => 44,
"Discharged from long stay hospital or similar institution" => 45, "Discharged from long stay hospital or similar institution" => 45,
"Other" => 20, "Other" => 20,
"Don’t know" => 28, "Don’t know" => 28,
"Prefer not to say" => 100, "Tenant prefers not to say" => 100,
}.freeze }.freeze
ENGLISH_LA = { ENGLISH_LA = {
@ -1087,7 +1087,7 @@ module Constants::CaseLog
"completed" => 2, "completed" => 2,
}.freeze }.freeze
SHELTERED_ACCOMODATION = { SHELTERED_ACCOMMODATION = {
"Yes - sheltered housing" => 1, "Yes - sheltered housing" => 1,
"Yes - extra care housing" => 2, "Yes - extra care housing" => 2,
"No" => 3, "No" => 3,
@ -1119,9 +1119,9 @@ module Constants::CaseLog
NON_TEMP_ACCOMMODATION = ["Tied housing or rented with job", NON_TEMP_ACCOMMODATION = ["Tied housing or rented with job",
"Supported housing", "Supported housing",
"Sheltered accomodation", "Sheltered accommodation",
"Home Office Asylum Support", "Home Office Asylum Support",
"Other"].freeze "Any other accommodation"].freeze
OPTIONAL_FIELDS = %w[postcode_known la_known first_time_property_let_as_social_housing tenant_code propcode].freeze OPTIONAL_FIELDS = %w[postcode_known la_known first_time_property_let_as_social_housing tenant_code propcode].freeze
end end

9
app/models/form/page.rb

@ -44,12 +44,19 @@ private
}.compact }.compact
end end
def send_chain(arr, case_log)
Array(arr).inject(case_log) { |o, a| o.public_send(*a) }
end
def depends_on_met(case_log) def depends_on_met(case_log)
return true unless depends_on return true unless depends_on
depends_on.any? do |conditions_set| depends_on.any? do |conditions_set|
conditions_set.all? do |question, value| conditions_set.all? do |question, value|
value.nil? ? case_log[question] == value : !case_log[question].nil? && case_log[question] == value parts = question.split(".")
case_log_value = send_chain(parts, case_log)
value.nil? ? case_log_value == value : !case_log_value.nil? && case_log_value == value
end end
end end
end end

2
app/models/validations/local_authority_validations.rb

@ -4,7 +4,7 @@ module Validations::LocalAuthorityValidations
def validate_previous_accommodation_postcode(record) def validate_previous_accommodation_postcode(record)
postcode = record.previous_postcode postcode = record.previous_postcode
if postcode.present? && !postcode.match(POSTCODE_REGEXP) if record.previous_postcode_known == "Yes" && (postcode.blank? || !postcode.match(POSTCODE_REGEXP))
error_message = I18n.t("validations.postcode") error_message = I18n.t("validations.postcode")
record.errors.add :previous_postcode, error_message record.errors.add :previous_postcode, error_message
end end

717
config/forms/2021_2022.json

File diff suppressed because it is too large Load Diff

9
db/migrate/20220209105333_fix_typo.rb

@ -0,0 +1,9 @@
class FixTypo < ActiveRecord::Migration[7.0]
def up
rename_column :case_logs, :letting_in_sheltered_accomodation, :letting_in_sheltered_accommodation
end
def down
rename_column :case_logs, :letting_in_sheltered_accommodation, :letting_in_sheltered_accomodation
end
end

7
db/migrate/20220209132411_add_previous_postcode_known.rb

@ -0,0 +1,7 @@
class AddPreviousPostcodeKnown < ActiveRecord::Migration[7.0]
change_table :case_logs, bulk: true do |t|
t.column :previous_postcode_known, :integer
t.column :previous_la_known, :integer
t.column :is_previous_la_inferred, :boolean
end
end

7
db/migrate/20220209155009_add_unknown_letting_allocation.rb

@ -0,0 +1,7 @@
class AddUnknownLettingAllocation < ActiveRecord::Migration[7.0]
def change
change_table :case_logs, bulk: true do |t|
t.column :letting_allocation_unknown, :boolean
end
end
end

6
db/schema.rb

@ -176,7 +176,7 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do
t.string "has_benefits" t.string "has_benefits"
t.integer "nocharge" t.integer "nocharge"
t.integer "is_carehome" t.integer "is_carehome"
t.integer "letting_in_sheltered_accomodation" t.integer "letting_in_sheltered_accommodation"
t.integer "household_charge" t.integer "household_charge"
t.integer "referral" t.integer "referral"
t.decimal "brent", precision: 10, scale: 2 t.decimal "brent", precision: 10, scale: 2
@ -187,6 +187,10 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do
t.decimal "tshortfall", precision: 10, scale: 2 t.decimal "tshortfall", precision: 10, scale: 2
t.decimal "chcharge", precision: 10, scale: 2 t.decimal "chcharge", precision: 10, scale: 2
t.integer "declaration" t.integer "declaration"
t.integer "previous_postcode_known"
t.integer "previous_la_known"
t.boolean "is_previous_la_inferred"
t.boolean "letting_allocation_unknown"
t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id" t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id" t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id"
end end

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

@ -331,7 +331,7 @@
"supcharg": 35, "supcharg": 35,
"tcharge": 325, "tcharge": 325,
"tshortfall": "Yes", "tshortfall": "Yes",
"layear": "1 to 2 years", "layear": "1 year but under 2 years",
"lawaitlist": "Less than 1 year", "lawaitlist": "Less than 1 year",
"prevloc": "Ashford", "prevloc": "Ashford",
"property_postcode": "SE2 6RT", "property_postcode": "SE2 6RT",
@ -733,36 +733,36 @@
"Left home country as a refugee", "Left home country as a refugee",
"Loss of tied accommodation", "Loss of tied accommodation",
"Domestic abuse", "Domestic abuse",
"(Non violent) relationship breakdown with partner", "Relationship breakdown (non-violent) with partner",
"Asked to leave by family or friends", "Asked to leave by family or friends",
"Racial harassment", "Racial harassment",
"Other problems with neighbours", "Other problems with neighbours",
"Property unsuitable because of overcrowding", "Property unsuitable because of overcrowding",
"End of assured shorthold tenancy - no fault", "End of assured shorthold tenancy - no fault",
"End of assured shorthold tenancy - tenant’s fault", "End of assured shorthold tenancy - eviction or tenant at fault",
"End of fixed term tenancy - no fault", "End of fixed term tenancy - no fault",
"End of fixed term tenancy - tenant’s fault", "End of fixed term tenancy - eviction or tenant at fault",
"Repossession", "Repossession",
"Under occupation - offered incentive to downsize", "Under occupation - offered incentive to downsize",
"Under occupation - no incentive", "Under occupation - no incentive",
"Property unsuitable because of ill health / disability", "Property unsuitable because of ill health or disability",
"Property unsuitable because of poor condition", "Property unsuitable because of poor condition",
"Couldn’t afford fees attached to renewing the tenancy", "Couldn’t afford fees attached to renewing the tenancy",
"Couldn’t afford increase in rent", "Couldn’t afford increase in rent",
"Couldn’t afford rent or mortgage - welfare reforms", "Couldn’t afford rent or mortgage - welfare reforms",
"Couldn’t afford rent or mortgage - employment", "Couldn’t afford rent or mortgage - employment",
"Couldn’t afford rent or mortgage - other", "Couldn’t afford rent or mortgage - other",
"To move nearer to family / friends / school", "To move nearer to family, friends or school",
"To move nearer to work", "To move nearer to work",
"To move to accomodation with support", "To move to accommodation with support",
"To move to independent accomodation", "To move to independent accommodation",
"Hate crime", "Hate crime",
"Death of household member in last settled accomodation", "Death of household member in last settled accommodation",
"Discharged from prison", "Discharged from prison",
"Discharged from long stay hospital or similar institution", "Discharged from long stay hospital or similar institution",
"Other", "Other",
"Don’t know", "Don’t know",
"Prefer not to say" "Tenant prefers not to say"
] ]
}, },
"underoccupation_benefitcap": { "underoccupation_benefitcap": {
@ -771,7 +771,7 @@
"enum": [ "enum": [
"Yes - benefit cap", "Yes - benefit cap",
"Yes - removal of the spare room subsidy", "Yes - removal of the spare room subsidy",
"Yes - both the benefit cap and the removal of the spare room subsidy", "Yes - both",
"No", "No",
"Don’t know", "Don’t know",
"Prefer not to say" "Prefer not to say"

6
spec/factories/case_log.rb

@ -47,7 +47,7 @@ FactoryBot.define do
age2 { 32 } age2 { 32 }
sex2 { "Male" } sex2 { "Male" }
ecstat2 { "Not seeking work" } ecstat2 { "Not seeking work" }
homeless { "Yes - other homelessness" } homeless { "Other homeless - not found statutorily homeless but considered homeless by landlord" }
underoccupation_benefitcap { "No" } underoccupation_benefitcap { "No" }
leftreg { "No - they left up to 5 years ago" } leftreg { "No - they left up to 5 years ago" }
reservist { "No" } reservist { "No" }
@ -75,7 +75,7 @@ FactoryBot.define do
pscharge { 40 } pscharge { 40 }
supcharg { 35 } supcharg { 35 }
tcharge { 325 } tcharge { 325 }
layear { "1 to 2 years" } layear { "1 year but under 2 years" }
lawaitlist { "Less than 1 year" } lawaitlist { "Less than 1 year" }
property_postcode { "NW1 5TY" } property_postcode { "NW1 5TY" }
reasonpref { "Yes" } reasonpref { "Yes" }
@ -144,7 +144,7 @@ FactoryBot.define do
has_benefits { "Yes" } has_benefits { "Yes" }
is_carehome { "No" } is_carehome { "No" }
chcharge { 7 } chcharge { 7 }
letting_in_sheltered_accomodation { "No" } letting_in_sheltered_accommodation { "No" }
la_known { "Yes" } la_known { "Yes" }
declaration { "Yes" } declaration { "Yes" }
end end

2
spec/features/form/check_answers_page_spec.rb

@ -179,7 +179,7 @@ RSpec.describe "Form Check Answers Page" do
managing_organisation: user.organisation, managing_organisation: user.organisation,
tenant_code: nil, tenant_code: nil,
age1: nil, age1: nil,
layear: "1 to 2 years", layear: "1 year but under 2 years",
lawaitlist: "Less than 1 year", lawaitlist: "Less than 1 year",
property_postcode: "NW1 5TY", property_postcode: "NW1 5TY",
reason: "Permanently decanted from another property owned by this landlord", reason: "Permanently decanted from another property owned by this landlord",

4
spec/fixtures/complete_case_log.json vendored

@ -84,7 +84,7 @@
"supcharg": 35, "supcharg": 35,
"tcharge": 325, "tcharge": 325,
"outstanding_amount": "Yes", "outstanding_amount": "Yes",
"layear": "1 to 2 years", "layear": "1 year but under 2 years",
"lawaitlist": "Less than 1 year", "lawaitlist": "Less than 1 year",
"prevloc": "Ashford", "prevloc": "Ashford",
"previous_postcode": "SE2 6RT", "previous_postcode": "SE2 6RT",
@ -143,7 +143,7 @@
"household_charge": "Yes", "household_charge": "Yes",
"is_carehome": "Yes", "is_carehome": "Yes",
"chcharge": "6", "chcharge": "6",
"letting_in_sheltered_accomodation": "No", "letting_in_sheltered_accommodation": "No",
"declaration": "Yes" "declaration": "Yes"
} }
} }

20
spec/fixtures/exports/case_logs.xml vendored

@ -41,7 +41,7 @@
<age8/> <age8/>
<sex8/> <sex8/>
<ecstat8/> <ecstat8/>
<homeless>Yes - other homelessness</homeless> <homeless>Other homeless - not found statutorily homeless but considered homeless by landlord</homeless>
<underoccupation_benefitcap>No</underoccupation_benefitcap> <underoccupation_benefitcap>No</underoccupation_benefitcap>
<leftreg>No - they left up to 5 years ago</leftreg> <leftreg>No - they left up to 5 years ago</leftreg>
<reservist>No</reservist> <reservist>No</reservist>
@ -62,7 +62,7 @@
<incfreq>Weekly</incfreq> <incfreq>Weekly</incfreq>
<benefits>Some</benefits> <benefits>Some</benefits>
<period>Every 2 weeks</period> <period>Every 2 weeks</period>
<layear>1 to 2 years</layear> <layear>1 year but under 2 years</layear>
<lawaitlist>Less than 1 year</lawaitlist> <lawaitlist>Less than 1 year</lawaitlist>
<property_postcode>NW1 5TY</property_postcode> <property_postcode>NW1 5TY</property_postcode>
<reasonpref>Yes</reasonpref> <reasonpref>Yes</reasonpref>
@ -144,7 +144,7 @@
<has_benefits>Yes</has_benefits> <has_benefits>Yes</has_benefits>
<nocharge>No</nocharge> <nocharge>No</nocharge>
<is_carehome>No</is_carehome> <is_carehome>No</is_carehome>
<letting_in_sheltered_accomodation>No</letting_in_sheltered_accomodation> <letting_in_sheltered_accommodation>No</letting_in_sheltered_accommodation>
<household_charge>Yes</household_charge> <household_charge>Yes</household_charge>
<referral/> <referral/>
<brent>200.0</brent> <brent>200.0</brent>
@ -155,6 +155,10 @@
<tshortfall>12.0</tshortfall> <tshortfall>12.0</tshortfall>
<chcharge>7.0</chcharge> <chcharge>7.0</chcharge>
<declaration>Yes</declaration> <declaration>Yes</declaration>
<previous_postcode_known>Yes</previous_postcode_known>
<previous_la_known/>
<is_previous_la_inferred>false</is_previous_la_inferred>
<letting_allocation_unknown/>
</form> </form>
<form> <form>
<id>{id_2}</id> <id>{id_2}</id>
@ -197,7 +201,7 @@
<age8/> <age8/>
<sex8/> <sex8/>
<ecstat8/> <ecstat8/>
<homeless>Yes - other homelessness</homeless> <homeless>Other homeless - not found statutorily homeless but considered homeless by landlord</homeless>
<underoccupation_benefitcap>No</underoccupation_benefitcap> <underoccupation_benefitcap>No</underoccupation_benefitcap>
<leftreg>No - they left up to 5 years ago</leftreg> <leftreg>No - they left up to 5 years ago</leftreg>
<reservist>No</reservist> <reservist>No</reservist>
@ -218,7 +222,7 @@
<incfreq>Weekly</incfreq> <incfreq>Weekly</incfreq>
<benefits>Some</benefits> <benefits>Some</benefits>
<period>Every 2 weeks</period> <period>Every 2 weeks</period>
<layear>1 to 2 years</layear> <layear>1 year but under 2 years</layear>
<lawaitlist>Less than 1 year</lawaitlist> <lawaitlist>Less than 1 year</lawaitlist>
<property_postcode>NW1 5TY</property_postcode> <property_postcode>NW1 5TY</property_postcode>
<reasonpref>Yes</reasonpref> <reasonpref>Yes</reasonpref>
@ -300,7 +304,7 @@
<has_benefits>Yes</has_benefits> <has_benefits>Yes</has_benefits>
<nocharge>No</nocharge> <nocharge>No</nocharge>
<is_carehome>No</is_carehome> <is_carehome>No</is_carehome>
<letting_in_sheltered_accomodation>No</letting_in_sheltered_accomodation> <letting_in_sheltered_accommodation>No</letting_in_sheltered_accommodation>
<household_charge>Yes</household_charge> <household_charge>Yes</household_charge>
<referral/> <referral/>
<brent>200.0</brent> <brent>200.0</brent>
@ -311,5 +315,9 @@
<tshortfall>12.0</tshortfall> <tshortfall>12.0</tshortfall>
<chcharge>7.0</chcharge> <chcharge>7.0</chcharge>
<declaration>Yes</declaration> <declaration>Yes</declaration>
<previous_postcode_known>Yes</previous_postcode_known>
<previous_la_known/>
<is_previous_la_inferred>false</is_previous_la_inferred>
<letting_allocation_unknown/>
</form> </form>
</forms> </forms>

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

@ -688,16 +688,16 @@
"value": "Less than 1 year" "value": "Less than 1 year"
}, },
"2": { "2": {
"value": "1 to 2 years" "value": "1 year but under 2 years"
}, },
"3": { "3": {
"value": "2 to 3 years" "value": "2 years but under 3 years"
}, },
"4": { "4": {
"value": "3 to 4 years" "value": "3 years but under 4 years"
}, },
"5": { "5": {
"value": "4 to 5 years" "value": "4 years but under 5 years"
}, },
"6": { "6": {
"value": "5 years or more" "value": "5 years or more"
@ -726,16 +726,16 @@
"value": "Less than 1 year" "value": "Less than 1 year"
}, },
"2": { "2": {
"value": "1 to 2 years" "value": "1 year but under 2 years"
}, },
"3": { "3": {
"value": "2 to 3 years" "value": "2 years but under 3 years"
}, },
"4": { "4": {
"value": "3 to 4 years" "value": "3 years but under 4 years"
}, },
"5": { "5": {
"value": "4 to 5 years" "value": "4 years but under 5 years"
}, },
"6": { "6": {
"value": "5 years or more" "value": "5 years or more"
@ -753,7 +753,7 @@
"property_postcode": { "property_postcode": {
"questions": { "questions": {
"property_postcode": { "property_postcode": {
"check_answer_label": "Postcode of previous accomodation if the household has moved from settled accommodation", "check_answer_label": "Postcode of previous accommodation if the household has moved from settled accommodation",
"header": "Postcode for the previous accommodation", "header": "Postcode for the previous accommodation",
"hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed", "hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed",
"type": "text", "type": "text",
@ -761,7 +761,7 @@
"conditional_for": { "fake_key": "fake_condition" } "conditional_for": { "fake_key": "fake_condition" }
}, },
"previous_postcode": { "previous_postcode": {
"check_answer_label": "Postcode of previous accomodation if the household has moved from settled accommodation", "check_answer_label": "Postcode of previous accommodation if the household has moved from settled accommodation",
"header": "Postcode for the previous accommodation", "header": "Postcode for the previous accommodation",
"hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed", "hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed",
"type": "text", "type": "text",

66
spec/models/case_log_spec.rb

@ -781,15 +781,15 @@ RSpec.describe CaseLog do
}.to raise_error(ActiveRecord::RecordInvalid) }.to raise_error(ActiveRecord::RecordInvalid)
end end
it "cannot be temp accomodation if previous tenancy was non temp" do it "cannot be temp accommodation if previous tenancy was non temp" do
check_rsnvac_validation("Tied housing or rented with job") check_rsnvac_validation("Tied housing or rented with job")
check_rsnvac_validation("Supported housing") check_rsnvac_validation("Supported housing")
check_rsnvac_validation("Sheltered accomodation") check_rsnvac_validation("Sheltered accommodation")
check_rsnvac_validation("Home Office Asylum Support") check_rsnvac_validation("Home Office Asylum Support")
check_rsnvac_validation("Other") check_rsnvac_validation("Any other accommodation")
end end
it "cannot be temp accomodation if source of letting referral " do it "cannot be temp accommodation if source of letting referral " do
check_rsnvac_referral_validation("Re-located through official housing mobility scheme") check_rsnvac_referral_validation("Re-located through official housing mobility scheme")
check_rsnvac_referral_validation("Other social landlord") check_rsnvac_referral_validation("Other social landlord")
check_rsnvac_referral_validation("Police, probation or prison") check_rsnvac_referral_validation("Police, probation or prison")
@ -987,6 +987,64 @@ RSpec.describe CaseLog do
end end
end end
context "when saving previous address" do
before do
stub_request(:get, /api.postcodes.io/)
.to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\"}}", headers: {})
end
let!(:address_case_log) do
described_class.create({
managing_organisation: organisation,
owning_organisation: organisation,
previous_postcode_known: "Yes",
previous_postcode: "M1 1AE",
})
end
it "correctly infers prevloc" do
record_from_db = ActiveRecord::Base.connection.execute("select prevloc from case_logs where id=#{address_case_log.id}").to_a[0]
expect(address_case_log.prevloc).to eq("Manchester")
expect(record_from_db["prevloc"]).to eq("E08000003")
end
it "errors if the previous postcode is emptied" do
expect { address_case_log.update!({ previous_postcode: "" }) }
.to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/)
end
it "errors if the previous postcode is not valid" do
expect { address_case_log.update!({ previous_postcode: "invalid_postcode" }) }
.to raise_error(ActiveRecord::RecordInvalid, /#{I18n.t("validations.postcode")}/)
end
it "correctly resets all fields if previous postcode not known" do
address_case_log.update!({ previous_postcode_known: "No" })
record_from_db = ActiveRecord::Base.connection.execute("select prevloc, previous_postcode from case_logs where id=#{address_case_log.id}").to_a[0]
expect(record_from_db["previous_postcode"]).to eq(nil)
expect(address_case_log.prevloc).to eq(nil)
expect(record_from_db["prevloc"]).to eq(nil)
end
it "changes the prevloc if previous postcode changes from not known to known and provided" do
address_case_log.update!({ previous_postcode_known: "No" })
address_case_log.update!({ prevloc: "Westminster" })
record_from_db = ActiveRecord::Base.connection.execute("select prevloc, previous_postcode from case_logs where id=#{address_case_log.id}").to_a[0]
expect(record_from_db["previous_postcode"]).to eq(nil)
expect(address_case_log.prevloc).to eq("Westminster")
expect(record_from_db["prevloc"]).to eq("E09000033")
address_case_log.update!({ previous_postcode_known: "Yes", previous_postcode: "M1 1AD" })
record_from_db = ActiveRecord::Base.connection.execute("select prevloc, previous_postcode from case_logs where id=#{address_case_log.id}").to_a[0]
expect(record_from_db["previous_postcode"]).to eq("M1 1AD")
expect(address_case_log.prevloc).to eq("Manchester")
expect(record_from_db["prevloc"]).to eq("E08000003")
end
end
context "when saving rent and charges" do context "when saving rent and charges" do
let!(:case_log) do let!(:case_log) do
described_class.create({ described_class.create({

2
spec/models/form_spec.rb

@ -77,7 +77,7 @@ RSpec.describe Form, type: :model do
end end
def answer_local_authority(case_log) def answer_local_authority(case_log)
case_log.layear = "1 to 2 years" case_log.layear = "1 year but under 2 years"
case_log.lawaitlist = "Less than 1 year" case_log.lawaitlist = "Less than 1 year"
case_log.property_postcode = "NW1 5TY" case_log.property_postcode = "NW1 5TY"
case_log.reason = "Permanently decanted from another property owned by this landlord" case_log.reason = "Permanently decanted from another property owned by this landlord"

3
spec/models/validations/local_authority_validations_spec.rb

@ -14,18 +14,21 @@ RSpec.describe Validations::LocalAuthorityValidations do
end end
it "does not add an error if the record previous_postcode is valid (uppercase space)" do it "does not add an error if the record previous_postcode is valid (uppercase space)" do
record.previous_postcode_known = "Yes"
record.previous_postcode = "M1 1AE" record.previous_postcode = "M1 1AE"
local_auth_validator.validate_previous_accommodation_postcode(record) local_auth_validator.validate_previous_accommodation_postcode(record)
expect(record.errors).to be_empty expect(record.errors).to be_empty
end end
it "does not add an error if the record previous_postcode is valid (lowercase no space)" do it "does not add an error if the record previous_postcode is valid (lowercase no space)" do
record.previous_postcode_known = "Yes"
record.previous_postcode = "m11ae" record.previous_postcode = "m11ae"
local_auth_validator.validate_previous_accommodation_postcode(record) local_auth_validator.validate_previous_accommodation_postcode(record)
expect(record.errors).to be_empty expect(record.errors).to be_empty
end end
it "does add an error when the postcode is invalid" do it "does add an error when the postcode is invalid" do
record.previous_postcode_known = "Yes"
record.previous_postcode = "invalid" record.previous_postcode = "invalid"
local_auth_validator.validate_previous_accommodation_postcode(record) local_auth_validator.validate_previous_accommodation_postcode(record)
expect(record.errors).not_to be_empty expect(record.errors).not_to be_empty

Loading…
Cancel
Save