0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-09 21:45:25 +08:00
discourse/spec/models/reviewable_claimed_topic_spec.rb
Régis Hanol 32afc4d1f7
FIX: Only record deliberate reviewable claims in the timeline (#42375)
Previously, claiming a topic recorded a history entry on every
reviewable it contained, including ones resolved long ago, and the
transient lock taken whenever a moderator opens a confirmation dialog or
an action modal was recorded the same way — even on the sites where
claiming is disabled, which is the default. A flag that stayed open
therefore accumulated an endless list of claim/unclaim pairs, most of
them recording activity on other flags entirely.

This change records only deliberate claims, and only against reviewables
that are still pending, so a resolved item's timeline stops changing and
the entries that remain correspond to real moderation decisions.
2026-08-06 10:08:08 +02:00

73 lines
2.4 KiB
Ruby
Vendored

# 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 "#log_topic_history" do
fab!(:topic)
fab!(:moderator)
fab!(:pending_reviewable) { Fabricate(:reviewable_flagged_post, topic:) }
fab!(:resolved_reviewable) { Fabricate(:reviewable_flagged_post, topic:, status: :approved) }
it "logs on every pending reviewable of the topic, never on resolved ones" do
claim = Fabricate(:reviewable_claimed_topic, topic:, user: moderator)
claim.log_topic_history(:claimed, moderator)
expect(pending_reviewable.history.claimed.size).to eq(1)
expect(resolved_reviewable.history.claimed).to be_empty
end
it "logs nothing for an automatic claim, which is a transient lock" do
claim = Fabricate(:reviewable_claimed_topic, topic:, user: moderator, automatic: true)
claim.log_topic_history(:claimed, moderator)
expect(pending_reviewable.history.claimed).to be_empty
end
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.keys).to contain_exactly(topic1.id, 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.keys).to contain_exactly(topic2.id)
end
end
end