fix(Dossier.processed_in_month): using PG between operator with a date does not play nicely when it is compared to DateTime in postgres. meaning given a Date as 2022/03/31, when compared with a DateTime in postgres, the casting of 2022/03/31 to Datetime becomes 2022/03/31 00:00. So we skiped all dossiers from last date in month
This commit is contained in:
parent
4a6d5a03aa
commit
9484c4cdf4
2 changed files with 27 additions and 2 deletions
|
@ -233,10 +233,10 @@ class Dossier < ApplicationRecord
|
||||||
scope :en_instruction, -> { not_archived.state_en_instruction }
|
scope :en_instruction, -> { not_archived.state_en_instruction }
|
||||||
scope :termine, -> { not_archived.state_termine }
|
scope :termine, -> { not_archived.state_termine }
|
||||||
|
|
||||||
scope :processed_in_month, -> (month) do
|
scope :processed_in_month, -> (date) do
|
||||||
state_termine
|
state_termine
|
||||||
.joins(:traitements)
|
.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
|
end
|
||||||
scope :downloadable_sorted, -> {
|
scope :downloadable_sorted, -> {
|
||||||
state_not_brouillon
|
state_not_brouillon
|
||||||
|
|
|
@ -1720,4 +1720,29 @@ describe Dossier do
|
||||||
expect(rebased_datetime_champ.rebased_at).not_to be_nil
|
expect(rebased_datetime_champ.rebased_at).not_to be_nil
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue