diff --git a/app/models/topic.rb b/app/models/topic.rb index 7a3a1a5b0b0..4f69e3055d0 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -1423,8 +1423,9 @@ class Topic < ActiveRecord::Base scores = ReviewableScore.pending .joins(:reviewable) - .where("reviewables.topic_id = ?", self.id) - .pluck("COUNT(DISTINCT reviewable_scores.user_id), COALESCE(SUM(reviewable_scores.score), 0.0)") + .where('reviewable_scores.score >= ?', Reviewable.min_score_for_priority) + .where('reviewables.topic_id = ?', self.id) + .pluck('COUNT(DISTINCT reviewable_scores.user_id), COALESCE(SUM(reviewable_scores.score), 0.0)') .first scores[0] >= SiteSetting.num_flaggers_to_close_topic && scores[1] >= Reviewable.score_to_auto_close_topic diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 84df06dd0d9..e4db2d1d00d 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -2574,4 +2574,40 @@ describe Topic do expect(user.user_profile.reload.featured_topic).to eq(nil) end end + + describe '#auto_close_threshold_reached?' do + before do + Reviewable.set_priorities(low: 2.0, medium: 6.0, high: 9.0) + SiteSetting.num_flaggers_to_close_topic = 2 + SiteSetting.reviewable_default_visibility = 'medium' + SiteSetting.auto_close_topic_sensitivity = Reviewable.sensitivity[:high] + post = Fabricate(:post) + @topic = post.topic + @reviewable = Fabricate(:reviewable_flagged_post, target: post, topic: @topic) + end + + it 'ignores flags with a low score' do + 5.times do + @reviewable.add_score( + Fabricate(:user, trust_level: TrustLevel[0]), + PostActionType.types[:spam], + created_at: 1.minute.ago + ) + end + + expect(@topic.auto_close_threshold_reached?).to eq(false) + end + + it 'returns true when the flags have a high score' do + 5.times do + @reviewable.add_score( + Fabricate(:user, admin: true), + PostActionType.types[:spam], + created_at: 1.minute.ago + ) + end + + expect(@topic.auto_close_threshold_reached?).to eq(true) + end + end end