mirror of
https://github.com/discourse/discourse.git
synced 2025-02-06 03:18:23 +00:00
a86833fe91
This commit fixes an issue where when some actions were done (deleting/recovering post, moving posts) we updated the topic_users.bookmarked column to the wrong value. This was happening because the SyncTopicUserBookmarked job was not taking into account Topic level bookmarks, so if there was a Topic bookmark and no Post bookmarks for a user in the topic, they would have topic_users.bookmarked set to false, which meant the bookmark would no longer show in the /bookmarks list. To reproduce before the fix: * Bookmark a topic and don’t bookmark any posts within * Delete or recover any post in the topic c.f. https://meta.discourse.org/t/disappearing-bookmarks-and-expected-behavior-of-bookmarks/264670/36
49 lines
1.8 KiB
Ruby
49 lines
1.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe Jobs::SyncTopicUserBookmarked do
|
|
subject(:job) { described_class.new }
|
|
|
|
fab!(:topic) { Fabricate(:topic) }
|
|
fab!(:post1) { Fabricate(:post, topic: topic) }
|
|
fab!(:post2) { Fabricate(:post, topic: topic) }
|
|
fab!(:post3) { Fabricate(:post, topic: topic) }
|
|
|
|
fab!(:tu1) { Fabricate(:topic_user, topic: topic, bookmarked: false) }
|
|
fab!(:tu2) { Fabricate(:topic_user, topic: topic, bookmarked: false) }
|
|
fab!(:tu3) { Fabricate(:topic_user, topic: topic, bookmarked: true) }
|
|
fab!(:tu4) { Fabricate(:topic_user, topic: topic, bookmarked: true) }
|
|
fab!(:tu5) { Fabricate(:topic_user, topic: topic, bookmarked: true) }
|
|
|
|
it "corrects all topic_users.bookmarked records for the topic" do
|
|
Fabricate(:bookmark, user: tu1.user, bookmarkable: topic.posts.sample)
|
|
Fabricate(:bookmark, user: tu4.user, bookmarkable: topic.posts.sample)
|
|
|
|
job.execute(topic_id: topic.id)
|
|
|
|
expect(tu1.reload.bookmarked).to eq(true)
|
|
expect(tu2.reload.bookmarked).to eq(false)
|
|
expect(tu3.reload.bookmarked).to eq(false)
|
|
expect(tu4.reload.bookmarked).to eq(true)
|
|
expect(tu5.reload.bookmarked).to eq(false)
|
|
end
|
|
|
|
it "does not consider topic as bookmarked if the bookmarked post is deleted" do
|
|
Fabricate(:bookmark, user: tu1.user, bookmarkable: post1)
|
|
Fabricate(:bookmark, user: tu2.user, bookmarkable: post1)
|
|
|
|
post1.trash!
|
|
|
|
job.execute(topic_id: topic.id)
|
|
|
|
expect(tu1.reload.bookmarked).to eq(false)
|
|
expect(tu2.reload.bookmarked).to eq(false)
|
|
end
|
|
|
|
it "still considers the topic bookmarked if it has a Topic bookmarkable" do
|
|
expect(tu1.reload.bookmarked).to eq(false)
|
|
Fabricate(:bookmark, user: tu1.user, bookmarkable: topic)
|
|
job.execute(topic_id: topic.id)
|
|
expect(tu1.reload.bookmarked).to eq(true)
|
|
end
|
|
end
|