From f06b773d2569c4a8ff3528349a302fce92bf5ffa Mon Sep 17 00:00:00 2001
From: Guo Xiang Tan <tgx_world@hotmail.com>
Date: Wed, 16 Jan 2019 17:08:59 +0800
Subject: [PATCH] FIX: Don't show liked consolidated notification when
 frequency is never.

---
 app/models/notification.rb       |  9 ++++++++-
 spec/models/notification_spec.rb | 21 +++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/app/models/notification.rb b/app/models/notification.rb
index 40663702986..bb692273ce3 100644
--- a/app/models/notification.rb
+++ b/app/models/notification.rb
@@ -152,7 +152,14 @@ class Notification < ActiveRecord::Base
       .includes(:topic)
 
     if user.user_option.like_notification_frequency == UserOption.like_notification_frequency_type[:never]
-      notifications = notifications.where('notification_type <> ?', Notification.types[:liked])
+      [
+        Notification.types[:liked],
+        Notification.types[:liked_consolidated]
+      ].each do |notification_type|
+        notifications = notifications.where(
+          'notification_type <> ?', notification_type
+        )
+      end
     end
 
     notifications = notifications.to_a
diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb
index 39b20554f06..3a7969fedca 100644
--- a/spec/models/notification_spec.rb
+++ b/spec/models/notification_spec.rb
@@ -303,6 +303,10 @@ describe Notification do
       fab(Notification.types[:liked], true)
     end
 
+    def liked_consolidated
+      fab(Notification.types[:liked_consolidated], true)
+    end
+
     it 'correctly finds visible notifications' do
       pm
       expect(Notification.visible.count).to eq(1)
@@ -322,5 +326,22 @@ describe Notification do
       expect(notifications.map { |n| n.id }).to eq([a.id, d.id, c.id])
 
     end
+
+    describe 'for a user that does not want to be notify on liked' do
+      before do
+        user.user_option.update!(
+          like_notification_frequency:
+            UserOption.like_notification_frequency_type[:never]
+        )
+      end
+
+      it "should not return any form of liked notifications" do
+        notification = pm
+        regular
+        liked_consolidated
+
+        expect(Notification.recent_report(user)).to contain_exactly(notification)
+      end
+    end
   end
 end