mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 19:39:30 +08:00
FIX: Ensure topic user bookmarked synced on bookmark auto-delete (#10323)
For the following conditions, the TopicUser.bookmarked column was not updated correctly: * When a bookmark was auto-deleted because the reminder was sent * When a bookmark was auto-deleted because the owner of the bookmark replied to the topic This adds another migration to fix the out-of-sync column and also some refactors to BookmarkManager to allow for more of these delete cases. BookmarkManager is used instead of directly destroying the bookmark in PostCreator and BookmarkReminderNotificationHandler.
This commit is contained in:
@ -35,11 +35,31 @@ RSpec.describe BookmarkReminderNotificationHandler do
|
||||
end
|
||||
|
||||
context "when the auto_delete_preference is when_reminder_sent" do
|
||||
it "deletes the bookmark after the reminder gets sent" do
|
||||
before do
|
||||
TopicUser.create!(topic: bookmark.topic, user: user, bookmarked: true)
|
||||
bookmark.update(auto_delete_preference: Bookmark.auto_delete_preferences[:when_reminder_sent])
|
||||
end
|
||||
|
||||
it "deletes the bookmark after the reminder gets sent" do
|
||||
subject.send_notification(bookmark)
|
||||
expect(Bookmark.find_by(id: bookmark.id)).to eq(nil)
|
||||
end
|
||||
|
||||
it "changes the TopicUser bookmarked column to false" do
|
||||
subject.send_notification(bookmark)
|
||||
expect(TopicUser.find_by(topic: bookmark.topic, user: user).bookmarked).to eq(false)
|
||||
end
|
||||
|
||||
context "if there are still other bookmarks in the topic" do
|
||||
before do
|
||||
Fabricate(:bookmark, topic: bookmark.topic, post: Fabricate(:post, topic: bookmark.topic), user: user)
|
||||
end
|
||||
|
||||
it "does not change the TopicUser bookmarked column to false" do
|
||||
subject.send_notification(bookmark)
|
||||
expect(TopicUser.find_by(topic: bookmark.topic, user: user).bookmarked).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when the post has been deleted" do
|
||||
|
Reference in New Issue
Block a user