From 960f074b3f77a1b2ea293ee16eecf2e1516a410a Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Thu, 28 Aug 2025 12:53:19 +0200 Subject: [PATCH] Don't bundle new notifications is bundling is disabled --- app/models/notification.rb | 2 +- app/models/user/settings.rb | 10 +++++++--- test/models/notification/bundle_test.rb | 9 +++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index 0b1e2e377..3f5a00aac 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -43,6 +43,6 @@ class Notification < ApplicationRecord end def bundle - user.bundle(self) + user.bundle(self) if user.settings.bundling_emails? end end diff --git a/app/models/user/settings.rb b/app/models/user/settings.rb index 3de7d8a79..57206cd26 100644 --- a/app/models/user/settings.rb +++ b/app/models/user/settings.rb @@ -19,12 +19,16 @@ class User::Settings < ApplicationRecord end end + def bundling_emails? + !bundle_email_never? + end + private def review_pending_bundles - if bundle_email_never? - cancel_pending_bundles - else + if bundling_emails? reschedule_pending_bundles + else + cancel_pending_bundles end end diff --git a/test/models/notification/bundle_test.rb b/test/models/notification/bundle_test.rb index a84627b3e..9d7848db4 100644 --- a/test/models/notification/bundle_test.rb +++ b/test/models/notification/bundle_test.rb @@ -3,6 +3,7 @@ require "test_helper" class Notification::BundleTest < ActiveSupport::TestCase setup do @user = users(:david) + @user.settings.bundle_email_every_few_hours! end test "new notifications are bundled" do @@ -14,6 +15,14 @@ class Notification::BundleTest < ActiveSupport::TestCase assert_includes bundle.notifications, notification end + test "don't bundle new notifications if bundling is disabled" do + @user.settings.bundle_email_never! + + assert_no_difference -> { @user.notification_bundles.count } do + @user.notifications.create!(source: events(:logo_published), creator: @user) + end + end + test "notifications are bundled withing the aggregation period" do notification_1 = assert_difference -> { @user.notification_bundles.pending.count }, 1 do @user.notifications.create!(source: events(:logo_published), creator: @user)