Add notification for submitted state

This commit is contained in:
Xavier J 2016-12-26 11:57:08 +01:00
parent 33c1a12b84
commit 33362d1a52
4 changed files with 17 additions and 1 deletions

View file

@ -42,6 +42,7 @@ class Dossier < ActiveRecord::Base
after_save :build_default_champs, if: Proc.new { procedure_id_changed? } after_save :build_default_champs, if: Proc.new { procedure_id_changed? }
after_save :build_default_individual, if: Proc.new { procedure.for_individual? } after_save :build_default_individual, if: Proc.new { procedure.for_individual? }
after_save :internal_notification
validates :user, presence: true validates :user, presence: true
@ -327,4 +328,12 @@ class Dossier < ActiveRecord::Base
def invite_by_user? email def invite_by_user? email
(invites_user.pluck :email).include? email (invites_user.pluck :email).include? email
end end
private
def internal_notification
if state_changed? && state == 'submitted'
NotificationService.new('submitted', self.id).notify
end
end
end end

View file

@ -7,7 +7,8 @@ class Notification < ActiveRecord::Base
commentaire: 'commentaire', commentaire: 'commentaire',
cerfa: 'cerfa', cerfa: 'cerfa',
piece_justificative: 'piece_justificative', piece_justificative: 'piece_justificative',
champs: 'champs' champs: 'champs',
submitted: 'submitted'
} }
# def broadcast_notification # def broadcast_notification

View file

@ -33,6 +33,8 @@ class NotificationService
attribut attribut
when 'champs' when 'champs'
attribut attribut
when 'submitted'
"Le dossier n°#{@dossier_id} a été déposé."
else else
'Notification par défaut' 'Notification par défaut'
end end

View file

@ -82,6 +82,10 @@ describe Users::RecapitulatifController, type: :controller do
dossier.validated! dossier.validated!
post :submit, params: {dossier_id: dossier.id} post :submit, params: {dossier_id: dossier.id}
end 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 end
end end