Feature: Paying it forward badge

This commit is contained in:
Sam 2014-07-08 14:26:53 +10:00
parent fae3eab580
commit 81682b74b7
4 changed files with 31 additions and 2 deletions

View File

@ -7,12 +7,24 @@ class Badge < ActiveRecord::Base
GreatPost = 8
Autobiographer = 9
Editor = 10
PayingItForward = 11
# other consts
AutobiographerMinBioLength = 10
module Queries
PayingItForward = <<SQL
SELECT pa.user_id, min(post_id) post_id, min(pa.created_at) granted_at
FROM post_actions pa
JOIN posts p on p.id = pa.post_id
JOIN topics t on t.id = p.topic_id
WHERE p.deleted_at IS NULL AND
t.deleted_at IS NULL AND
t.visible AND
post_action_type_id = 2
GROUP BY pa.user_id
SQL
Editor = <<SQL
SELECT p.user_id, min(p.id) post_id, min(p.created_at) granted_at

View File

@ -1977,3 +1977,6 @@ en:
great_post:
name: Great Post
description: Received 50 likes on a post. This badge can be granted multiple times.
paying_it_forward:
name: Paying It Forward
description: Liked a post

View File

@ -15,6 +15,15 @@ trust_level_badges.each do |spec|
end
end
Badge.seed do |b|
b.id = Badge::PayingItForward
b.name = "Paying It Forward"
b.badge_type_id = BadgeType::Bronze
b.multiple_grant = false
b.target_posts = true
b.query = Badge::Queries::PayingItForward
end
Badge.seed do |b|
b.id = Badge::Welcome
b.name = "Welcome"

View File

@ -20,10 +20,15 @@ describe BadgeGranter do
UserBadge.destroy_all
BadgeGranter.backfill(Badge.find(Badge::Welcome))
BadgeGranter.backfill(Badge.find(Badge::PayingItForward))
b = UserBadge.first
b.user_id.should == post.user_id
b = UserBadge.find_by(user_id: post.user_id)
b.post_id.should == post.id
b.badge_id = Badge::Welcome
b = UserBadge.find_by(user_id: user2.id)
b.post_id.should == post.id
b.badge_id = Badge::PayingItForward
end
it 'should grant missing badges' do