Browse Source

Default charge values to 0 (#294)

pull/299/head
baarkerlounger 3 years ago committed by GitHub
parent
commit
3912f920cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/models/case_log.rb
  2. 13
      spec/models/case_log_spec.rb

8
app/models/case_log.rb

@ -249,7 +249,13 @@ private
self.totchild = get_totchild self.totchild = get_totchild
self.totelder = get_totelder self.totelder = get_totelder
self.totadult = get_totadult self.totadult = get_totadult
self.tcharge = brent.to_f + scharge.to_f + pscharge.to_f + supcharg.to_f if %i[brent scharge pscharge supcharg].any? { |f| public_send(f).present? }
self.brent ||= 0
self.scharge ||= 0
self.pscharge ||= 0
self.supcharg ||= 0
self.tcharge = brent.to_f + scharge.to_f + pscharge.to_f + supcharg.to_f
end
self.has_benefits = get_has_benefits self.has_benefits = get_has_benefits
self.nocharge = household_charge == "Yes" ? "No" : "Yes" self.nocharge = household_charge == "Yes" ? "No" : "Yes"
self.layear = "Less than 1 year" if renewal == "Yes" self.layear = "Less than 1 year" if renewal == "Yes"

13
spec/models/case_log_spec.rb

@ -956,7 +956,6 @@ RSpec.describe CaseLog do
end end
describe "derived variables" do describe "derived variables" do
require "date"
let(:organisation) { FactoryBot.create(:organisation, provider_type: "PRP") } let(:organisation) { FactoryBot.create(:organisation, provider_type: "PRP") }
let!(:case_log) do let!(:case_log) do
described_class.create({ described_class.create({
@ -1029,6 +1028,18 @@ RSpec.describe CaseLog do
expect(record_from_db["year"]).to eq(2021) expect(record_from_db["year"]).to eq(2021)
end end
context "when any charge field is set" do
before do
case_log.update!(pscharge: 10)
end
it "derives that any blank ones are 0" do
record_from_db = ActiveRecord::Base.connection.execute("select supcharg, scharge from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["supcharg"].to_f).to eq(0.0)
expect(record_from_db["scharge"].to_f).to eq(0.0)
end
end
context "when saving addresses" do context "when saving addresses" do
before do before do
stub_request(:get, /api.postcodes.io/) stub_request(:get, /api.postcodes.io/)

Loading…
Cancel
Save