From 5ab7f7e88d59e015fe35990cb2df33c2dca03e56 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 19 Jun 2015 12:31:36 +1000 Subject: [PATCH] FIX: double like notification If you got a like -> edit/quote/etc -> like you would get a double notification --- app/services/post_alerter.rb | 4 +++- spec/services/post_alerter_spec.rb | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rb index f90754c22c8..59250eae3f7 100644 --- a/app/services/post_alerter.rb +++ b/app/services/post_alerter.rb @@ -107,7 +107,9 @@ class PostAlerter # Don't notify the same user about the same notification on the same post existing_notification = user.notifications .order("notifications.id desc") - .find_by(topic_id: post.topic_id, post_number: post.post_number) + .find_by(topic_id: post.topic_id, + post_number: post.post_number, + notification_type: type) if existing_notification && existing_notification.notification_type == type return unless existing_notification.notification_type == Notification.types[:edited] && diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rb index df4b27510eb..cd30348da7b 100644 --- a/spec/services/post_alerter_spec.rb +++ b/spec/services/post_alerter_spec.rb @@ -9,6 +9,23 @@ describe PostAlerter do PostAlerter.post_created(post) end + context 'likes' do + it 'does not double notify users on likes' do + ActiveRecord::Base.observers.enable :all + + post = Fabricate(:post, raw: 'I love waffles') + PostAction.act(evil_trout, post, PostActionType.types[:like]) + + admin = Fabricate(:admin) + post.revise(admin, {raw: 'I made a revision'}) + + PostAction.act(admin, post, PostActionType.types[:like]) + + # one like and one edit notification + expect(Notification.count(post_number: 1, topic_id: post.topic_id)).to eq(2) + end + end + context 'quotes' do it 'does not notify for muted users' do