FIX: multiple grant not working correctly

This commit is contained in:
Sam 2014-07-04 17:40:44 +10:00
parent c2fa382471
commit 650e9348f3
2 changed files with 8 additions and 2 deletions

View file

@ -26,7 +26,7 @@ module Jobs
user = post.user
# Grant "Welcome" badge to the user if they do not already have it.
BadgeGranter.grant(Badge.find(5), user)
BadgeGranter.grant(Badge.find(Badge::Welcome), user)
Badge.like_badge_counts.each do |badge_id, count|
if post.like_count >= count

View file

@ -13,7 +13,13 @@ class BadgeGranter
def grant
return if @granted_by and !Guardian.new(@granted_by).can_grant_badges?(@user)
user_badge = UserBadge.find_by(badge_id: @badge.id, user_id: @user.id, post_id: @post_id)
find_by = { badge_id: @badge.id, user_id: @user.id }
if @badge.multiple_grant?
find_by[:post_id] = @post_id
end
user_badge = UserBadge.find_by(find_by)
if user_badge.nil? || (@badge.multiple_grant? && @post_id.nil?)
UserBadge.transaction do