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..f62afab48 100644 --- a/spec/models/procedure_presentation_spec.rb +++ b/spec/models/procedure_presentation_spec.rb @@ -135,14 +135,14 @@ describe ProcedurePresentation do let(:column) { 'created_at' } let(:dossier) { Timecop.freeze(Time.zone.local(1992, 3, 22)) { create(:dossier, procedure: procedure) } } - it { is_expected.to eq(Time.zone.local(1992, 3, 22).strftime('%d/%m/%Y')) } + it { is_expected.to eq('22/03/1992') } end context 'for en_construction_at column' do let(:column) { 'en_construction_at' } let(:dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: Time.zone.local(2018, 10, 17)) } - it { is_expected.to eq(Time.zone.local(2018, 10, 17).strftime('%d/%m/%Y')) } + it { is_expected.to eq('17/10/2018') } end context 'for updated_at column' do @@ -151,7 +151,7 @@ describe ProcedurePresentation do before { dossier.touch(time: Time.zone.local(2018, 9, 25)) } - it { is_expected.to eq(Time.zone.local(2018, 9, 25).strftime('%d/%m/%Y')) } + it { is_expected.to eq('25/09/2018') } end end @@ -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' }] }