Merge pull request #2916 from betagouv/frederic/cosmetic_date_handling

cosmetic date handling
This commit is contained in:
Frederic Merizen 2018-10-26 18:14:51 +02:00 committed by GitHub
commit 87330c1d4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View file

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

View file

@ -135,14 +135,14 @@ describe ProcedurePresentation do
let(:column) { 'created_at' } let(:column) { 'created_at' }
let(:dossier) { Timecop.freeze(Time.zone.local(1992, 3, 22)) { create(:dossier, procedure: procedure) } } 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 end
context 'for en_construction_at column' do context 'for en_construction_at column' do
let(:column) { 'en_construction_at' } let(:column) { 'en_construction_at' }
let(:dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: Time.zone.local(2018, 10, 17)) } 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 end
context 'for updated_at column' do context 'for updated_at column' do
@ -151,7 +151,7 @@ describe ProcedurePresentation do
before { dossier.touch(time: Time.zone.local(2018, 9, 25)) } 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
end end
@ -405,6 +405,14 @@ describe ProcedurePresentation do
it { is_expected.to contain_exactly(kept_dossier.id) } it { is_expected.to contain_exactly(kept_dossier.id) }
end 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 'for a malformed date' do
context 'when its a string' do context 'when its a string' do
let(:filter) { [{ 'table' => 'self', 'column' => 'updated_at', 'value' => 'malformed date' }] } let(:filter) { [{ 'table' => 'self', 'column' => 'updated_at', 'value' => 'malformed date' }] }