2021-04-13 18:10:53 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe Jobs::SyncTopicUserBookmarked do
|
2023-06-21 09:00:19 -05:00
|
|
|
subject(:job) { described_class.new }
|
|
|
|
|
2023-11-09 16:47:59 -06:00
|
|
|
fab!(:topic)
|
2022-05-08 18:37:23 -05:00
|
|
|
fab!(:post1) { Fabricate(:post, topic: topic) }
|
|
|
|
fab!(:post2) { Fabricate(:post, topic: topic) }
|
|
|
|
fab!(:post3) { Fabricate(:post, topic: topic) }
|
2021-04-13 18:10:53 -05:00
|
|
|
|
2022-05-08 18:37:23 -05:00
|
|
|
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) }
|
2021-04-13 18:10:53 -05:00
|
|
|
|
2022-05-08 18:37:23 -05:00
|
|
|
it "corrects all topic_users.bookmarked records for the topic" do
|
2022-05-22 19:07:15 -05:00
|
|
|
Fabricate(:bookmark, user: tu1.user, bookmarkable: topic.posts.sample)
|
|
|
|
Fabricate(:bookmark, user: tu4.user, bookmarkable: topic.posts.sample)
|
2021-04-13 18:10:53 -05:00
|
|
|
|
2023-06-21 09:00:19 -05:00
|
|
|
job.execute(topic_id: topic.id)
|
2021-04-13 18:10:53 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-06-15 17:30:40 -05:00
|
|
|
it "does not consider topic as bookmarked if the bookmarked post is deleted" do
|
2022-05-22 19:07:15 -05:00
|
|
|
Fabricate(:bookmark, user: tu1.user, bookmarkable: post1)
|
|
|
|
Fabricate(:bookmark, user: tu2.user, bookmarkable: post1)
|
2021-06-15 17:30:40 -05:00
|
|
|
|
|
|
|
post1.trash!
|
|
|
|
|
2023-06-21 09:00:19 -05:00
|
|
|
job.execute(topic_id: topic.id)
|
2021-06-15 17:30:40 -05:00
|
|
|
|
|
|
|
expect(tu1.reload.bookmarked).to eq(false)
|
|
|
|
expect(tu2.reload.bookmarked).to eq(false)
|
|
|
|
end
|
|
|
|
|
2023-11-06 20:54:05 -06:00
|
|
|
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)
|
2021-04-13 18:10:53 -05:00
|
|
|
expect(tu1.reload.bookmarked).to eq(true)
|
|
|
|
end
|
|
|
|
end
|