From 76ef1924799e0f24e779f98680975d38c102b2d7 Mon Sep 17 00:00:00 2001 From: Kat Date: Tue, 30 Nov 2021 14:41:52 +0000 Subject: [PATCH] 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 acd65bb0c..5d3608274 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -109,8 +109,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 @@ -202,6 +203,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 393589bb2..d1729ccf1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -168,6 +168,7 @@ ActiveRecord::Schema.define(version: 2021_11_30_090246) do t.bigint "owning_organisation_id" t.bigint "managing_organisation_id" t.datetime "property_void_date" + t.integer "renttype" t.index ["discarded_at"], name: "index_case_logs_on_discarded_at" t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id" diff --git a/spec/factories/case_log.rb b/spec/factories/case_log.rb index 17cc1ddff..dd636f9d9 100644 --- a/spec/factories/case_log.rb +++ b/spec/factories/case_log.rb @@ -137,7 +137,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 84602d1dc..b0a987127 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -843,4 +843,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