FIX: handle badge grant for deleted badge (#11558)
This commit is contained in:
parent
e113ddc73c
commit
c9381beb9c
|
@ -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 }
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue