Add notification for piece justificative
This commit is contained in:
parent
6ed91073c4
commit
e5768b6798
4 changed files with 20 additions and 4 deletions
|
@ -5,7 +5,8 @@ class Notification < ActiveRecord::Base
|
|||
|
||||
enum type_notif: {
|
||||
commentaire: 'commentaire',
|
||||
cerfa: 'cerfa'
|
||||
cerfa: 'cerfa',
|
||||
piece_justificative: 'piece_justificative'
|
||||
}
|
||||
|
||||
# def broadcast_notification
|
||||
|
|
|
@ -13,6 +13,8 @@ class PieceJustificative < ActiveRecord::Base
|
|||
validates :content, :file_size => {:maximum => 20.megabytes}
|
||||
validates :content, presence: true, allow_blank: false, allow_nil: false
|
||||
|
||||
after_save :internal_notification
|
||||
|
||||
def empty?
|
||||
content.blank?
|
||||
end
|
||||
|
@ -43,4 +45,10 @@ class PieceJustificative < ActiveRecord::Base
|
|||
image/jpeg
|
||||
"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def internal_notification
|
||||
NotificationService.new('piece_justificative', self.dossier.id, self.libelle).notify
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
class NotificationService
|
||||
|
||||
def initialize type_notif, dossier_id
|
||||
def initialize type_notif, dossier_id, attribut_change=''
|
||||
@type_notif = type_notif
|
||||
@dossier_id = dossier_id
|
||||
|
||||
notification.liste.push text_for_notif
|
||||
notification.liste.push text_for_notif attribut_change
|
||||
notification.liste = notification.liste.uniq
|
||||
|
||||
self
|
||||
end
|
||||
|
@ -22,12 +23,14 @@ class NotificationService
|
|||
end
|
||||
end
|
||||
|
||||
def text_for_notif
|
||||
def text_for_notif attribut=''
|
||||
case @type_notif
|
||||
when 'commentaire'
|
||||
"#{notification.liste.size + 1} nouveau(x) commentaire(s) déposé(s)."
|
||||
when 'cerfa'
|
||||
"Un nouveau formulaire a été déposé."
|
||||
when 'piece_justificative'
|
||||
attribut
|
||||
else
|
||||
'Notification par défaut'
|
||||
end
|
||||
|
|
|
@ -299,6 +299,10 @@ shared_examples 'description_controller_spec' do
|
|||
sign_in guest
|
||||
end
|
||||
|
||||
it 'Notification interne is create' do
|
||||
expect { subject }.to change(Notification, :count).by (1)
|
||||
end
|
||||
|
||||
context 'when PJ have no documents' do
|
||||
it { expect(dossier.pieces_justificatives.size).to eq 0 }
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue