diff --git a/app/models/cerfa.rb b/app/models/cerfa.rb index 184060706..0e69ca60e 100644 --- a/app/models/cerfa.rb +++ b/app/models/cerfa.rb @@ -24,6 +24,8 @@ class Cerfa < ActiveRecord::Base private def internal_notification - NotificationService.new('cerfa', self.dossier.id).notify + unless dossier.state == 'draft' + NotificationService.new('cerfa', self.dossier.id).notify + end end end \ No newline at end of file diff --git a/app/models/champ.rb b/app/models/champ.rb index 0016b1c45..c9b956a85 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -52,6 +52,8 @@ class Champ < ActiveRecord::Base private def internal_notification - NotificationService.new('champs', self.dossier.id, self.libelle).notify + unless dossier.state == 'draft' + NotificationService.new('champs', self.dossier.id, self.libelle).notify + end end end diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index 2a785da37..c7645ce52 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -13,6 +13,8 @@ class Commentaire < ActiveRecord::Base private def internal_notification - NotificationService.new('commentaire', self.dossier.id).notify + if email == dossier.user.email || dossier.invites.pluck(:email).to_a.include?(email) + NotificationService.new('commentaire', self.dossier.id).notify + end end end diff --git a/app/models/piece_justificative.rb b/app/models/piece_justificative.rb index 405871a38..865120e18 100644 --- a/app/models/piece_justificative.rb +++ b/app/models/piece_justificative.rb @@ -49,6 +49,8 @@ class PieceJustificative < ActiveRecord::Base private def internal_notification - NotificationService.new('piece_justificative', self.dossier.id, self.libelle).notify + unless self.type_de_piece_justificative.nil? && dossier.state == 'draft' + NotificationService.new('piece_justificative', self.dossier.id, self.libelle).notify + end end end diff --git a/spec/controllers/backoffice/commentaires_controller_spec.rb b/spec/controllers/backoffice/commentaires_controller_spec.rb index 63ebb3261..2fccafe5e 100644 --- a/spec/controllers/backoffice/commentaires_controller_spec.rb +++ b/spec/controllers/backoffice/commentaires_controller_spec.rb @@ -36,6 +36,10 @@ describe Backoffice::CommentairesController, type: :controller do expect { subject }.to change(Follow, :count).by(0) end end + + it 'Internal notification is not create' do + expect { subject }.to change(Notification, :count).by (0) + end end context 'when document is upload whith a commentaire', vcr: {cassette_name: 'controllers_backoffice_commentaires_controller_doc_upload_with_comment'} do @@ -54,6 +58,10 @@ describe Backoffice::CommentairesController, type: :controller do subject end + it 'Internal notification is not create' do + expect { subject }.to change(Notification, :count).by (0) + end + describe 'piece justificative created' do let(:pj) { PieceJustificative.last } diff --git a/spec/factories/gestionnaire.rb b/spec/factories/gestionnaire.rb index dcdb76c62..63004f8e9 100644 --- a/spec/factories/gestionnaire.rb +++ b/spec/factories/gestionnaire.rb @@ -1,5 +1,5 @@ FactoryGirl.define do - sequence(:gestionnaire_email) { |n| "plop#{n}@plop.com" } + sequence(:gestionnaire_email) { |n| "gest#{n}@plop.com" } factory :gestionnaire do email { generate(:gestionnaire_email) } password 'password'