From 3b46b5ecbf0da3813d97aed394cd73d46009c5dc Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Thu, 31 Jul 2014 10:43:13 -0400 Subject: [PATCH] FIX: TL3 requirements now only counts agreed flags --- app/models/leader_requirements.rb | 20 ++++++++++++++++---- spec/models/leader_requirements_spec.rb | 18 +++++++++++++----- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/app/models/leader_requirements.rb b/app/models/leader_requirements.rb index c5761cc6875..5c71a5a0227 100644 --- a/app/models/leader_requirements.rb +++ b/app/models/leader_requirements.rb @@ -95,7 +95,12 @@ class LeaderRequirements end def num_flagged_posts - PostAction.with_deleted.where(post_id: flagged_post_ids).where.not(user_id: @user.id).pluck(:post_id).uniq.count + PostAction.with_deleted + .where(post_id: flagged_post_ids) + .where.not(user_id: @user.id) + .where.not(agreed_at: nil) + .pluck(:post_id) + .uniq.count end def max_flagged_posts @@ -103,7 +108,12 @@ class LeaderRequirements end def num_flagged_by_users - PostAction.with_deleted.where(post_id: flagged_post_ids).where.not(user_id: @user.id).pluck(:user_id).uniq.count + PostAction.with_deleted + .where(post_id: flagged_post_ids) + .where.not(user_id: @user.id) + .where.not(agreed_at: nil) + .pluck(:user_id) + .uniq.count end def max_flagged_by_users @@ -137,7 +147,9 @@ class LeaderRequirements end def flagged_post_ids - # (TODO? and moderators explicitly agreed with the flags) - @user.posts.with_deleted.where('created_at > ? AND (spam_count > 0 OR inappropriate_count > 0)', TIME_PERIOD.days.ago).pluck(:id) + @user.posts + .with_deleted + .where('created_at > ? AND (spam_count > 0 OR inappropriate_count > 0)', TIME_PERIOD.days.ago) + .pluck(:id) end end diff --git a/spec/models/leader_requirements_spec.rb b/spec/models/leader_requirements_spec.rb index 432f4c78226..2dfe679d53d 100644 --- a/spec/models/leader_requirements_spec.rb +++ b/spec/models/leader_requirements_spec.rb @@ -125,20 +125,28 @@ describe LeaderRequirements do before do user.save flags = [:off_topic, :inappropriate, :notify_user, :notify_moderators, :spam].map do |t| - Fabricate(:flag, post: Fabricate(:post, user: user), post_action_type_id: PostActionType.types[t]) + Fabricate(:flag, post: Fabricate(:post, user: user), post_action_type_id: PostActionType.types[t], agreed_at: 1.minute.ago) + end + + deferred_flags = [:off_topic, :inappropriate, :notify_user, :notify_moderators, :spam].map do |t| + Fabricate(:flag, post: Fabricate(:post, user: user), post_action_type_id: PostActionType.types[t], defered_at: 1.minute.ago) + end + + deleted_flags = [:off_topic, :inappropriate, :notify_user, :notify_moderators, :spam].map do |t| + Fabricate(:flag, post: Fabricate(:post, user: user), post_action_type_id: PostActionType.types[t], deleted_at: 1.minute.ago) end # Same post, different user: - Fabricate(:flag, post: flags[1].post, post_action_type_id: PostActionType.types[:spam]) + Fabricate(:flag, post: flags[1].post, post_action_type_id: PostActionType.types[:spam], agreed_at: 1.minute.ago) # Flagged their own post: - Fabricate(:flag, user: user, post: Fabricate(:post, user: user), post_action_type_id: PostActionType.types[:spam]) + Fabricate(:flag, user: user, post: Fabricate(:post, user: user), post_action_type_id: PostActionType.types[:spam], agreed_at: 1.minute.ago) # More than 100 days ago: - Fabricate(:flag, post: Fabricate(:post, user: user, created_at: 101.days.ago), post_action_type_id: PostActionType.types[:spam], created_at: 101.days.ago) + Fabricate(:flag, post: Fabricate(:post, user: user, created_at: 101.days.ago), post_action_type_id: PostActionType.types[:spam], created_at: 101.days.ago, agreed_at: 1.day.ago) end - it "num_flagged_posts and num_flagged_by_users count spam and inappropriate flags in the last 100 days" do + it "num_flagged_posts and num_flagged_by_users count spam and inappropriate agreed flags in the last 100 days" do leader_requirements.num_flagged_posts.should == 2 leader_requirements.num_flagged_by_users.should == 3 end