Do not take time of day into account when searching dates

This commit is contained in:
Frederic Merizen 2018-10-26 15:10:42 +02:00
parent 16a018d137
commit f6207bee26
2 changed files with 9 additions and 1 deletions

View file

@ -111,7 +111,7 @@ class ProcedurePresentation < ApplicationRecord
column = sanitized_column(filter)
case table
when 'self'
date = Time.zone.parse(filter['value']) rescue nil
date = Time.zone.parse(filter['value']).beginning_of_day rescue nil
if date.present?
dossiers.where("#{column} BETWEEN ? AND ?", date, date + 1.day)
else

View file

@ -405,6 +405,14 @@ describe ProcedurePresentation do
it { is_expected.to contain_exactly(kept_dossier.id) }
end
context 'ignore time of day' do
let!(:kept_dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: Time.zone.local(2018, 10, 17, 15, 56)) }
let!(:discarded_dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: Time.zone.local(2018, 10, 18, 5, 42)) }
let(:filter) { [{ 'table' => 'self', 'column' => 'en_construction_at', 'value' => '17/10/2018 19:30' }] }
it { is_expected.to contain_exactly(kept_dossier.id) }
end
context 'for a malformed date' do
context 'when its a string' do
let(:filter) { [{ 'table' => 'self', 'column' => 'updated_at', 'value' => 'malformed date' }] }