Require at least two likes to get the "New User of the Month" badge
This commit is contained in:
parent
b189486fc0
commit
3d64f33d40
|
@ -54,7 +54,9 @@ module Jobs
|
|||
NOT(u.moderator) AND
|
||||
u.created_at >= CURRENT_TIMESTAMP - '1 month'::INTERVAL
|
||||
GROUP BY u.id
|
||||
HAVING COUNT(DISTINCT p.id) > 1 AND COUNT(DISTINCT p.topic_id) > 1
|
||||
HAVING COUNT(DISTINCT p.id) > 1
|
||||
AND COUNT(DISTINCT p.topic_id) > 1
|
||||
AND COUNT(pa.id) > 1
|
||||
ORDER BY score DESC
|
||||
LIMIT :max_awarded
|
||||
SQL
|
||||
|
|
|
@ -10,6 +10,8 @@ describe Jobs::GrantNewUserOfTheMonthBadges do
|
|||
p = 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])
|
||||
old_user = Fabricate(:user, created_at: 6.months.ago)
|
||||
PostAction.act(old_user, p, PostActionType.types[:like])
|
||||
|
||||
|
@ -24,20 +26,45 @@ 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)
|
||||
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 "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)
|
||||
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)
|
||||
p = Fabricate(:post, user: user)
|
||||
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 "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)
|
||||
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).to include(user.id)
|
||||
end
|
||||
|
||||
|
@ -65,12 +92,23 @@ describe Jobs::GrantNewUserOfTheMonthBadges do
|
|||
u2 = Fabricate(:user, created_at: 2.weeks.ago)
|
||||
u3 = Fabricate(:user, created_at: 3.weeks.ago)
|
||||
|
||||
ou1 = Fabricate(:user, created_at: 6.months.ago)
|
||||
ou2 = Fabricate(:user, created_at: 6.months.ago)
|
||||
|
||||
p = Fabricate(:post, user: u1)
|
||||
Fabricate(:post, user: u1)
|
||||
Fabricate(:post, user: u1)
|
||||
Fabricate(:post, user: u2)
|
||||
PostAction.act(ou1, p, PostActionType.types[:like])
|
||||
PostAction.act(ou2, p, PostActionType.types[:like])
|
||||
|
||||
p = Fabricate(:post, user: u2)
|
||||
Fabricate(:post, user: u2)
|
||||
PostAction.act(ou1, p, PostActionType.types[:like])
|
||||
PostAction.act(ou2, p, PostActionType.types[:like])
|
||||
|
||||
p = Fabricate(:post, user: u3)
|
||||
Fabricate(:post, user: u3)
|
||||
Fabricate(:post, user: u3)
|
||||
PostAction.act(ou1, p, PostActionType.types[:like])
|
||||
PostAction.act(ou2, p, PostActionType.types[:like])
|
||||
|
||||
expect(granter.scores.keys.size).to eq(2)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue