From f6207bee2625ac3c6fbd0c9bc34f2013639b561a Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Fri, 26 Oct 2018 15:10:42 +0200 Subject: [PATCH] Do not take time of day into account when searching dates --- app/models/procedure_presentation.rb | 2 +- spec/models/procedure_presentation_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index 3695600af..1798ece76 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -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 diff --git a/spec/models/procedure_presentation_spec.rb b/spec/models/procedure_presentation_spec.rb index aeb3e8db5..ec69ba20a 100644 --- a/spec/models/procedure_presentation_spec.rb +++ b/spec/models/procedure_presentation_spec.rb @@ -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' }] }