Merge pull request #1326 from basecamp/bundle-time-zone

Fix: use user timezone when delivering notification emails
This commit is contained in:
Jorge Manrubia
2025-10-16 06:36:23 +02:00
committed by GitHub
2 changed files with 21 additions and 3 deletions
+5 -3
View File
@@ -36,11 +36,13 @@ class Notification::Bundle < ApplicationRecord
end
def deliver
processing!
user.in_time_zone do
processing!
Notification::BundleMailer.notification(self).deliver if deliverable?
Notification::BundleMailer.notification(self).deliver if deliverable?
delivered!
delivered!
end
end
def deliver_later
+16
View File
@@ -114,4 +114,20 @@ class Notification::BundleTest < ActiveSupport::TestCase
bundle.reload
assert bundle.pending?
end
test "deliver sends email with time in user's time zone" do
@user.settings.update!(timezone_name: "Madrid")
freeze_time Time.utc(2025, 1, 15, 14, 30, 0) do
@user.notifications.create!(source: events(:logo_published), creator: @user)
bundle = @user.notification_bundles.pending.last
bundle.deliver
email = ActionMailer::Base.deliveries.last
assert_not_nil email
# Time in Madrid should be 15:30 (UTC+1 in winter)
assert_match /everything since 3pm/i, email.text_part&.body&.to_s
end
end
end