Browse Source

Add and derive totelder field (#167)

pull/168/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
a8b7af0cbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/models/case_log.rb
  2. 7
      db/migrate/20211214153925_add_totelder.rb
  3. 5
      db/schema.rb
  4. 10
      spec/models/case_log_spec.rb

8
app/models/case_log.rb

@ -133,7 +133,7 @@ class CaseLog < ApplicationRecord
enum postcode_known: POLAR, _suffix: true enum postcode_known: POLAR, _suffix: true
enum la_known: POLAR, _suffix: true enum la_known: POLAR, _suffix: true
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at renttype lettype is_la_inferred totchild].freeze AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at renttype lettype is_la_inferred totchild totelder].freeze
OPTIONAL_FIELDS = %w[postcode_known OPTIONAL_FIELDS = %w[postcode_known
la_known la_known
first_time_property_let_as_social_housing].freeze first_time_property_let_as_social_housing].freeze
@ -214,6 +214,12 @@ private
self.is_la_inferred = false if is_la_inferred.nil? self.is_la_inferred = false if is_la_inferred.nil?
self.la = get_la(property_postcode) self.la = get_la(property_postcode)
self.totchild = get_totchild self.totchild = get_totchild
self.totelder = get_totelder
end
def get_totelder
ages = [age1, age2, age3, age4, age5, age6, age7, age8]
ages.count { |x| !x.nil? && x >= 60 }
end end
def get_totchild def get_totchild

7
db/migrate/20211214153925_add_totelder.rb

@ -0,0 +1,7 @@
class AddTotelder < ActiveRecord::Migration[6.1]
def change
change_table :case_logs, bulk: true do |t|
t.column :totelder, :integer
end
end
end

5
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_12_14_143841) do ActiveRecord::Schema.define(version: 2021_12_14_153925) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -171,11 +171,12 @@ ActiveRecord::Schema.define(version: 2021_12_14_143841) do
t.integer "lettype" t.integer "lettype"
t.integer "postcode_known" t.integer "postcode_known"
t.integer "la_known" t.integer "la_known"
t.boolean "is_la_inferred"
t.integer "day" t.integer "day"
t.integer "month" t.integer "month"
t.integer "year" t.integer "year"
t.boolean "is_la_inferred"
t.integer "totchild" t.integer "totchild"
t.integer "totelder"
t.index ["discarded_at"], name: "index_case_logs_on_discarded_at" 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 ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id" t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id"

10
spec/models/case_log_spec.rb

@ -1070,6 +1070,9 @@ RSpec.describe Form, type: :model do
relat3: "Child - includes young adult and grown-up", relat3: "Child - includes young adult and grown-up",
relat4: "Other", relat4: "Other",
relat5: "Child - includes young adult and grown-up", relat5: "Child - includes young adult and grown-up",
age4: 60,
age2: 14,
age6: 88,
}) })
end end
@ -1079,6 +1082,13 @@ RSpec.describe Form, type: :model do
record_from_db = ActiveRecord::Base.connection.execute("select totchild from case_logs where id=#{household_case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select totchild from case_logs where id=#{household_case_log.id}").to_a[0]
expect(record_from_db["totchild"]).to eq(3) expect(record_from_db["totchild"]).to eq(3)
end end
it "correctly derives and saves totelder" do
household_case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select totelder from case_logs where id=#{household_case_log.id}").to_a[0]
expect(record_from_db["totelder"]).to eq(2)
end
end end
end end
end end

Loading…
Cancel
Save