Add notification for cerfa

This commit is contained in:
Xavier J 2016-12-26 11:33:12 +01:00
parent 5eaa2941ad
commit 6ed91073c4
4 changed files with 24 additions and 6 deletions

View file

@ -5,6 +5,8 @@ class Cerfa < ActiveRecord::Base
mount_uploader :content, CerfaUploader
validates :content, :file_size => {:maximum => 20.megabytes}
after_save :internal_notification
def empty?
content.blank?
end
@ -18,4 +20,10 @@ class Cerfa < ActiveRecord::Base
end
end
end
private
def internal_notification
NotificationService.new('cerfa', self.dossier.id).notify
end
end

View file

@ -1,14 +1,15 @@
class Notification < ActiveRecord::Base
belongs_to :dossier
after_save :broadcast_notification
# after_save :broadcast_notification
enum type_notif: {
commentaire: 'commentaire'
commentaire: 'commentaire',
cerfa: 'cerfa'
}
def broadcast_notification
ActionCable.server.broadcast 'notifications',
message: "Nouveau commentaire posté sur le dossier #{self.dossier.id}"
end
# def broadcast_notification
# ActionCable.server.broadcast 'notifications',
# message: "Nouveau commentaire posté sur le dossier #{self.dossier.id}"
# end
end

View file

@ -26,6 +26,8 @@ class NotificationService
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é."
else
'Notification par défaut'
end

View file

@ -145,6 +145,13 @@ shared_examples 'description_controller_spec' do
end
context 'Quand la procédure accepte les CERFA' do
subject { post :create, params: {dossier_id: dossier_id,
cerfa_pdf: cerfa_pdf} }
it 'Notification interne is create' do
expect { subject }.to change(Notification, :count).by (1)
end
context 'Sauvegarde du CERFA PDF', vcr: {cassette_name: 'controllers_users_description_controller_save_cerfa'} do
before do
post :create, params: {dossier_id: dossier_id,