From 37be2958f7ec2bb65c05019c370fa3f3b7e0744f Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Thu, 7 May 2020 14:35:32 +1000 Subject: [PATCH] DEV: Allow specifying if a notification is high_priority on create (#9660) This allows for special cases where we may not want a certain notification type to ALWAYS be high priority (e.g. a topic timer). --- app/models/notification.rb | 4 +++- spec/models/notification_spec.rb | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index 0407f17c96e..b549ee50ab4 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -45,7 +45,9 @@ class Notification < ActiveRecord::Base end before_create do - self.high_priority = Notification.high_priority_types.include?(self.notification_type) + # if we have manually set the notification to high_priority on create then + # make sure that is respected + self.high_priority = self.high_priority || Notification.high_priority_types.include?(self.notification_type) end def self.purge_old! diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index 9f0a38a8363..740bf8e50af 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -87,6 +87,24 @@ describe Notification do end + describe 'high priority creation' do + fab!(:user) { Fabricate(:user) } + + it "automatically marks the notification as high priority if it is a high priority type" do + notif = Notification.create(user: user, notification_type: Notification.types[:bookmark_reminder], data: {}) + expect(notif.high_priority).to eq(true) + notif = Notification.create(user: user, notification_type: Notification.types[:private_message], data: {}) + expect(notif.high_priority).to eq(true) + notif = Notification.create(user: user, notification_type: Notification.types[:liked], data: {}) + expect(notif.high_priority).to eq(false) + end + + it "allows manually specifying a notification is high priority" do + notif = Notification.create(user: user, notification_type: Notification.types[:liked], data: {}, high_priority: true) + expect(notif.high_priority).to eq(true) + end + end + describe 'unread counts' do fab!(:user) { Fabricate(:user) }