Basic tests for detecting stalled cards

This commit is contained in:
Jorge Manrubia
2025-06-04 16:14:16 +02:00
parent 84fdeb4a5e
commit 9cdc34f0ae
4 changed files with 49 additions and 4 deletions
+7 -3
View File
@@ -7,8 +7,12 @@ class Card::ActivitySpike::Detector
def detect
if has_activity_spike?
activity_spike = card.activity_spike || card.build_activity_spike
activity_spike.touch
if card.activity_spike
card.activity_spike.touch
else
card.create_activity_spike!
end
true
else
false
@@ -22,7 +26,7 @@ class Card::ActivitySpike::Detector
def multiple_people_commented?
card.comments
.where("created_at >= ?", recent_period.ago)
.where("created_at >= ?", recent_period.seconds.ago)
.group(:card_id)
.having("COUNT(*) >= ?", minimum_comments)
.having("COUNT(DISTINCT creator_id) >= ?", minimum_participants)
+5 -1
View File
@@ -13,7 +13,11 @@ module Card::Stallable
end
def stalled?
activity_spike && activity_spike.updated_at < STALLED_AFTER_LAST_SPIKE_PERIOD.ago
last_activity_spike_at < STALLED_AFTER_LAST_SPIKE_PERIOD.ago if activity_spike.present?
end
def last_activity_spike_at
activity_spike&.updated_at
end
def detect_activity_spikes
@@ -0,0 +1 @@
# See tests in +Card::StallableTest+
+36
View File
@@ -0,0 +1,36 @@
require "test_helper"
class Card::StallableTest < ActiveSupport::TestCase
setup do
Current.session = sessions(:david)
end
test "a card without activity spike is not stalled" do
assert_not cards(:logo).stalled?
end
test "a card with a recent activity spike is not stalled" do
cards(:logo).create_activity_spike!
assert_not cards(:logo).stalled?
end
test "a card with an old activity spike is stalled" do
cards(:logo).create_activity_spike!(updated_at: 3.months.ago)
assert cards(:logo).stalled?
end
# More fine-grained testing in Card::ActivitySpike::Detector
test "detect activity spikes" do
assert_not cards(:logo).stalled?
perform_enqueued_jobs only: Card::ActivitySpike::DetectionJob do
4.times do |index|
cards(:logo).comments.create(body: "Comment number #{index}")
end
end
travel_to 1.month.from_now
assert cards(:logo).reload.stalled?
end
end