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