mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Use bookmarkable pattern for bookmark cleanup (#17202)
We have a `cleanup!` class method on bookmarks that deletes bookmarks X days after their related record (post/topic) are deleted. This commit changes this method to use the registered_bookmarkables for this instead, and each bookmarkable type can delete related bookmarks in their own way.
This commit is contained in:
@@ -60,7 +60,7 @@ describe Bookmark do
|
||||
expect_job_enqueued(job: :sync_topic_user_bookmarked, args: { topic_id: post2.topic_id })
|
||||
end
|
||||
|
||||
it "deletes bookmarks attached to a deleted topic which has been deleted for > 3 days" do
|
||||
it "deletes bookmarks attached via a post to a deleted topic which has been deleted for > 3 days" do
|
||||
bookmark = Fabricate(:bookmark, bookmarkable: post)
|
||||
bookmark2 = Fabricate(:bookmark, bookmarkable: Fabricate(:post, topic: post.topic))
|
||||
bookmark3 = Fabricate(:bookmark)
|
||||
@@ -70,6 +70,21 @@ describe Bookmark do
|
||||
expect(Bookmark.find_by(id: bookmark.id)).to eq(nil)
|
||||
expect(Bookmark.find_by(id: bookmark2.id)).to eq(nil)
|
||||
expect(Bookmark.find_by(id: bookmark3.id)).to eq(bookmark3)
|
||||
expect_job_enqueued(job: :sync_topic_user_bookmarked, args: { topic_id: post.topic_id })
|
||||
end
|
||||
|
||||
it "deletes bookmarks attached via the topic to a deleted topic which has been deleted for > 3 days" do
|
||||
topic = Fabricate(:topic)
|
||||
bookmark = Fabricate(:bookmark, bookmarkable: topic)
|
||||
bookmark2 = Fabricate(:bookmark, bookmarkable: Fabricate(:post, topic: topic))
|
||||
bookmark3 = Fabricate(:bookmark)
|
||||
topic.trash!
|
||||
topic.update(deleted_at: 4.days.ago)
|
||||
Bookmark.cleanup!
|
||||
expect(Bookmark.find_by(id: bookmark.id)).to eq(nil)
|
||||
expect(Bookmark.find_by(id: bookmark2.id)).to eq(nil)
|
||||
expect(Bookmark.find_by(id: bookmark3.id)).to eq(bookmark3)
|
||||
expect_job_enqueued(job: :sync_topic_user_bookmarked, args: { topic_id: topic.id })
|
||||
end
|
||||
|
||||
it "does not delete bookmarks attached to posts that are not deleted or that have not met the 3 day grace period" do
|
||||
|
||||
Reference in New Issue
Block a user