Don't bundle new notifications is bundling is disabled

This commit is contained in:
Jorge Manrubia
2025-08-28 12:53:19 +02:00
parent 4e2717a61f
commit 960f074b3f
3 changed files with 17 additions and 4 deletions
+1 -1
View File
@@ -43,6 +43,6 @@ class Notification < ApplicationRecord
end
def bundle
user.bundle(self)
user.bundle(self) if user.settings.bundling_emails?
end
end
+7 -3
View File
@@ -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
+9
View File
@@ -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)