FIX: double like notification

If you got a like -> edit/quote/etc -> like you would get a
double notification
This commit is contained in:
Sam 2015-06-19 12:31:36 +10:00
parent 0dfb9261ea
commit 5ab7f7e88d
2 changed files with 20 additions and 1 deletions

View File

@ -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] &&

View File

@ -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