From a8d3779f0bb6ee6d48d2c49b158c0a9547f8bc28 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 31 Mar 2017 16:49:10 -0400 Subject: [PATCH] Update New User of the Month badge to require 4 posts in 2 topics --- .../grant_new_user_of_the_month_badges.rb | 2 +- ...grant_new_user_of_the_month_badges_spec.rb | 37 +++++++++++++++++-- 2 files changed, 34 insertions(+), 5 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 2094ceb9cbf..38f3350f78f 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 @@ -51,7 +51,7 @@ module Jobs NOT(u.moderator) AND u.created_at >= CURRENT_TIMESTAMP - '1 month'::INTERVAL GROUP BY u.id - HAVING COUNT(p.id) > 0 + HAVING COUNT(DISTINCT p.id) > 3 AND COUNT(DISTINCT p.topic_id) > 1 ORDER BY score DESC LIMIT :max_awarded SQL 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 f4abe6e9e73..a727edbe885 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 @@ -8,6 +8,9 @@ describe Jobs::GrantNewUserOfTheMonthBadges do it "runs correctly" do user = Fabricate(:user, created_at: 1.week.ago) p = Fabricate(:post, user: user) + Fabricate(:post, user: user) + Fabricate(:post, user: user) + Fabricate(:post, user: user) old_user = Fabricate(:user, created_at: 6.months.ago) PostAction.act(old_user, p, PostActionType.types[:like]) @@ -16,7 +19,6 @@ describe Jobs::GrantNewUserOfTheMonthBadges do badge = user.user_badges.where(badge_id: Badge::NewUserOfTheMonth) expect(badge).to be_present - end describe '.scores' do @@ -24,11 +26,26 @@ describe Jobs::GrantNewUserOfTheMonthBadges do it "doesn't award it to accounts over a month old" do user = Fabricate(:user, created_at: 2.months.ago) Fabricate(:post, user: user) + Fabricate(:post, user: user) + Fabricate(:post, user: user) + Fabricate(:post, user: user) expect(granter.scores.keys).not_to include(user.id) end - it "returns active accounts created in the last month" do + it "doesn't score users who haven't posted in two topics" do user = Fabricate(:user, created_at: 1.week.ago) + p = Fabricate(:post, user: user) + Fabricate(:post, topic_id: p.topic_id, user: user) + Fabricate(:post, topic_id: p.topic_id, user: user) + Fabricate(:post, topic_id: p.topic_id, user: user) + expect(granter.scores.keys).not_to include(user.id) + end + + it "returns scores for accounts created within the last month" do + user = Fabricate(:user, created_at: 1.week.ago) + Fabricate(:post, user: user) + Fabricate(:post, user: user) + Fabricate(:post, user: user) Fabricate(:post, user: user) expect(granter.scores.keys).to include(user.id) end @@ -36,6 +53,9 @@ describe Jobs::GrantNewUserOfTheMonthBadges do it "likes from older accounts are scored higher" do user = Fabricate(:user, created_at: 1.week.ago) p = Fabricate(:post, user: user) + Fabricate(:post, user: user) + Fabricate(:post, user: user) + Fabricate(:post, user: user) new_user = Fabricate(:user, created_at: 2.days.ago) med_user = Fabricate(:user, created_at: 3.weeks.ago) @@ -44,11 +64,11 @@ describe Jobs::GrantNewUserOfTheMonthBadges do PostAction.act(new_user, p, PostActionType.types[:like]) PostAction.act(med_user, p, PostActionType.types[:like]) PostAction.act(old_user, p, PostActionType.types[:like]) - expect(granter.scores[user.id]).to eq(1.6) + expect(granter.scores[user.id]).to eq(0.4) # It goes down the more they post Fabricate(:post, user: user) - expect(granter.scores[user.id]).to eq(0.8) + expect(granter.scores[user.id]).to eq(0.32) end it "is limited to two accounts" do @@ -56,8 +76,17 @@ describe Jobs::GrantNewUserOfTheMonthBadges do u2 = Fabricate(:user, created_at: 2.weeks.ago) u3 = Fabricate(:user, created_at: 3.weeks.ago) + Fabricate(:post, user: u1) + Fabricate(:post, user: u1) + Fabricate(:post, user: u1) Fabricate(:post, user: u1) Fabricate(:post, user: u2) + Fabricate(:post, user: u2) + Fabricate(:post, user: u2) + Fabricate(:post, user: u2) + Fabricate(:post, user: u3) + Fabricate(:post, user: u3) + Fabricate(:post, user: u3) Fabricate(:post, user: u3) expect(granter.scores.keys.size).to eq(2)