diff --git a/app/models/notification.rb b/app/models/notification.rb index 823168a67a5..168f6e40c73 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -64,7 +64,7 @@ class Notification < ActiveRecord::Base DELETE FROM notifications n WHERE high_priority - AND notification_type NOT IN (#{types[:chat_mention].to_i}, #{types[:chat_message].to_i}) + AND n.topic_id IS NOT NULL AND NOT EXISTS ( SELECT 1 FROM posts p diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index 2d897b22ae4..31a4a9bc627 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -340,10 +340,9 @@ describe Notification do expect(Notification.count).to eq(2) end - it 'does not delete chat_message notifications' do + it 'does not delete notifications that do not have a topic_id' do Notification.create!(read: false, user_id: user.id, topic_id: nil, post_number: nil, data: '[]', - notification_type: Notification.types[:chat_mention]) - + notification_type: Notification.types[:chat_mention], high_priority: true) expect { Notification.ensure_consistency! }.to_not change { Notification.count }