Browse Source

infer renttype value from rent_type

pull/123/head
Kat 4 years ago
parent
commit
891bcbc8a7
  1. 8
      app/constants/db_enums.rb
  2. 15
      app/models/case_log.rb
  3. 1
      db/schema.rb
  4. 1
      spec/factories/case_log.rb
  5. 8
      spec/models/case_log_spec.rb

8
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

15
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!

1
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

1
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 }

8
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

Loading…
Cancel
Save