Merge pull request #7119 from betagouv/US/fix-dossier.processed_in_month-2

fix: missing dossiers from last day of month in archives
This commit is contained in:
mfo 2022-04-05 13:57:58 +02:00 committed by GitHub
commit 8c4c5ed0cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

View file

@ -233,10 +233,11 @@ class Dossier < ApplicationRecord
scope :en_instruction, -> { not_archived.state_en_instruction }
scope :termine, -> { not_archived.state_termine }
scope :processed_in_month, -> (month) do
scope :processed_in_month, -> (date) do
date = date.to_datetime
state_termine
.joins(:traitements)
.where(traitements: { processed_at: month.beginning_of_month..month.end_of_month })
.where(traitements: { processed_at: date.beginning_of_month..date.end_of_month })
end
scope :downloadable_sorted, -> {
state_not_brouillon

View file

@ -1720,4 +1720,29 @@ describe Dossier do
expect(rebased_datetime_champ.rebased_at).not_to be_nil
end
end
describe '#processed_in_month' do
include ActiveSupport::Testing::TimeHelpers
let(:dossier_accepte_at) { DateTime.new(2022, 3, 31, 12, 0) }
before do
travel_to(dossier_accepte_at) do
dossier = create(:dossier, :accepte)
end
end
context 'given a date' do
let(:archive_date) { Date.new(2022, 3, 1) }
it 'includes a dossier processed_at at last day of month' do
expect(Dossier.processed_in_month(archive_date).count).to eq(1)
end
end
context 'given a datetime' do
let(:archive_date) { DateTime.new(2022, 3, 1, 12, 0) }
it 'includes a dossier processed_at at last day of month' do
expect(Dossier.processed_in_month(archive_date).count).to eq(1)
end
end
end
end