Skip to content

Commit

Permalink
FIX: Update featured badge ranking when mass-awarding badges
Browse files Browse the repository at this point in the history
Follow-up to cff6e94
  • Loading branch information
davidtaylorhq committed Jan 14, 2020
1 parent cff6e94 commit 4fdfc26
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/services/badge_granter.rb
Expand Up @@ -28,6 +28,8 @@ def self.mass_grant(badge, users)
user_id: user.id,
badge_id: badge.id
)

UserBadge.update_featured_ranks!(user.id)
end
end

Expand Down
11 changes: 11 additions & 0 deletions spec/jobs/mass_award_badge_spec.rb
Expand Up @@ -28,5 +28,16 @@
expect(Notification.exists?(user: user)).to eq(true)
expect(UserBadge.where.not(notification_id: nil).exists?(user: user, badge: badge)).to eq(true)
end

it 'updates badge ranks correctly' do
user_2 = Fabricate(:user)

UserBadge.create!(badge_id: Badge::Member, user: user, granted_by: Discourse.system_user, granted_at: Time.now)

subject.execute(user_emails: [user.email, user_2.email], badge_id: badge.id)

expect(UserBadge.find_by(user: user, badge: badge).featured_rank).to eq(2)
expect(UserBadge.find_by(user: user_2, badge: badge).featured_rank).to eq(1)
end
end
end

0 comments on commit 4fdfc26

Please sign in to comment.