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.rbindex c4b741a118e..d7e271d3ed8 100644--- a/lib/bookmark_reminder_notification_handler.rb+++ b/lib/bookmark_reminder_notification_handler.rb@@ -9,16 +9,17 @@ class BookmarkReminderNotificationHandlerdef send_notificationreturn 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-+ elsebookmark.clear_reminder!endenddiff --git a/spec/lib/bookmark_reminder_notification_handler_spec.rb b/spec/lib/bookmark_reminder_notification_handler_spec.rbindex 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" dobefore doFabricate(@@ -86,6 +95,15 @@ RSpec.describe BookmarkReminderNotificationHandler dosend_notificationexpect(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!)+ endendcontext "when the auto_delete_preference is never" do