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