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_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

View file

@ -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

View file

@ -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

View file

@ -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