Browse Source

CLDC-3463: Fix bug with vacdays calculation

pull/2444/head
Rachael Booth 2 years ago
parent
commit
05b15a26df
  1. 4
      app/models/derived_variables/lettings_log_variables.rb
  2. 5
      lib/tasks/recalculate_vacdays.rake
  3. 18
      spec/models/lettings_log_spec.rb

4
app/models/derived_variables/lettings_log_variables.rb

@ -306,9 +306,9 @@ private
return unless startdate return unless startdate
if mrcdate.present? if mrcdate.present?
(startdate - mrcdate).to_i / 1.day startdate.to_date - mrcdate.to_date
elsif voiddate.present? elsif voiddate.present?
(startdate - voiddate).to_i / 1.day startdate.to_date - voiddate.to_date
end end
end end

5
lib/tasks/recalculate_vacdays.rake

@ -0,0 +1,5 @@
desc "Recalculate vacdays after bugfix for daylight savings time changes"
task recalculate_vacdays: :environment do
logs = LettingsLog.filter_by_years(%w[2023 2024]).where.not(vacdays: nil)
logs.each(&:save!)
end

18
spec/models/lettings_log_spec.rb

@ -1514,6 +1514,24 @@ RSpec.describe LettingsLog do
expect(record_from_db["has_benefits"]).to eq(1) expect(record_from_db["has_benefits"]).to eq(1)
end end
describe "deriving vacant days" do
it "correctly derives vacdays from startdate and mrcdate across DST boundaries" do
log = build(:lettings_log, startdate: Time.zone.local(2024, 4, 1), mrcdate: Time.zone.local(2024, 3, 30))
log.set_derived_fields!
expect(log.vacdays).to be 2
end
it "correctly derives vacdays from startdate and voiddate across DST boundaries" do
log = build(:lettings_log, startdate: Time.zone.local(2024, 4, 1), mrcdate: nil, voiddate: Time.zone.local(2024, 3, 30))
log.set_derived_fields!
expect(log.vacdays).to be 2
end
end
context "when updating values that derive vacdays" do context "when updating values that derive vacdays" do
let(:lettings_log) { create(:lettings_log, startdate:) } let(:lettings_log) { create(:lettings_log, startdate:) }

Loading…
Cancel
Save