From 33362d1a525f1f80d3d0d1749f895a709cdf63e9 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Mon, 26 Dec 2016 11:57:08 +0100 Subject: [PATCH] Add notification for submitted state --- app/models/dossier.rb | 9 +++++++++ app/models/notification.rb | 3 ++- app/services/notification_service.rb | 2 ++ spec/controllers/users/recapitulatif_controller_spec.rb | 4 ++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index e0d7c2979..8680dc64c 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -42,6 +42,7 @@ class Dossier < ActiveRecord::Base after_save :build_default_champs, if: Proc.new { procedure_id_changed? } after_save :build_default_individual, if: Proc.new { procedure.for_individual? } + after_save :internal_notification validates :user, presence: true @@ -327,4 +328,12 @@ class Dossier < ActiveRecord::Base def invite_by_user? email (invites_user.pluck :email).include? email end + + private + + def internal_notification + if state_changed? && state == 'submitted' + NotificationService.new('submitted', self.id).notify + end + end end diff --git a/app/models/notification.rb b/app/models/notification.rb index 9bf44e61a..be256f25a 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -7,7 +7,8 @@ class Notification < ActiveRecord::Base commentaire: 'commentaire', cerfa: 'cerfa', piece_justificative: 'piece_justificative', - champs: 'champs' + champs: 'champs', + submitted: 'submitted' } # def broadcast_notification diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index 1fb438b42..edb011739 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -33,6 +33,8 @@ class NotificationService attribut when 'champs' attribut + when 'submitted' + "Le dossier n°#{@dossier_id} a été déposé." else 'Notification par défaut' end diff --git a/spec/controllers/users/recapitulatif_controller_spec.rb b/spec/controllers/users/recapitulatif_controller_spec.rb index 31e12dad0..3cbbe1696 100644 --- a/spec/controllers/users/recapitulatif_controller_spec.rb +++ b/spec/controllers/users/recapitulatif_controller_spec.rb @@ -82,6 +82,10 @@ describe Users::RecapitulatifController, type: :controller do dossier.validated! post :submit, params: {dossier_id: dossier.id} end + + it 'Internal notification is created' do + expect(Notification.where(dossier_id: dossier.id, type_notif: 'submitted').first).not_to be_nil + end end end end