FIX: all badges got revoked due to ensure consistency query

This commit is contained in:
Sam 2016-03-29 23:54:18 +11:00
parent 480e8d0dc7
commit aae835a42f
2 changed files with 3 additions and 2 deletions

View file

@ -378,7 +378,7 @@ SQL
DELETE FROM user_badges
USING user_badges ub
LEFT JOIN users u ON u.id = ub.user_id
WHERE u.id IS NULL
WHERE u.id IS NULL AND user_badges.id = ub.id
SQL
Badge.find_each(&:reset_grant_count!)

View file

@ -49,11 +49,12 @@ describe Badge do
b.save
UserBadge.create!(user_id: -100, badge_id: b.id, granted_at: 1.minute.ago, granted_by_id: -1)
UserBadge.create!(user_id: User.first.id, badge_id: b.id, granted_at: 1.minute.ago, granted_by_id: -1)
Badge.ensure_consistency!
b.reload
expect(b.grant_count).to eq(0)
expect(b.grant_count).to eq(1)
end
end