From 6ed91073c4377d770d9500709265b6a570c5ce7d Mon Sep 17 00:00:00 2001 From: Xavier J Date: Mon, 26 Dec 2016 11:33:12 +0100 Subject: [PATCH] Add notification for cerfa --- app/models/cerfa.rb | 8 ++++++++ app/models/notification.rb | 13 +++++++------ app/services/notification_service.rb | 2 ++ .../users/description_controller_shared_example.rb | 7 +++++++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/models/cerfa.rb b/app/models/cerfa.rb index 0022ad244..184060706 100644 --- a/app/models/cerfa.rb +++ b/app/models/cerfa.rb @@ -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 \ No newline at end of file diff --git a/app/models/notification.rb b/app/models/notification.rb index 9abe292c1..75396be4b 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -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 diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index 7e5ad2bcb..d4f672a18 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -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 diff --git a/spec/controllers/users/description_controller_shared_example.rb b/spec/controllers/users/description_controller_shared_example.rb index a751f08e2..f74f8e04b 100644 --- a/spec/controllers/users/description_controller_shared_example.rb +++ b/spec/controllers/users/description_controller_shared_example.rb @@ -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,