From 09325403e5b3975b60c7799becd5e2015e78d57f Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Tue, 16 Sep 2025 11:22:14 +0200 Subject: [PATCH] Add missing test (we were only testing this logic via the bundle test) --- app/models/user/notifiable.rb | 1 + test/models/user/notifiable_test.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 test/models/user/notifiable_test.rb diff --git a/app/models/user/notifiable.rb b/app/models/user/notifiable.rb index b0e4ffcad..bb84852d7 100644 --- a/app/models/user/notifiable.rb +++ b/app/models/user/notifiable.rb @@ -16,6 +16,7 @@ module User::Notifiable private def find_or_create_bundle_for(notification) + puts "find_bundle_for(notification)=#{find_bundle_for(notification)}" find_bundle_for(notification) || create_bundle_for(notification) end diff --git a/test/models/user/notifiable_test.rb b/test/models/user/notifiable_test.rb new file mode 100644 index 000000000..c7bc4fabc --- /dev/null +++ b/test/models/user/notifiable_test.rb @@ -0,0 +1,26 @@ +require "test_helper" + +class User::NotifiableTest < ActiveSupport::TestCase + setup do + @user = users(:david) + @user.settings.bundle_email_every_few_hours! + end + + test "bundle method creates new bundle for first notification" do + notification = assert_difference -> { @user.notification_bundles.count }, 1 do + @user.notifications.create!(source: events(:logo_published), creator: @user) + end + + bundle = @user.notification_bundles.last + assert_equal notification.created_at, bundle.starts_at + assert bundle.pending? + end + + test "bundle method finds existing bundle within aggregation period" do + @user.notifications.create!(source: events(:logo_published), creator: @user) + + assert_no_difference -> { @user.notification_bundles.count } do + @user.notifications.create!(source: events(:logo_published), creator: @user) + end + end +end