FIX: Don't count private content in New User of the Month

This commit is contained in:
Robin Ward 2017-09-27 15:02:43 -04:00
parent 6a7920ad75
commit fa41913ba5
2 changed files with 20 additions and 2 deletions

View File

@ -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

View File

@ -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)