Browse Source

derive has_benefits

pull/213/head
Kat 4 years ago
parent
commit
633e79ea93
  1. 8
      app/models/case_log.rb
  2. 1
      db/schema.rb
  3. 9
      spec/models/case_log_spec.rb

8
app/models/case_log.rb

@ -274,6 +274,7 @@ private
self.property_postcode = nil self.property_postcode = nil
self.postcode = nil self.postcode = nil
self.postcod2 = nil self.postcod2 = nil
self.has_benefits = get_has_benefits
end end
def get_totelder def get_totelder
@ -303,6 +304,13 @@ private
end end
end end
def get_has_benefits
return "yes" if ["1. Housing benefit",
"6. Universal Credit with housing element (excluding housing benefit)",
"7. Universal Credit (without housing element)",
"8. Housing benefit and Universal Credit (without housing element)"].include?(hb)
end
def all_fields_completed? def all_fields_completed?
mandatory_fields.none? { |field| public_send(field).nil? if respond_to?(field) } mandatory_fields.none? { |field| public_send(field).nil? if respond_to?(field) }
end end

1
db/schema.rb

@ -178,6 +178,7 @@ ActiveRecord::Schema.define(version: 2022_01_10_115720) do
t.integer "totelder" t.integer "totelder"
t.integer "totadult" t.integer "totadult"
t.integer "net_income_known" t.integer "net_income_known"
t.string "has_benefits"
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"

9
spec/models/case_log_spec.rb

@ -1038,6 +1038,8 @@ RSpec.describe Form, type: :model do
other_hhmemb: 6, other_hhmemb: 6,
rent_type: "London living rent", rent_type: "London living rent",
needstype: "General needs", needstype: "General needs",
hb: "1. Housing benefit",
hbrentshortfall: "No",
}) })
end end
@ -1218,5 +1220,12 @@ RSpec.describe Form, type: :model do
expect(record_from_db["totadult"]).to eq(3) expect(record_from_db["totadult"]).to eq(3)
end end
end end
it "correctly derives and saves has_benefits" do
case_log.reload
record_from_db = ActiveRecord::Base.connection.execute("select has_benefits from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["has_benefits"]).to eq("yes")
end
end end
end end

Loading…
Cancel
Save