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

View file

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

View file

@ -26,6 +26,8 @@ class NotificationService
case @type_notif case @type_notif
when 'commentaire' when 'commentaire'
"#{notification.liste.size + 1} nouveau(x) commentaire(s) déposé(s)." "#{notification.liste.size + 1} nouveau(x) commentaire(s) déposé(s)."
when 'cerfa'
"Un nouveau formulaire a été déposé."
else else
'Notification par défaut' 'Notification par défaut'
end end

View file

@ -145,6 +145,13 @@ shared_examples 'description_controller_spec' do
end end
context 'Quand la procédure accepte les CERFA' do 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 context 'Sauvegarde du CERFA PDF', vcr: {cassette_name: 'controllers_users_description_controller_save_cerfa'} do
before do before do
post :create, params: {dossier_id: dossier_id, post :create, params: {dossier_id: dossier_id,