From 3d95642aca30c3dddc665c6d2379e7545227aaa4 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Thu, 16 Feb 2017 03:02:38 +0100 Subject: [PATCH] Fix receiving multiple mentioned-in-comment notifications When somebody commented multiple times and is mentioned in another comment afterwards, the person received multiple notifications. --- app/models/notifications/mentioned_in_comment.rb | 2 +- spec/integration/mentioning_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/notifications/mentioned_in_comment.rb b/app/models/notifications/mentioned_in_comment.rb index 5e5466b68..5b57f395b 100644 --- a/app/models/notifications/mentioned_in_comment.rb +++ b/app/models/notifications/mentioned_in_comment.rb @@ -11,7 +11,7 @@ module Notifications end def self.filter_mentions(mentions, mentionable, _recipient_user_ids) - mentions.joins(:person).merge(Person.allowed_to_be_mentioned_in_a_comment_to(mentionable.parent)) + mentions.includes(:person).merge(Person.allowed_to_be_mentioned_in_a_comment_to(mentionable.parent)).distinct end def mail_job diff --git a/spec/integration/mentioning_spec.rb b/spec/integration/mentioning_spec.rb index 2e6b4292d..367758bf8 100644 --- a/spec/integration/mentioning_spec.rb +++ b/spec/integration/mentioning_spec.rb @@ -376,6 +376,18 @@ describe "mentioning", type: :request do end end end + + it "only creates one notification for the mentioned person, when mentioned person commented twice before" do + parent = FactoryGirl.create(:status_message_in_aspect, author: author.person) + mentioned_user = FactoryGirl.create(:user_with_aspect, friends: [author]) + mentioned_user.comment!(parent, "test comment 1") + mentioned_user.comment!(parent, "test comment 2") + comment = inlined_jobs do + author.comment!(parent, text_mentioning(mentioned_user)) + end + + expect(notifications_about_mentioning(mentioned_user, comment).count).to eq(1) + end end end end