discourse/spec/models/reviewable_claimed_topic_spec.rb
Gary Pendergast b77d0f7589
FEATURE: Sync Reviewable Status (#31901)
When multiple admins are working in the review queue, it's quite easy for two people to try and handle the same reviewable at the same time. This change addresses the two major situations where this can occur.

The `ReviewableClaimedTopic` model has been extended to allow the system to mark a reviewable as claimed as soon as the first moderator starts handling the reviewable, even when the `reviewable_claiming` setting is disabled. This ensures that reviewable actions with client-site activity (for example, `agree_and_suspend`) will lock the reviewable before another moderator starts working on it.

When someone handles handles a reviewable, we now use `MessageBus` to inform other moderators that it's changed. If any of the other moderator have that reviewable open (either individually, or on the list screen), it will automatically refresh that data.
2025-03-24 14:27:18 +11:00

50 lines
1.6 KiB
Ruby

# frozen_string_literal: true
RSpec.describe ReviewableClaimedTopic, type: :model do
it "respects the uniqueness constraint" do
topic = Fabricate(:topic)
ct = ReviewableClaimedTopic.new(topic_id: topic.id, user_id: Fabricate(:user).id)
expect(ct.save).to eq(true)
ct = ReviewableClaimedTopic.new(topic_id: topic.id, user_id: Fabricate(:user).id)
expect(ct.save).to eq(false)
end
describe "#claimed_hash" do
it "returns the all the claimed topics when reviewable claiming is enabled" do
SiteSetting.reviewable_claiming = "optional"
topic1 = Fabricate(:topic)
topic2 = Fabricate(:topic)
ReviewableClaimedTopic.create(topic_id: topic1.id, user_id: Fabricate(:user).id)
ReviewableClaimedTopic.create(
topic_id: topic2.id,
user_id: Fabricate(:user).id,
automatic: true,
)
result = ReviewableClaimedTopic.claimed_hash([topic1.id, topic2.id])
expect(result[topic1.id].topic_id).to eq(topic1.id)
expect(result[topic2.id].topic_id).to eq(topic2.id)
end
it "only returns the automatic claimed topics when reviewable claiming is disabled" do
SiteSetting.reviewable_claiming = "disabled"
topic1 = Fabricate(:topic)
topic2 = Fabricate(:topic)
ReviewableClaimedTopic.create(topic_id: topic1.id, user_id: Fabricate(:user).id)
ReviewableClaimedTopic.create(
topic_id: topic2.id,
user_id: Fabricate(:user).id,
automatic: true,
)
result = ReviewableClaimedTopic.claimed_hash([topic1.id, topic2.id])
expect(result[topic2.id].topic_id).to eq(topic2.id)
end
end
end