@ -41,7 +41,7 @@ class CaseLog < ApplicationRecord
years.each { |year| query = query.or(filter_by_year(year)) }
query.all
}
scope :filter_by_year, ->(year) { where(startdate: Time.utc(year.to_i, 4, 1)...Time.utc(year.to_i + 1, 4, 1)) }
scope :filter_by_year, ->(year) { where(startdate: Time.zone.local(year.to_i, 4, 1)...Time.zone.local(year.to_i + 1, 4, 1)) }
scope :filter_by_user, lambda { |selected_user, user|
if !selected_user.include?("all") && user.present?
@ -1846,6 +1846,14 @@ RSpec.describe CaseLog do
it "can filter by year(s) AND status" do
expect(described_class.filter_by_years(%w[2021 2022]).filter_by_status("completed").count).to eq(1)
end
it "filters based on date boundaries correctly" do
case_log_1.update!(startdate: Time.zone.local(2022, 4, 1))
case_log_2.update!(startdate: Time.zone.local(2022, 3, 31))
expect(described_class.filter_by_years(%w[2021]).count).to eq(1)
expect(described_class.filter_by_years(%w[2022]).count).to eq(2)
context "when filtering on status" do