Browse Source

CLDC-656 housing needs derived variable (#398)

* add housing needs derived variable

* increase clarity
pull/401/head
Dushan 3 years ago committed by GitHub
parent
commit
719f43de2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      app/models/case_log.rb
  2. 7
      db/migrate/20220318140754_add_housing_needs_field.rb
  3. 1
      db/schema.rb
  4. 1
      spec/fixtures/exports/case_logs.xml
  5. 27
      spec/models/case_log_spec.rb

25
app/models/case_log.rb

@ -371,6 +371,7 @@ private
self.nocharge = household_charge&.zero? ? 1 : 0
self.underoccupation_benefitcap = 3 if renewal == 1 && year == 2021
self.ethnic = ethnic || ethnic_group
self.housingneeds = get_housingneeds
if is_renewal?
self.underoccupation_benefitcap = 2 if year == 2021
self.homeless = 2
@ -480,6 +481,30 @@ private
end
end
def get_housingneeds
return 1 if has_housingneeds?
return 2 if no_housingneeds?
return 3 if unknown_housingneeds?
end
def has_housingneeds?
if [housingneeds_a, housingneeds_b, housingneeds_c, housingneeds_f].any?(1)
1
end
end
def no_housingneeds?
if housingneeds_g == 1
1
end
end
def unknown_housingneeds?
if housingneeds_h == 1
1
end
end
def all_fields_completed?
mandatory_fields.none? { |field| public_send(field).nil? if respond_to?(field) }
end

7
db/migrate/20220318140754_add_housing_needs_field.rb

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

1
db/schema.rb

@ -224,6 +224,7 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do
t.decimal "wsupchrg", precision: 10, scale: 2
t.decimal "wtcharge", precision: 10, scale: 2
t.decimal "wtshortfall", precision: 10, scale: 2
t.integer "housingneeds"
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"
end

1
spec/fixtures/exports/case_logs.xml vendored

@ -166,5 +166,6 @@
<wsupchrg>17.5</wsupchrg>
<wtcharge>162.5</wtcharge>
<wtshortfall>6.0</wtshortfall>
<housingneeds>1</housingneeds>
</form>
</forms>

27
spec/models/case_log_spec.rb

@ -1366,6 +1366,33 @@ RSpec.describe CaseLog do
expect(case_log["referral"]).to eq(0)
end
end
context "when the data provider is filling in household needs" do
let!(:case_log) do
described_class.create({
managing_organisation: organisation,
owning_organisation: organisation,
})
end
it "correctly derives and saves housing neeeds as 1" do
case_log.update!(housingneeds_a: 1)
record_from_db = ActiveRecord::Base.connection.execute("select housingneeds from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["housingneeds"]).to eq(1)
end
it "correctly derives and saves housing neeeds as 2" do
case_log.update!(housingneeds_g: 1)
record_from_db = ActiveRecord::Base.connection.execute("select housingneeds from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["housingneeds"]).to eq(2)
end
it "correctly derives and saves housing neeeds as 3" do
case_log.update!(housingneeds_h: 1)
record_from_db = ActiveRecord::Base.connection.execute("select housingneeds from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["housingneeds"]).to eq(3)
end
end
end
describe "resetting invalidated fields" do

Loading…
Cancel
Save