From 8f0051e2c2250728cc660bd9770ca6f3a70b084a Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Mon, 23 Jun 2014 14:02:09 +0200 Subject: [PATCH] Test @all mentioning notifications. --- spec/services/notification_service_spec.rb | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index 57a4240f7a2..f82a14d482c 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -95,6 +95,49 @@ describe NotificationService do end end + context 'issue note mention' do + let(:issue) { create(:issue, assignee: create(:user)) } + let(:mentioned_issue) { create(:issue, assignee: issue.assignee) } + let(:note) { create(:note_on_issue, noteable: issue, project_id: issue.project_id, note: '@all mentioned') } + + before do + build_team(note.project) + end + + describe :new_note do + it do + # Notify all team members + note.project.team.members.each do |member| + # User with disabled notification should not be notified + next if member.id == @u_disabled.id + should_email(member.id) + end + should_email(note.noteable.author_id) + should_email(note.noteable.assignee_id) + + should_not_email(note.author_id) + should_not_email(@u_disabled.id) + should_not_email(@u_not_mentioned.id) + notification.new_note(note) + end + + it 'filters out "mentioned in" notes' do + mentioned_note = Note.create_cross_reference_note(mentioned_issue, issue, issue.author, issue.project) + + Notify.should_not_receive(:note_issue_email) + notification.new_note(mentioned_note) + end + end + + def should_email(user_id) + Notify.should_receive(:note_issue_email).with(user_id, note.id) + end + + def should_not_email(user_id) + Notify.should_not_receive(:note_issue_email).with(user_id, note.id) + end + end + context 'commit note' do let(:note) { create(:note_on_commit) } @@ -312,6 +355,7 @@ describe NotificationService do @u_disabled = create(:user, notification_level: Notification::N_DISABLED) @u_mentioned = create(:user, username: 'mention', notification_level: Notification::N_PARTICIPATING) @u_committer = create(:user, username: 'committer') + @u_not_mentioned = create(:user, username: 'regular', notification_level: Notification::N_PARTICIPATING) project.team << [@u_watcher, :master] project.team << [@u_participating, :master]