diff --git a/app/constants/db_enums.rb b/app/constants/db_enums.rb index fee4ab083..fb2e51bf6 100644 --- a/app/constants/db_enums.rb +++ b/app/constants/db_enums.rb @@ -154,4 +154,15 @@ module DbEnums "Yes" => 1, } end + + def self.tenancy + { + "Fixed term – Secure" => 1, + "Fixed term – Assured Shorthold Tenancy (AST)" => 4, + "Lifetime – Secure" => 100, + "Lifetime – Assured" => 2, + "License agreement" => 5, + "Other" => 3, + } + end end diff --git a/app/models/case_log.rb b/app/models/case_log.rb index caf82db18..f995a7e8b 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -81,6 +81,8 @@ class CaseLog < ApplicationRecord enum illness_type_8: DbEnums.polar, _suffix: true enum illness_type_9: DbEnums.polar, _suffix: true enum illness_type_10: DbEnums.polar, _suffix: true + enum startertenancy: DbEnums.polar2, _suffix: true + enum tenancy: DbEnums.tenancy, _suffix: true enum rp_homeless: DbEnums.polar, _suffix: true enum rp_insan_unsat: DbEnums.polar, _suffix: true diff --git a/db/migrate/20211103090530_change_field_types.rb b/db/migrate/20211103090530_change_field_types.rb index a62c97df7..e26dd4940 100644 --- a/db/migrate/20211103090530_change_field_types.rb +++ b/db/migrate/20211103090530_change_field_types.rb @@ -42,6 +42,9 @@ class ChangeFieldTypes < ActiveRecord::Migration[6.1] t.change :cbl, "integer USING cbl::integer" t.change :chr, "integer USING chr::integer" t.change :cap, "integer USING cap::integer" + t.change :startertenancy, "integer USING startertenancy::integer" + t.change :tenancylength, "integer USING tenancylength::integer" + t.change :tenancy, "integer USING tenancy::integer" end end @@ -88,6 +91,9 @@ class ChangeFieldTypes < ActiveRecord::Migration[6.1] t.column :cbl_letting, :string t.column :chr_letting, :string t.column :cap_letting, :string + t.change :startertenancy, :string + t.change :tenancylength, :string + t.change :tenancy, :string end end end diff --git a/db/schema.rb b/db/schema.rb index 96de7b3dd..eee19a22b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -68,9 +68,9 @@ ActiveRecord::Schema.define(version: 2021_11_03_090530) do t.string "condition_effects" t.string "tenancy_code" t.string "startdate" - t.string "startertenancy" - t.string "tenancylength" - t.string "tenancy" + t.integer "startertenancy" + t.integer "tenancylength" + t.integer "tenancy" t.string "lettype" t.string "landlord" t.string "property_location" diff --git a/spec/models/case_log_spec.rb b/spec/models/case_log_spec.rb index 792667816..9f5aeae9d 100644 --- a/spec/models/case_log_spec.rb +++ b/spec/models/case_log_spec.rb @@ -294,12 +294,12 @@ RSpec.describe Form, type: :model do it "must not be provided if tenancy type is not other" do expect { - CaseLog.create!(tenancy: "Fixed", + CaseLog.create!(tenancy: "Fixed term – Secure", tenancyother: "the other reason provided") }.to raise_error(ActiveRecord::RecordInvalid) expect { - CaseLog.create!(tenancy: "Fixed", + CaseLog.create!(tenancy: "Fixed term – Secure", tenancyother: nil) }.not_to raise_error end