feat(procedure_presentation): add since date filters
This commit is contained in:
parent
1cbdfe3d66
commit
95a1ea1047
5 changed files with 34 additions and 3 deletions
|
@ -4,9 +4,16 @@ module DossierFilteringConcern
|
|||
included do
|
||||
scope :filter_by_datetimes, lambda { |column, dates|
|
||||
if dates.present?
|
||||
dates
|
||||
.map { |date| self.where(column => date..(date + 1.day)) }
|
||||
.reduce(:or)
|
||||
case column
|
||||
when 'depose_since'
|
||||
where('dossiers.depose_at >= ?', dates.sort.first)
|
||||
when 'updated_since'
|
||||
where('dossiers.updated_at >= ?', dates.sort.first)
|
||||
else
|
||||
dates
|
||||
.map { |date| self.where(column => date..(date + 1.day)) }
|
||||
.reduce(:or)
|
||||
end
|
||||
else
|
||||
none
|
||||
end
|
||||
|
|
|
@ -41,6 +41,8 @@ class ProcedurePresentation < ApplicationRecord
|
|||
field_hash('self', 'en_construction_at'),
|
||||
field_hash('self', 'depose_at'),
|
||||
field_hash('self', 'updated_at'),
|
||||
field_hash('self', 'depose_since'),
|
||||
field_hash('self', 'updated_since'),
|
||||
field_hash('user', 'email'),
|
||||
field_hash('followers_instructeurs', 'email'),
|
||||
field_hash('groupe_instructeur', 'label')
|
||||
|
|
|
@ -10,6 +10,8 @@ en:
|
|||
en_construction_at: En construction le
|
||||
depose_at: Submitted on
|
||||
updated_at: Updated on
|
||||
depose_since: Submitted since
|
||||
updated_since: Updated since
|
||||
user:
|
||||
email: Requester
|
||||
followers_instructeurs:
|
||||
|
|
|
@ -10,6 +10,8 @@ fr:
|
|||
en_construction_at: En construction le
|
||||
depose_at: Déposé le
|
||||
updated_at: Mis à jour le
|
||||
depose_since: Déposé depuis
|
||||
updated_since: Mis à jour depuis
|
||||
user:
|
||||
email: Demandeur
|
||||
followers_instructeurs:
|
||||
|
|
|
@ -62,6 +62,8 @@ describe ProcedurePresentation do
|
|||
{ "label" => 'En construction le', "table" => 'self', "column" => 'en_construction_at', 'classname' => '' },
|
||||
{ "label" => 'Déposé le', "table" => 'self', "column" => 'depose_at', 'classname' => '' },
|
||||
{ "label" => 'Mis à jour le', "table" => 'self', "column" => 'updated_at', 'classname' => '' },
|
||||
{ "label" => "Déposé depuis", "table" => "self", "column" => "depose_since", "classname" => "" },
|
||||
{ "label" => "Mis à jour depuis", "table" => "self", "column" => "updated_since", "classname" => "" },
|
||||
{ "label" => 'Demandeur', "table" => 'user', "column" => 'email', 'classname' => '' },
|
||||
{ "label" => 'Email instructeur', "table" => 'followers_instructeurs', "column" => 'email', 'classname' => '' },
|
||||
{ "label" => 'Groupe instructeur', "table" => 'groupe_instructeur', "column" => 'label', 'classname' => '' },
|
||||
|
@ -415,6 +417,22 @@ describe ProcedurePresentation do
|
|||
it { is_expected.to contain_exactly(kept_dossier.id) }
|
||||
end
|
||||
|
||||
context 'for updated_since column' do
|
||||
let(:filter) { [{ 'table' => 'self', 'column' => 'updated_since', 'value' => '18/9/2018' }] }
|
||||
|
||||
let(:kept_dossier) { create(:dossier, procedure: procedure) }
|
||||
let(:later_dossier) { create(:dossier, procedure: procedure) }
|
||||
let(:discarded_dossier) { create(:dossier, procedure: procedure) }
|
||||
|
||||
before do
|
||||
kept_dossier.touch(time: Time.zone.local(2018, 9, 18, 14, 28))
|
||||
later_dossier.touch(time: Time.zone.local(2018, 9, 19, 14, 28))
|
||||
discarded_dossier.touch(time: Time.zone.local(2018, 9, 17, 14, 28))
|
||||
end
|
||||
|
||||
it { is_expected.to match_array([kept_dossier.id, later_dossier.id]) }
|
||||
end
|
||||
|
||||
context 'ignore time of day' do
|
||||
let(:filter) { [{ 'table' => 'self', 'column' => 'en_construction_at', 'value' => '17/10/2018 19:30' }] }
|
||||
|
||||
|
|
Loading…
Reference in a new issue