Browse Source

add wchchrg derived variable (#413)

pull/414/head
Dushan 3 years ago committed by GitHub
parent
commit
3882461017
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/models/case_log.rb
  2. 7
      db/migrate/20220322151056_add_wchchrg_derived_variable_field.rb
  3. 1
      db/schema.rb
  4. 1
      spec/fixtures/exports/case_logs.xml
  5. 154
      spec/models/case_log_spec.rb

3
app/models/case_log.rb

@ -368,6 +368,9 @@ private
self.wpschrge = weekly_value(pscharge) if pscharge.present? self.wpschrge = weekly_value(pscharge) if pscharge.present?
self.wsupchrg = weekly_value(supcharg) if supcharg.present? self.wsupchrg = weekly_value(supcharg) if supcharg.present?
self.wtcharge = weekly_value(tcharge) if tcharge.present? self.wtcharge = weekly_value(tcharge) if tcharge.present?
if is_supported_housing? && chcharge.present?
self.wchchrg = weekly_value(chcharge)
end
end end
self.has_benefits = get_has_benefits self.has_benefits = get_has_benefits
self.wtshortfall = if tshortfall && receives_housing_related_benefits? self.wtshortfall = if tshortfall && receives_housing_related_benefits?

7
db/migrate/20220322151056_add_wchchrg_derived_variable_field.rb

@ -0,0 +1,7 @@
class AddWchchrgDerivedVariableField < ActiveRecord::Migration[7.0]
def change
change_table :case_logs, bulk: true do |t|
t.decimal :wchchrg, precision: 10, scale: 2
end
end
end

1
db/schema.rb

@ -228,6 +228,7 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do
t.integer "vday" t.integer "vday"
t.integer "vmonth" t.integer "vmonth"
t.integer "vyear" t.integer "vyear"
t.decimal "wchchrg", precision: 10, scale: 2
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"
end end

1
spec/fixtures/exports/case_logs.xml vendored

@ -170,5 +170,6 @@
<vday>3</vday> <vday>3</vday>
<vmonth>11</vmonth> <vmonth>11</vmonth>
<vyear>2019</vyear> <vyear>2019</vyear>
<wchchrg/>
</form> </form>
</forms> </forms>

154
spec/models/case_log_spec.rb

@ -1404,6 +1404,160 @@ RSpec.describe CaseLog do
expect(record_from_db["housingneeds"]).to eq(3) expect(record_from_db["housingneeds"]).to eq(3)
end end
end end
context "when it is supported housing and a care home charge has been supplied" do
let!(:case_log) do
described_class.create({
managing_organisation: organisation,
owning_organisation: organisation,
needstype: 0,
})
end
context "when the care home charge is paid bi-weekly" do
it "correctly derives and saves weekly care home charge" do
case_log.update!(chcharge: 100, period: 2)
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wchchrg).to eq(50.0)
expect(record_from_db["wchchrg"]).to eq(50.0)
end
it "correctly derives floats" do
case_log.update!(chcharge: 100.12, period: 2)
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wchchrg).to eq(50.06)
expect(record_from_db["wchchrg"]).to eq(50.06)
end
end
context "when the care home charge is paid every 4 weeks" do
it "correctly derives and saves weekly care home charge" do
case_log.update!(chcharge: 120, period: 3)
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wchchrg).to eq(30.0)
expect(record_from_db["wchchrg"]).to eq(30.0)
end
it "correctly derives floats" do
case_log.update!(chcharge: 100.12, period: 3)
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wchchrg).to eq(25.03)
expect(record_from_db["wchchrg"]).to eq(25.03)
end
end
context "when the care home charge is paid every calendar month" do
it "correctly derives and saves weekly care home charge" do
case_log.update!(chcharge: 130, period: 4)
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wchchrg).to eq(30.0)
expect(record_from_db["wchchrg"]).to eq(30.0)
end
it "correctly derives floats" do
case_log.update!(chcharge: 100.12, period: 4)
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wchchrg).to eq(23.10)
expect(record_from_db["wchchrg"]).to eq(23.10)
end
end
context "when the care home charge is paid weekly for 50 weeks" do
it "correctly derives and saves weekly care home charge" do
case_log.update!(chcharge: 130, period: 5)
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wchchrg).to eq(125.0)
expect(record_from_db["wchchrg"]).to eq(125.0)
end
it "correctly derives floats" do
case_log.update!(chcharge: 100.12, period: 5)
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wchchrg).to eq(96.27)
expect(record_from_db["wchchrg"]).to eq(96.27)
end
end
context "when the care home charge is paid weekly for 49 weeks" do
it "correctly derives and saves weekly care home charge" do
case_log.update!(chcharge: 130, period: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wchchrg).to eq(122.5)
expect(record_from_db["wchchrg"]).to eq(122.5)
end
it "correctly derives floats" do
case_log.update!(chcharge: 100.12, period: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wchchrg).to eq(94.34)
expect(record_from_db["wchchrg"]).to eq(94.34)
end
end
context "when the care home charge is paid weekly for 48 weeks" do
it "correctly derives and saves weekly care home charge" do
case_log.update!(chcharge: 130, period: 7)
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wchchrg).to eq(120.0)
expect(record_from_db["wchchrg"]).to eq(120.0)
end
it "correctly derives floats" do
case_log.update!(chcharge: 100.12, period: 7)
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wchchrg).to eq(92.42)
expect(record_from_db["wchchrg"]).to eq(92.42)
end
end
context "when the care home charge is paid weekly for 47 weeks" do
it "correctly derives and saves weekly care home charge" do
case_log.update!(chcharge: 130, period: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wchchrg).to eq(117.5)
expect(record_from_db["wchchrg"]).to eq(117.5)
end
it "correctly derives floats" do
case_log.update!(chcharge: 100.12, period: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wchchrg).to eq(90.49)
expect(record_from_db["wchchrg"]).to eq(90.49)
end
end
context "when the care home charge is paid weekly for 46 weeks" do
it "correctly derives and saves weekly care home charge" do
case_log.update!(chcharge: 130, period: 9)
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wchchrg).to eq(115.0)
expect(record_from_db["wchchrg"]).to eq(115.0)
end
it "correctly derives floats" do
case_log.update!(chcharge: 100.12, period: 9)
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wchchrg).to eq(88.57)
expect(record_from_db["wchchrg"]).to eq(88.57)
end
end
context "when the care home charge is paid weekly for 52 weeks" do
it "correctly derives and saves weekly care home charge" do
case_log.update!(chcharge: 130, period: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wchchrg).to eq(130.0)
expect(record_from_db["wchchrg"]).to eq(130.0)
end
it "correctly derives floats" do
case_log.update!(chcharge: 100.12, period: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wchchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wchchrg).to eq(100.12)
expect(record_from_db["wchchrg"]).to eq(100.12)
end
end
end
end end
describe "resetting invalidated fields" do describe "resetting invalidated fields" do

Loading…
Cancel
Save