FIX: Make sure topic_user.bookmarked is synced in more places (#13383)

When we call Bookmark.cleanup! we want to make sure that
topic_user.bookmarked is updated for topics linked to the
bookmarks that were deleted. Also when PostDestroyer calls
destroy and recover. We have a job for this already --
SyncTopicUserBookmarked -- so we just utilize that.
This commit is contained in:
Martin Brennan
2021-06-16 08:30:40 +10:00
committed by GitHub
parent 4dc8c3c409
commit c659e3e95b
6 changed files with 70 additions and 4 deletions

View File

@ -241,6 +241,13 @@ describe PostDestroyer do
expect(UserAction.where(target_topic_id: post.topic_id, action_type: UserAction::NEW_TOPIC).count).to eq(1)
expect(UserAction.where(target_topic_id: post.topic_id, action_type: UserAction::REPLY).count).to eq(1)
end
it "runs the SyncTopicUserBookmarked for the topic that the post is in so topic_users.bookmarked is correct" do
PostDestroyer.new(@user, @reply).destroy
expect_enqueued_with(job: :sync_topic_user_bookmarked, args: { topic_id: @reply.topic_id }) do
PostDestroyer.new(@user, @reply.reload).recover
end
end
end
context "recovered by admin" do
@ -465,6 +472,12 @@ describe PostDestroyer do
expect(post.raw).to eq(I18n.t('js.post.deleted_by_author_simple'))
end
it "runs the SyncTopicUserBookmarked for the topic that the post is in so topic_users.bookmarked is correct" do
post2 = create_post
PostDestroyer.new(post2.user, post2).destroy
expect_job_enqueued(job: :sync_topic_user_bookmarked, args: { topic_id: post2.topic_id })
end
context "as a moderator" do
it "deletes the post" do
author = post.user