From 8d15193abca172def7ee49b9ecc92b9780a9833c Mon Sep 17 00:00:00 2001 From: Kat Date: Tue, 30 Nov 2021 09:13:31 +0000 Subject: [PATCH 1/3] Add renttype column --- db/migrate/20211130090246_add_rent_type.rb | 7 +++++++ db/schema.rb | 3 ++- spec/factories/case_log.rb | 1 + spec/fixtures/complete_case_log.json | 3 ++- 4 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20211130090246_add_rent_type.rb diff --git a/db/migrate/20211130090246_add_rent_type.rb b/db/migrate/20211130090246_add_rent_type.rb new file mode 100644 index 000000000..5df05be91 --- /dev/null +++ b/db/migrate/20211130090246_add_rent_type.rb @@ -0,0 +1,7 @@ +class AddRentType < ActiveRecord::Migration[6.1] + def change + change_table :case_logs, bulk: true do |t| + t.column :renttype, :integer + end + end +end diff --git a/db/schema.rb b/db/schema.rb index b63e15a8f..471d95a97 100644 --- a/db/schema.rb +++ b/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_25_154916) do +ActiveRecord::Schema.define(version: 2021_11_30_090246) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -166,6 +166,7 @@ ActiveRecord::Schema.define(version: 2021_11_25_154916) do t.integer "unitletas" t.integer "builtype" t.datetime "property_void_date" + t.integer "renttype" t.index ["discarded_at"], name: "index_case_logs_on_discarded_at" end diff --git a/spec/factories/case_log.rb b/spec/factories/case_log.rb index 944be4237..5e1836f7f 100644 --- a/spec/factories/case_log.rb +++ b/spec/factories/case_log.rb @@ -135,6 +135,7 @@ FactoryBot.define do armedforces { 1 } builtype { 1 } unitletas { 2 } + renttype { 1 } end created_at { Time.zone.now } updated_at { Time.zone.now } diff --git a/spec/fixtures/complete_case_log.json b/spec/fixtures/complete_case_log.json index 88e72fc34..a01ae395a 100644 --- a/spec/fixtures/complete_case_log.json +++ b/spec/fixtures/complete_case_log.json @@ -143,6 +143,7 @@ "property_wheelchair_accessible": "Yes", "void_or_renewal_date": "05/05/2020", "tenant_same_property_renewal": "Yes", - "new_build_handover_date": "01/01/2019" + "new_build_handover_date": "01/01/2019", + "renttype": 1 } } From 891bcbc8a7dd1b2651c264486eaeca9ba4bdefd2 Mon Sep 17 00:00:00 2001 From: Kat Date: Tue, 30 Nov 2021 14:41:52 +0000 Subject: [PATCH 2/3] infer renttype value from rent_type --- app/constants/db_enums.rb | 8 ++++++++ app/models/case_log.rb | 15 ++++++++++++++- db/schema.rb | 1 + spec/factories/case_log.rb | 1 - spec/models/case_log_spec.rb | 8 ++++++++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/constants/db_enums.rb b/app/constants/db_enums.rb index ad898c37a..0dc271baf 100644 --- a/app/constants/db_enums.rb +++ b/app/constants/db_enums.rb @@ -725,4 +725,12 @@ module DbEnums "A spouse / civil partner of a UK Armed Forces member who has separated or been bereaved within the last 2 years" => 5, } end + + def self.renttype + { + "Social Rent" => 1, + "Affordable Rent" => 2, + "Intermediate Rent" => 3, + } + end end diff --git a/app/models/case_log.rb b/app/models/case_log.rb index e9aab905d..c5ccf6e50 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -104,8 +104,9 @@ class CaseLog < ApplicationRecord enum unitletas: DbEnums.unitletas, _suffix: true enum builtype: DbEnums.builtype, _suffix: true enum incref: DbEnums.polar, _suffix: true + enum renttype: DbEnums.renttype, _suffix: true - AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze + AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at renttype].freeze OPTIONAL_FIELDS = %w[do_you_know_the_postcode do_you_know_the_local_authority first_time_property_let_as_social_housing].freeze @@ -197,6 +198,18 @@ class CaseLog < ApplicationRecord end end + def renttype + rent_type_mapping = { + "Social Rent" => "Social Rent", + "Affordable Rent" => "Affordable Rent", + "London Affordable Rent" => "Affordable Rent", + "Rent To Buy" => "Intermediate Rent", + "London Living Rent" => "Intermediate Rent", + "Other Intermediate Rent Product" => "Intermediate Rent", + } + rent_type_mapping[rent_type] + end + private def update_status! diff --git a/db/schema.rb b/db/schema.rb index 471d95a97..9c3feb9f6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -166,6 +166,7 @@ ActiveRecord::Schema.define(version: 2021_11_30_090246) do t.integer "unitletas" t.integer "builtype" t.datetime "property_void_date" + t.integer "renttype" t.index ["discarded_at"], name: "index_case_logs_on_discarded_at" end diff --git a/spec/factories/case_log.rb b/spec/factories/case_log.rb index 5e1836f7f..944be4237 100644 --- a/spec/factories/case_log.rb +++ b/spec/factories/case_log.rb @@ -135,7 +135,6 @@ FactoryBot.define do armedforces { 1 } builtype { 1 } unitletas { 2 } - renttype { 1 } end created_at { Time.zone.now } updated_at { Time.zone.now } diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index b52d04a63..6e3508e26 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -600,4 +600,12 @@ RSpec.describe Form, type: :model do expect(case_log.weekly_net_income).to eq(417) end end + + describe "inferred fields" do + let!(:case_log) { FactoryBot.create(:case_log, rent_type: "London Affordable Rent") } + + it "sets renttype correctly" do + expect(case_log.renttype).to eq("Affordable Rent") + end + end end From bcb9ee76dc19bf4f7d8376c348839922e908dd65 Mon Sep 17 00:00:00 2001 From: Kat Date: Tue, 30 Nov 2021 15:08:23 +0000 Subject: [PATCH 3/3] Fix typo --- config/forms/2021_2022.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json index 0b62cef59..86db34174 100644 --- a/config/forms/2021_2022.json +++ b/config/forms/2021_2022.json @@ -1546,8 +1546,8 @@ "header": "What is the reason for the property vacancy?", "hint_text": "", "type": "radio", - "answer_options": { - "0": "Renewal of fixed-term tenancy", + "answer_options": { + "0": "Renewal of fixed-term tenancy", "1": "Internal transfer (excluding renewals of a fixed-term tenancy)", "2": "Relet to tenant who occupied same property as temporary accommodation", "3": "Tenant involved in a succession downsize", @@ -1557,7 +1557,7 @@ "7": "Tenant abandoned property", "8": "Tenant evicted due to arrears", "9": "Tenant evicted due to ASB or other reason", - "10": "Previous tenant passed away (no succession)" + "10": "Previous tenant passed away (no succession)" } } }, @@ -1572,10 +1572,10 @@ "header": "What is the reason for the property vacancy?", "hint_text": "", "type": "radio", - "answer_options": { + "answer_options": { "11": "First let of newbuild property", "12": "First let of conversion/rehabilitation/acquired property", - "13": "First let of leased property" + "13": "First let of leased property" } } }, @@ -1734,7 +1734,7 @@ "type": "radio", "answer_options": { "0": "No", - "1": "Yesx" + "1": "Yes" }, "conditional_for": { "mrcdate": ["Yes"]