Bug with time zone: Time.zone.today looses time_zone and may breaks database comparisons

This commit is contained in:
maatinito 2019-12-02 10:27:05 -10:00 committed by simon lehericey
parent 1b17218b5c
commit 9672d892e9
3 changed files with 4 additions and 4 deletions

View file

@ -1,9 +1,9 @@
class BillSignatureService
def self.grouped_unsigned_operation_until(date)
date = date.in_time_zone
unsigned_operations = DossierOperationLog
.where(bill_signature: nil)
.where('executed_at < ?', date)
unsigned_operations.group_by { |e| e.executed_at.to_date }
end

View file

@ -2,9 +2,9 @@ require 'rails_helper'
RSpec.describe AutoArchiveProcedureJob, type: :job do
let!(:procedure) { create(:procedure, :published, :with_instructeur, auto_archive_on: nil) }
let!(:procedure_hier) { create(:procedure, :published, :with_instructeur, auto_archive_on: 1.day.ago) }
let!(:procedure_hier) { create(:procedure, :published, :with_instructeur, auto_archive_on: 1.day.ago.to_date) }
let!(:procedure_aujourdhui) { create(:procedure, :published, :with_instructeur, auto_archive_on: Time.zone.today) }
let!(:procedure_demain) { create(:procedure, :published, :with_instructeur, auto_archive_on: 1.day.from_now) }
let!(:procedure_demain) { create(:procedure, :published, :with_instructeur, auto_archive_on: 1.day.from_now.to_date) }
subject { AutoArchiveProcedureJob.new.perform }

View file

@ -4,7 +4,7 @@ describe BillSignatureService do
describe ".grouped_unsigned_operation_until" do
subject { BillSignatureService.grouped_unsigned_operation_until(date).length }
let(:date) { Time.zone.today }
let(:date) { Time.zone.now.beginning_of_day }
context "when operations of several days need to be signed" do
before do