Notification: new acknowledgment system

This commit is contained in:
Simon Lehericey 2017-10-24 11:41:22 +02:00 committed by Mathieu Magnin
parent f7d7cec5ae
commit ed4e885e6f
3 changed files with 29 additions and 0 deletions

View file

@ -7,21 +7,25 @@ module NewGestionnaire
def show
@dossier = dossier
dossier.notifications.demande.mark_as_read
current_gestionnaire.mark_tab_as_seen(dossier, :demande)
end
def messagerie
@dossier = dossier
dossier.notifications.messagerie.mark_as_read
current_gestionnaire.mark_tab_as_seen(dossier, :messagerie)
end
def annotations_privees
@dossier = dossier
dossier.notifications.annotations_privees.mark_as_read
current_gestionnaire.mark_tab_as_seen(dossier, :annotations_privees)
end
def avis
@dossier = dossier
dossier.notifications.avis.mark_as_read
current_gestionnaire.mark_tab_as_seen(dossier, :avis)
end
def follow

View file

@ -175,6 +175,12 @@ class Gestionnaire < ActiveRecord::Base
Dossier.where(id: dossiers_id_with_notifications(dossiers)).group(:procedure_id).count
end
def mark_tab_as_seen(dossier, tab)
attributes = {}
attributes["#{tab}_seen_at"] = DateTime.now
Follow.where(gestionnaire: self, dossier: dossier).update_all(attributes)
end
private
def valid_couple_table_attr? table, column

View file

@ -550,4 +550,23 @@ describe Gestionnaire, type: :model do
it { is_expected.to match({ procedure.id => 1 }) }
end
end
describe '#mark_tab_as_seen' do
let!(:dossier) { create(:dossier, :followed, state: 'initiated') }
let(:gestionnaire) { dossier.follows.first.gestionnaire }
let(:freeze_date) { DateTime.parse('12/12/2012') }
context 'when demande is acknowledged' do
let(:follow) { gestionnaire.follows.find_by(dossier: dossier) }
before do
Timecop.freeze(freeze_date)
gestionnaire.mark_tab_as_seen(dossier, :demande)
end
it { expect(follow.demande_seen_at).to eq(freeze_date) }
after { Timecop.return }
end
end
end