mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:26:54 -06:00
FIX: Don't ever grant badges when they're disabled
This commit is contained in:
parent
b4b96bf62b
commit
4061725a95
@ -12,6 +12,7 @@ class BadgeGranter
|
||||
|
||||
def grant
|
||||
return if @granted_by and !Guardian.new(@granted_by).can_grant_badges?(@user)
|
||||
return unless @badge.enabled?
|
||||
|
||||
find_by = { badge_id: @badge.id, user_id: @user.id }
|
||||
|
||||
|
@ -604,11 +604,18 @@ describe CookedPostProcessor do
|
||||
|
||||
before { Oneboxer.stubs(:onebox) }
|
||||
|
||||
it "awards a badge for using an emoji" do
|
||||
it "awards a badge for using an onebox" do
|
||||
cpp.post_process_oneboxes
|
||||
cpp.grant_badges
|
||||
expect(post.user.user_badges.where(badge_id: Badge::FirstOnebox).exists?).to eq(true)
|
||||
end
|
||||
|
||||
it "doesn't award the badge when the badge is disabled" do
|
||||
Badge.where(id: Badge::FirstOnebox).update_all(enabled: false)
|
||||
cpp.post_process_oneboxes
|
||||
cpp.grant_badges
|
||||
expect(post.user.user_badges.where(badge_id: Badge::FirstOnebox).exists?).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
context "reply_by_email" do
|
||||
|
@ -106,7 +106,14 @@ describe BadgeGranter do
|
||||
|
||||
expect(user_badge.granted_at).to eq(time)
|
||||
expect(Notification.where(user_id: user.id).count).to eq(0)
|
||||
end
|
||||
|
||||
it "doesn't grant disabled badges" do
|
||||
badge = Fabricate(:badge, badge_type_id: BadgeType::Bronze, enabled: false)
|
||||
time = 1.year.ago
|
||||
|
||||
user_badge = BadgeGranter.grant(badge, user, created_at: time)
|
||||
expect(user_badge).to eq(nil)
|
||||
end
|
||||
|
||||
it 'grants multiple badges' do
|
||||
|
Loading…
Reference in New Issue
Block a user