Skip to content

A platform for community discussion. Free, open, simple.

FIX: don't clear reminder on deleted bookmarks (#35987)

Régis Hanolca3a2d2c8861
diff --git a/lib/bookmark_reminder_notification_handler.rb b/lib/bookmark_reminder_notification_handler.rb
index c4b741a118e..d7e271d3ed8 100644
--- a/lib/bookmark_reminder_notification_handler.rb
+++ b/lib/bookmark_reminder_notification_handler.rb
@@ -9,16 +9,17 @@ class BookmarkReminderNotificationHandler
def send_notification
return if bookmark.blank?
+
Bookmark.transaction do
- if !bookmark.registered_bookmarkable.can_send_reminder?(bookmark)
- bookmark.clear_reminder!
- else
+ if bookmark.registered_bookmarkable.can_send_reminder?(bookmark)
bookmark.registered_bookmarkable.send_reminder_notification(bookmark)
if bookmark.auto_delete_when_reminder_sent?
BookmarkManager.new(bookmark.user).destroy(bookmark.id)
+ else
+ bookmark.clear_reminder!
end
-
+ else
bookmark.clear_reminder!
end
end
diff --git a/spec/lib/bookmark_reminder_notification_handler_spec.rb b/spec/lib/bookmark_reminder_notification_handler_spec.rb
index 103ada423f1..ea676d2cb15 100644
--- a/spec/lib/bookmark_reminder_notification_handler_spec.rb
+++ b/spec/lib/bookmark_reminder_notification_handler_spec.rb
@@ -58,6 +58,15 @@ RSpec.describe BookmarkReminderNotificationHandler do
)
end
+ it "does not call clear_reminder! after deleting the bookmark" do
+ allow(bookmark).to receive(:clear_reminder!)
+
+ send_notification
+
+ expect(Bookmark.find_by(id: bookmark.id)).to be_nil
+ expect(bookmark).not_to have_received(:clear_reminder!)
+ end
+
context "if there are still other bookmarks in the topic" do
before do
Fabricate(
@@ -86,6 +95,15 @@ RSpec.describe BookmarkReminderNotificationHandler do
send_notification
expect(Bookmark.find_by(id: bookmark.id).reminder_at).to eq(nil)
end
+
+ it "calls clear_reminder! and keeps the bookmark" do
+ allow(bookmark).to receive(:clear_reminder!).and_call_original
+
+ send_notification
+
+ expect(Bookmark.find_by(id: bookmark.id)).not_to be_nil
+ expect(bookmark).to have_received(:clear_reminder!)
+ end
end
context "when the auto_delete_preference is never" do