FIX: handle badge grant for deleted badge (#11558)

This commit is contained in:
Arpit Jalan 2020-12-22 20:24:51 +05:30 committed by GitHub
parent e113ddc73c
commit c9381beb9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -44,7 +44,7 @@ class BadgeGranter
def grant
return if @granted_by && !Guardian.new(@granted_by).can_grant_badges?(@user)
return unless @badge.enabled?
return unless @badge.present? && @badge.enabled?
return if @badge.badge_grouping_id == BadgeGrouping::GettingStarted && @badge.id != Badge::NewUserOfTheMonth && @user.user_option.skip_new_user_tips
find_by = { badge_id: @badge.id, user_id: @user.id }

View File

@ -208,6 +208,12 @@ describe BadgeGranter do
expect(Notification.where(user_id: user.id).count).to eq(0)
end
it "handles deleted badge" do
freeze_time
user_badge = BadgeGranter.grant(nil, user, created_at: 1.year.ago)
expect(user_badge).to eq(nil)
end
it "doesn't grant disabled badges" do
freeze_time
badge = Fabricate(:badge, badge_type_id: BadgeType::Bronze, enabled: false)