Browse Source

CLDC-1074: Derive landlord value from owning organisation provider type (#447)

* Derive landlord from owning org provider type

* Use valid charge values
pull/451/head
baarkerlounger 3 years ago committed by GitHub
parent
commit
00ebde0401
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/models/case_log.rb
  2. 2
      app/models/validations/financial_validations.rb
  3. 2
      spec/fixtures/complete_case_log.json
  4. 274
      spec/models/case_log_spec.rb

2
app/models/case_log.rb

@ -416,6 +416,8 @@ private
self["ecstat#{idx}"] = nil self["ecstat#{idx}"] = nil
end end
end end
self.landlord = 1 if owning_organisation.provider_type == "LA"
self.landlord = 2 if owning_organisation.provider_type == "PRP"
end end
def process_postcode_changes! def process_postcode_changes!

2
app/models/validations/financial_validations.rb

@ -122,7 +122,7 @@ private
%i[scharge pscharge supcharg].each do |charge| %i[scharge pscharge supcharg].each do |charge|
maximum = CHARGE_MAXIMUMS.dig(charge, LANDLORD_VALUES[record.landlord], NEEDSTYPE_VALUES[record.needstype]) maximum = CHARGE_MAXIMUMS.dig(charge, LANDLORD_VALUES[record.landlord], NEEDSTYPE_VALUES[record.needstype])
if maximum.present? && record[charge].present? && !weekly_value_in_range(record, charge, 0, maximum) if maximum.present? && record[:period].present? && record[charge].present? && !weekly_value_in_range(record, charge, 0.0, maximum)
record.errors.add charge, I18n.t("validations.financial.rent.#{charge}.#{LANDLORD_VALUES[record.landlord]}.#{NEEDSTYPE_VALUES[record.needstype]}") record.errors.add charge, I18n.t("validations.financial.rent.#{charge}.#{LANDLORD_VALUES[record.landlord]}.#{NEEDSTYPE_VALUES[record.needstype]}")
end end
end end

2
spec/fixtures/complete_case_log.json vendored

@ -53,7 +53,7 @@
"startertenancy": 0, "startertenancy": 0,
"tenancylength": 5, "tenancylength": 5,
"tenancy": 3, "tenancy": 3,
"landlord": "This landlord", "landlord": 1,
"la": "Barnet", "la": "Barnet",
"postcode_full": "NW1 5TY", "postcode_full": "NW1 5TY",
"property_relet": 0, "property_relet": 0,

274
spec/models/case_log_spec.rb

@ -258,6 +258,24 @@ RSpec.describe CaseLog do
expect(record_from_db["renttype"]).to eq(3) expect(record_from_db["renttype"]).to eq(3)
end end
context "when the owning organisation is a PRP" do
it "correctly derives and saves landlord based on owning_organisation provider_type" do
record_from_db = ActiveRecord::Base.connection.execute("select landlord from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.landlord).to eq(2)
expect(record_from_db["landlord"]).to eq(2)
end
end
context "when the owning organisation is an LA" do
let(:organisation) { FactoryBot.create(:organisation) }
it "correctly derives and saves landlord based on owning_organisation provider_type" do
record_from_db = ActiveRecord::Base.connection.execute("select landlord from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.landlord).to eq(1)
expect(record_from_db["landlord"]).to eq(1)
end
end
context "when deriving lettype" do context "when deriving lettype" do
context "when the owning organisation is a PRP" do context "when the owning organisation is a PRP" do
context "when the rent type is intermediate rent and supported housing" do context "when the rent type is intermediate rent and supported housing" do
@ -332,17 +350,17 @@ RSpec.describe CaseLog do
end end
it "correctly derives and saves weekly service charge" do it "correctly derives and saves weekly service charge" do
case_log.update!(scharge: 100, period: 2) case_log.update!(scharge: 70, period: 2)
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wscharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wscharge).to eq(50.0) expect(case_log.wscharge).to eq(35.0)
expect(record_from_db["wscharge"]).to eq(50.0) expect(record_from_db["wscharge"]).to eq(35.0)
end end
it "correctly derives and saves weekly personal service charge" do it "correctly derives and saves weekly personal service charge" do
case_log.update!(pscharge: 100, period: 2) case_log.update!(pscharge: 70, period: 2)
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wpschrge).to eq(50.0) expect(case_log.wpschrge).to eq(35.0)
expect(record_from_db["wpschrge"]).to eq(50.0) expect(record_from_db["wpschrge"]).to eq(35.0)
end end
it "correctly derives and saves weekly support charge" do it "correctly derives and saves weekly support charge" do
@ -389,18 +407,18 @@ RSpec.describe CaseLog do
end end
it "correctly derives floats" do it "correctly derives floats" do
case_log.update!(supcharg: 100.12, pscharge: 100.13, scharge: 100.98, brent: 100.97, period: 2) case_log.update!(supcharg: 60.12, pscharge: 60.13, scharge: 60.98, brent: 60.97, period: 2)
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(50.06) expect(case_log.wsupchrg).to eq(30.06)
expect(case_log.wpschrge).to eq(50.07) expect(case_log.wpschrge).to eq(30.06)
expect(case_log.wscharge).to eq(50.49) expect(case_log.wscharge).to eq(30.49)
expect(case_log.wrent).to eq(50.49) expect(case_log.wrent).to eq(30.49)
expect(case_log.wtcharge).to eq(201.1) expect(case_log.wtcharge).to eq(121.1)
expect(record_from_db["wsupchrg"]).to eq(50.06) expect(record_from_db["wsupchrg"]).to eq(30.06)
expect(record_from_db["wpschrge"]).to eq(50.07) expect(record_from_db["wpschrge"]).to eq(30.06)
expect(record_from_db["wscharge"]).to eq(50.49) expect(record_from_db["wscharge"]).to eq(30.49)
expect(record_from_db["wrent"]).to eq(50.49) expect(record_from_db["wrent"]).to eq(30.49)
expect(record_from_db["wtcharge"]).to eq(201.1) expect(record_from_db["wtcharge"]).to eq(121.1)
end end
end end
@ -575,24 +593,24 @@ RSpec.describe CaseLog do
end end
it "correctly derives and saves weekly service charge" do it "correctly derives and saves weekly service charge" do
case_log.update!(scharge: 130, period: 5) case_log.update!(scharge: 20, period: 5)
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wscharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wscharge).to eq(125.0) expect(case_log.wscharge).to eq(19.23)
expect(record_from_db["wscharge"]).to eq(125.0) expect(record_from_db["wscharge"]).to eq(19.23)
end end
it "correctly derives and saves weekly personal service charge" do it "correctly derives and saves weekly personal service charge" do
case_log.update!(pscharge: 130, period: 5) case_log.update!(pscharge: 20, period: 5)
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wpschrge).to eq(125.0) expect(case_log.wpschrge).to eq(19.23)
expect(record_from_db["wpschrge"]).to eq(125.0) expect(record_from_db["wpschrge"]).to eq(19.23)
end end
it "correctly derives and saves weekly support charge" do it "correctly derives and saves weekly support charge" do
case_log.update!(supcharg: 130, period: 5) case_log.update!(supcharg: 20, period: 5)
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(125.0) expect(case_log.wsupchrg).to eq(19.23)
expect(record_from_db["wsupchrg"]).to eq(125.0) expect(record_from_db["wsupchrg"]).to eq(19.23)
end end
it "correctly derives and saves weekly total charge" do it "correctly derives and saves weekly total charge" do
@ -632,18 +650,18 @@ RSpec.describe CaseLog do
end end
it "correctly derives floats" do it "correctly derives floats" do
case_log.update!(supcharg: 100.12, pscharge: 100.13, scharge: 100.98, brent: 100.97, period: 5) case_log.update!(supcharg: 20.12, pscharge: 20.13, scharge: 20.98, brent: 100.97, period: 5)
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(96.27) expect(case_log.wsupchrg).to eq(19.35)
expect(case_log.wpschrge).to eq(96.28) expect(case_log.wpschrge).to eq(19.36)
expect(case_log.wscharge).to eq(97.1) expect(case_log.wscharge).to eq(20.17)
expect(case_log.wrent).to eq(97.09) expect(case_log.wrent).to eq(97.09)
expect(case_log.wtcharge).to eq(386.73) expect(case_log.wtcharge).to eq(155.96)
expect(record_from_db["wsupchrg"]).to eq(96.27) expect(record_from_db["wsupchrg"]).to eq(19.35)
expect(record_from_db["wpschrge"]).to eq(96.28) expect(record_from_db["wpschrge"]).to eq(19.36)
expect(record_from_db["wscharge"]).to eq(97.1) expect(record_from_db["wscharge"]).to eq(20.17)
expect(record_from_db["wrent"]).to eq(97.09) expect(record_from_db["wrent"]).to eq(97.09)
expect(record_from_db["wtcharge"]).to eq(386.73) expect(record_from_db["wtcharge"]).to eq(155.96)
end end
end end
@ -656,24 +674,24 @@ RSpec.describe CaseLog do
end end
it "correctly derives and saves weekly service charge" do it "correctly derives and saves weekly service charge" do
case_log.update!(scharge: 130, period: 6) case_log.update!(scharge: 30, period: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wscharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wscharge).to eq(122.5) expect(case_log.wscharge).to eq(28.27)
expect(record_from_db["wscharge"]).to eq(122.5) expect(record_from_db["wscharge"]).to eq(28.27)
end end
it "correctly derives and saves weekly personal service charge" do it "correctly derives and saves weekly personal service charge" do
case_log.update!(pscharge: 130, period: 6) case_log.update!(pscharge: 30, period: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wpschrge).to eq(122.5) expect(case_log.wpschrge).to eq(28.27)
expect(record_from_db["wpschrge"]).to eq(122.5) expect(record_from_db["wpschrge"]).to eq(28.27)
end end
it "correctly derives and saves weekly support charge" do it "correctly derives and saves weekly support charge" do
case_log.update!(supcharg: 130, period: 6) case_log.update!(supcharg: 30, period: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(122.5) expect(case_log.wsupchrg).to eq(28.27)
expect(record_from_db["wsupchrg"]).to eq(122.5) expect(record_from_db["wsupchrg"]).to eq(28.27)
end end
it "correctly derives and saves weekly total charge" do it "correctly derives and saves weekly total charge" do
@ -713,18 +731,18 @@ RSpec.describe CaseLog do
end end
it "correctly derives floats" do it "correctly derives floats" do
case_log.update!(supcharg: 100.12, pscharge: 100.13, scharge: 100.98, brent: 100.97, period: 6) case_log.update!(supcharg: 30.12, pscharge: 30.13, scharge: 30.98, brent: 100.97, period: 6)
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(94.34) expect(case_log.wsupchrg).to eq(28.38)
expect(case_log.wpschrge).to eq(94.35) expect(case_log.wpschrge).to eq(28.39)
expect(case_log.wscharge).to eq(95.15) expect(case_log.wscharge).to eq(29.19)
expect(case_log.wrent).to eq(95.14) expect(case_log.wrent).to eq(95.14)
expect(case_log.wtcharge).to eq(379) expect(case_log.wtcharge).to eq(181.11)
expect(record_from_db["wsupchrg"]).to eq(94.34) expect(record_from_db["wsupchrg"]).to eq(28.38)
expect(record_from_db["wpschrge"]).to eq(94.35) expect(record_from_db["wpschrge"]).to eq(28.39)
expect(record_from_db["wscharge"]).to eq(95.15) expect(record_from_db["wscharge"]).to eq(29.19)
expect(record_from_db["wrent"]).to eq(95.14) expect(record_from_db["wrent"]).to eq(95.14)
expect(record_from_db["wtcharge"]).to eq(379) expect(record_from_db["wtcharge"]).to eq(181.11)
end end
end end
@ -737,24 +755,24 @@ RSpec.describe CaseLog do
end end
it "correctly derives and saves weekly service charge" do it "correctly derives and saves weekly service charge" do
case_log.update!(scharge: 130, period: 7) case_log.update!(scharge: 30, period: 7)
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wscharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wscharge).to eq(120.0) expect(case_log.wscharge).to eq(27.69)
expect(record_from_db["wscharge"]).to eq(120.0) expect(record_from_db["wscharge"]).to eq(27.69)
end end
it "correctly derives and saves weekly personal service charge" do it "correctly derives and saves weekly personal service charge" do
case_log.update!(pscharge: 130, period: 7) case_log.update!(pscharge: 30, period: 7)
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wpschrge).to eq(120.0) expect(case_log.wpschrge).to eq(27.69)
expect(record_from_db["wpschrge"]).to eq(120.0) expect(record_from_db["wpschrge"]).to eq(27.69)
end end
it "correctly derives and saves weekly support charge" do it "correctly derives and saves weekly support charge" do
case_log.update!(supcharg: 130, period: 7) case_log.update!(supcharg: 30, period: 7)
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(120.0) expect(case_log.wsupchrg).to eq(27.69)
expect(record_from_db["wsupchrg"]).to eq(120.0) expect(record_from_db["wsupchrg"]).to eq(27.69)
end end
it "correctly derives and saves weekly total charge" do it "correctly derives and saves weekly total charge" do
@ -794,18 +812,18 @@ RSpec.describe CaseLog do
end end
it "correctly derives floats" do it "correctly derives floats" do
case_log.update!(supcharg: 100.12, pscharge: 100.13, scharge: 100.98, brent: 100.97, period: 7) case_log.update!(supcharg: 30.12, pscharge: 30.13, scharge: 30.98, brent: 100.97, period: 7)
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(92.42) expect(case_log.wsupchrg).to eq(27.8)
expect(case_log.wpschrge).to eq(92.43) expect(case_log.wpschrge).to eq(27.81)
expect(case_log.wscharge).to eq(93.21) expect(case_log.wscharge).to eq(28.6)
expect(case_log.wrent).to eq(93.20) expect(case_log.wrent).to eq(93.20)
expect(case_log.wtcharge).to eq(371.26) expect(case_log.wtcharge).to eq(177.42)
expect(record_from_db["wsupchrg"]).to eq(92.42) expect(record_from_db["wsupchrg"]).to eq(27.8)
expect(record_from_db["wpschrge"]).to eq(92.43) expect(record_from_db["wpschrge"]).to eq(27.81)
expect(record_from_db["wscharge"]).to eq(93.21) expect(record_from_db["wscharge"]).to eq(28.6)
expect(record_from_db["wrent"]).to eq(93.20) expect(record_from_db["wrent"]).to eq(93.20)
expect(record_from_db["wtcharge"]).to eq(371.26) expect(record_from_db["wtcharge"]).to eq(177.42)
end end
end end
@ -818,24 +836,24 @@ RSpec.describe CaseLog do
end end
it "correctly derives and saves weekly service charge" do it "correctly derives and saves weekly service charge" do
case_log.update!(scharge: 130, period: 8) case_log.update!(scharge: 30, period: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wscharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wscharge).to eq(117.5) expect(case_log.wscharge).to eq(27.12)
expect(record_from_db["wscharge"]).to eq(117.5) expect(record_from_db["wscharge"]).to eq(27.12)
end end
it "correctly derives and saves weekly personal service charge" do it "correctly derives and saves weekly personal service charge" do
case_log.update!(pscharge: 130, period: 8) case_log.update!(pscharge: 30, period: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wpschrge).to eq(117.5) expect(case_log.wpschrge).to eq(27.12)
expect(record_from_db["wpschrge"]).to eq(117.5) expect(record_from_db["wpschrge"]).to eq(27.12)
end end
it "correctly derives and saves weekly support charge" do it "correctly derives and saves weekly support charge" do
case_log.update!(supcharg: 130, period: 8) case_log.update!(supcharg: 30, period: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(117.5) expect(case_log.wsupchrg).to eq(27.12)
expect(record_from_db["wsupchrg"]).to eq(117.5) expect(record_from_db["wsupchrg"]).to eq(27.12)
end end
it "correctly derives and saves weekly total charge" do it "correctly derives and saves weekly total charge" do
@ -875,18 +893,18 @@ RSpec.describe CaseLog do
end end
it "correctly derives floats" do it "correctly derives floats" do
case_log.update!(supcharg: 100.12, pscharge: 100.13, scharge: 100.98, brent: 100.97, period: 8) case_log.update!(supcharg: 30.12, pscharge: 30.13, scharge: 30.98, brent: 100.97, period: 8)
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(90.49) expect(case_log.wsupchrg).to eq(27.22)
expect(case_log.wpschrge).to eq(90.50) expect(case_log.wpschrge).to eq(27.23)
expect(case_log.wscharge).to eq(91.27) expect(case_log.wscharge).to eq(28)
expect(case_log.wrent).to eq(91.26) expect(case_log.wrent).to eq(91.26)
expect(case_log.wtcharge).to eq(363.53) expect(case_log.wtcharge).to eq(173.72)
expect(record_from_db["wsupchrg"]).to eq(90.49) expect(record_from_db["wsupchrg"]).to eq(27.22)
expect(record_from_db["wpschrge"]).to eq(90.50) expect(record_from_db["wpschrge"]).to eq(27.23)
expect(record_from_db["wscharge"]).to eq(91.27) expect(record_from_db["wscharge"]).to eq(28)
expect(record_from_db["wrent"]).to eq(91.26) expect(record_from_db["wrent"]).to eq(91.26)
expect(record_from_db["wtcharge"]).to eq(363.53) expect(record_from_db["wtcharge"]).to eq(173.72)
end end
end end
@ -899,24 +917,24 @@ RSpec.describe CaseLog do
end end
it "correctly derives and saves weekly service charge" do it "correctly derives and saves weekly service charge" do
case_log.update!(scharge: 130, period: 9) case_log.update!(scharge: 30, period: 9)
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wscharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wscharge).to eq(115.0) expect(case_log.wscharge).to eq(26.54)
expect(record_from_db["wscharge"]).to eq(115.0) expect(record_from_db["wscharge"]).to eq(26.54)
end end
it "correctly derives and saves weekly personal service charge" do it "correctly derives and saves weekly personal service charge" do
case_log.update!(pscharge: 130, period: 9) case_log.update!(pscharge: 30, period: 9)
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wpschrge).to eq(115.0) expect(case_log.wpschrge).to eq(26.54)
expect(record_from_db["wpschrge"]).to eq(115.0) expect(record_from_db["wpschrge"]).to eq(26.54)
end end
it "correctly derives and saves weekly support charge" do it "correctly derives and saves weekly support charge" do
case_log.update!(supcharg: 130, period: 9) case_log.update!(supcharg: 30, period: 9)
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(115.0) expect(case_log.wsupchrg).to eq(26.54)
expect(record_from_db["wsupchrg"]).to eq(115.0) expect(record_from_db["wsupchrg"]).to eq(26.54)
end end
it "correctly derives and saves weekly total charge" do it "correctly derives and saves weekly total charge" do
@ -956,18 +974,18 @@ RSpec.describe CaseLog do
end end
it "correctly derives floats" do it "correctly derives floats" do
case_log.update!(supcharg: 100.12, pscharge: 100.13, scharge: 100.98, brent: 100.97, period: 9) case_log.update!(supcharg: 30.12, pscharge: 30.13, scharge: 30.98, brent: 100.97, period: 9)
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(88.57) expect(case_log.wsupchrg).to eq(26.64)
expect(case_log.wpschrge).to eq(88.58) expect(case_log.wpschrge).to eq(26.65)
expect(case_log.wscharge).to eq(89.33) expect(case_log.wscharge).to eq(27.41)
expect(case_log.wrent).to eq(89.32) expect(case_log.wrent).to eq(89.32)
expect(case_log.wtcharge).to eq(355.79) expect(case_log.wtcharge).to eq(170.02)
expect(record_from_db["wsupchrg"]).to eq(88.57) expect(record_from_db["wsupchrg"]).to eq(26.64)
expect(record_from_db["wpschrge"]).to eq(88.58) expect(record_from_db["wpschrge"]).to eq(26.65)
expect(record_from_db["wscharge"]).to eq(89.33) expect(record_from_db["wscharge"]).to eq(27.41)
expect(record_from_db["wrent"]).to eq(89.32) expect(record_from_db["wrent"]).to eq(89.32)
expect(record_from_db["wtcharge"]).to eq(355.79) expect(record_from_db["wtcharge"]).to eq(170.02)
end end
end end
@ -980,31 +998,31 @@ RSpec.describe CaseLog do
end end
it "correctly derives and saves weekly service charge" do it "correctly derives and saves weekly service charge" do
case_log.update!(scharge: 130, period: 1) case_log.update!(scharge: 30, period: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wscharge from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wscharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wscharge).to eq(130.0) expect(case_log.wscharge).to eq(30.0)
expect(record_from_db["wscharge"]).to eq(130.0) expect(record_from_db["wscharge"]).to eq(30.0)
end end
it "correctly derives and saves weekly personal service charge" do it "correctly derives and saves weekly personal service charge" do
case_log.update!(pscharge: 130, period: 1) case_log.update!(pscharge: 30, period: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wpschrge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wpschrge).to eq(130.0) expect(case_log.wpschrge).to eq(30.0)
expect(record_from_db["wpschrge"]).to eq(130.0) expect(record_from_db["wpschrge"]).to eq(30.0)
end end
it "correctly derives and saves weekly support charge" do it "correctly derives and saves weekly support charge" do
case_log.update!(supcharg: 130, period: 1) case_log.update!(supcharg: 30, period: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wsupchrg from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(130.0) expect(case_log.wsupchrg).to eq(30.0)
expect(record_from_db["wsupchrg"]).to eq(130.0) expect(record_from_db["wsupchrg"]).to eq(30.0)
end end
it "correctly derives and saves weekly total charge" do it "correctly derives and saves weekly total charge" do
case_log.update!(tcharge: 130, period: 1) case_log.update!(tcharge: 30, period: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtcharge from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wtcharge).to eq(130.0) expect(case_log.wtcharge).to eq(30.0)
expect(record_from_db["wtcharge"]).to eq(130.0) expect(record_from_db["wtcharge"]).to eq(30.0)
end end
context "when the tenant has an outstanding amount after benefits" do context "when the tenant has an outstanding amount after benefits" do
@ -1037,18 +1055,18 @@ RSpec.describe CaseLog do
end end
it "correctly derives floats" do it "correctly derives floats" do
case_log.update!(supcharg: 100.12, pscharge: 100.13, scharge: 100.98, brent: 100.97, period: 1) case_log.update!(supcharg: 30.12, pscharge: 30.13, scharge: 30.98, brent: 100.97, period: 1)
record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0] record_from_db = ActiveRecord::Base.connection.execute("select wtcharge, wsupchrg, wpschrge, wscharge, wrent from case_logs where id=#{case_log.id}").to_a[0]
expect(case_log.wsupchrg).to eq(100.12) expect(case_log.wsupchrg).to eq(30.12)
expect(case_log.wpschrge).to eq(100.13) expect(case_log.wpschrge).to eq(30.13)
expect(case_log.wscharge).to eq(100.98) expect(case_log.wscharge).to eq(30.98)
expect(case_log.wrent).to eq(100.97) expect(case_log.wrent).to eq(100.97)
expect(case_log.wtcharge).to eq(402.2) expect(case_log.wtcharge).to eq(192.2)
expect(record_from_db["wsupchrg"]).to eq(100.12) expect(record_from_db["wsupchrg"]).to eq(30.12)
expect(record_from_db["wpschrge"]).to eq(100.13) expect(record_from_db["wpschrge"]).to eq(30.13)
expect(record_from_db["wscharge"]).to eq(100.98) expect(record_from_db["wscharge"]).to eq(30.98)
expect(record_from_db["wrent"]).to eq(100.97) expect(record_from_db["wrent"]).to eq(100.97)
expect(record_from_db["wtcharge"]).to eq(402.2) expect(record_from_db["wtcharge"]).to eq(192.2)
end end
end end
end end

Loading…
Cancel
Save