From fa41913ba5126d4eb259789c53e6d9b05256b591 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 27 Sep 2017 15:02:43 -0400 Subject: [PATCH] FIX: Don't count private content in New User of the Month --- .../scheduled/grant_new_user_of_the_month_badges.rb | 9 +++++++-- .../jobs/grant_new_user_of_the_month_badges_spec.rb | 13 +++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/jobs/scheduled/grant_new_user_of_the_month_badges.rb b/app/jobs/scheduled/grant_new_user_of_the_month_badges.rb index 83e5b5cc728..be2b537f94f 100644 --- a/app/jobs/scheduled/grant_new_user_of_the_month_badges.rb +++ b/app/jobs/scheduled/grant_new_user_of_the_month_badges.rb @@ -59,10 +59,12 @@ module Jobs LEFT OUTER JOIN post_actions AS pa ON pa.post_id = p.id AND pa.post_action_type_id = :like LEFT OUTER JOIN users AS liked_by ON liked_by.id = pa.user_id + LEFT OUTER JOIN topics AS t ON t.id = p.topic_id WHERE u.active AND u.id > 0 AND NOT(u.admin) AND NOT(u.moderator) AND + t.archetype <> '#{Archetype.private_message}' AND u.created_at >= CURRENT_TIMESTAMP - '1 month'::INTERVAL AND u.id NOT IN (#{current_owners.join(',')}) GROUP BY u.id @@ -73,8 +75,11 @@ module Jobs LIMIT :max_awarded SQL - User.exec_sql(sql, like: PostActionType.types[:like], - max_awarded: MAX_AWARDED).each do |row| + User.exec_sql( + sql, + like: PostActionType.types[:like], + max_awarded: MAX_AWARDED + ).each do |row| scores[row['id'].to_i] = row['score'].to_f end scores diff --git a/spec/jobs/grant_new_user_of_the_month_badges_spec.rb b/spec/jobs/grant_new_user_of_the_month_badges_spec.rb index 27023373ccb..fd77fbf7d52 100644 --- a/spec/jobs/grant_new_user_of_the_month_badges_spec.rb +++ b/spec/jobs/grant_new_user_of_the_month_badges_spec.rb @@ -106,6 +106,19 @@ describe Jobs::GrantNewUserOfTheMonthBadges do expect(granter.scores.keys).not_to include(user.id) end + it "doesn't count private topics" do + user = Fabricate(:user, created_at: 1.week.ago) + topic = Fabricate(:private_message_topic) + Fabricate(:post, topic: topic, user: user) + p = Fabricate(:post, user: user) + old_user = Fabricate(:user, created_at: 6.months.ago) + PostAction.act(old_user, p, PostActionType.types[:like]) + old_user = Fabricate(:user, created_at: 6.months.ago) + PostAction.act(old_user, p, PostActionType.types[:like]) + + expect(granter.scores.keys).not_to include(user.id) + end + it "requires at least two likes to be considered" do user = Fabricate(:user, created_at: 1.week.ago) Fabricate(:post, user: user)