Browse Source

Make net_income_known enum

pull/192/head
baarkerlounger 3 years ago
parent
commit
678d03d74c
  1. 9
      app/models/case_log.rb
  2. 7
      app/models/constants/case_log.rb
  3. 15
      db/migrate/20220107103143_convert_net_income_known_to_enum.rb
  4. 6
      db/schema.rb
  5. 2
      spec/factories/case_log.rb
  6. 2
      spec/fixtures/complete_case_log.json

9
app/models/case_log.rb

@ -130,6 +130,7 @@ class CaseLog < ApplicationRecord
enum lettype: LET_TYPE, _suffix: true
enum postcode_known: POLAR, _suffix: true
enum la_known: POLAR, _suffix: true
enum net_income_known: NET_INCOME_KNOWN, _suffix: true
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at renttype lettype is_la_inferred totchild totelder totadult].freeze
OPTIONAL_FIELDS = %w[postcode_known
@ -316,9 +317,11 @@ private
dynamically_not_required << "tenancyother"
end
if net_income_known == "No"
if net_income_known == "Tenant prefers not to say"
dynamically_not_required << "earnings"
dynamically_not_required << "incfreq"
else
dynamically_not_required << "incref"
end
start_range = (other_hhmemb || 0) + 2
@ -329,10 +332,6 @@ private
dynamically_not_required << "ecstat#{n}"
end
if net_income_known != "Tenant prefers not to say"
dynamically_not_required << "incref"
end
required.delete_if { |key, _value| dynamically_not_required.include?(key) }
end
end

7
app/models/constants/case_log.rb

@ -1070,4 +1070,11 @@ module Constants::CaseLog
"Non-binary" => "X",
"Prefer not to say" => "R",
}.freeze
NET_INCOME_KNOWN = {
"Yes – the household has a weekly income" => 0,
"Yes – the household has a monthly income" => 1,
"Yes – the household has a yearly income" => 2,
"Tenant prefers not to say" => 3,
}.freeze
end

15
db/migrate/20220107103143_convert_net_income_known_to_enum.rb

@ -0,0 +1,15 @@
class ConvertNetIncomeKnownToEnum < ActiveRecord::Migration[7.0]
def up
change_table :case_logs, bulk: true do |t|
t.remove :net_income_known
t.column :net_income_known, :integer
end
end
def down
change_table :case_logs, bulk: true do |t|
t.remove :net_income_known
t.column :net_income_known, :string
end
end
end

6
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_12_14_163230) do
ActiveRecord::Schema.define(version: 2022_01_07_103143) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -127,7 +127,6 @@ ActiveRecord::Schema.define(version: 2021_12_14_163230) do
t.datetime "discarded_at"
t.string "tenancyother"
t.integer "override_net_income_validation"
t.string "net_income_known"
t.string "gdpr_acceptance"
t.string "gdpr_declined"
t.string "property_owner_organisation"
@ -163,9 +162,9 @@ ActiveRecord::Schema.define(version: 2021_12_14_163230) do
t.string "why_dont_you_know_la"
t.integer "unitletas"
t.integer "builtype"
t.datetime "property_void_date"
t.bigint "owning_organisation_id"
t.bigint "managing_organisation_id"
t.datetime "property_void_date"
t.integer "renttype"
t.integer "needstype"
t.integer "lettype"
@ -178,6 +177,7 @@ ActiveRecord::Schema.define(version: 2021_12_14_163230) do
t.integer "totchild"
t.integer "totelder"
t.integer "totadult"
t.integer "net_income_known"
t.index ["discarded_at"], name: "index_case_logs_on_discarded_at"
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"

2
spec/factories/case_log.rb

@ -113,7 +113,7 @@ FactoryBot.define do
discarded_at { nil }
tenancyother { nil }
override_net_income_validation { nil }
net_income_known { "Yes" }
net_income_known { "Yes – the household has a weekly income" }
gdpr_acceptance { "Yes" }
gdpr_declined { "No" }
property_owner_organisation { "Test" }

2
spec/fixtures/complete_case_log.json vendored

@ -74,7 +74,7 @@
"mrcyear": 2020,
"offered": 2,
"wchair": "Yes",
"net_income_known": "Yes",
"net_income_known": "Yes – the household has a weekly income",
"earnings": 0,
"incfreq": null,
"benefits": "Some",

Loading…
Cancel
Save