do not grant badge if badges are disabled

This commit is contained in:
Rimian Perkins 2017-05-01 10:58:14 +10:00
parent 88c13f11a2
commit 9c6cd58a59
2 changed files with 21 additions and 8 deletions

View File

@ -16,6 +16,7 @@ module DiscourseDonations
end end
def grant_badge(name) def grant_badge(name)
return unless SiteSetting.enable_badges
badge = ::Badge.find_by_name(name) badge = ::Badge.find_by_name(name)
return if badge.nil? return if badge.nil?
BadgeGranter.grant(badge, user) BadgeGranter.grant(badge, user)

View File

@ -25,15 +25,27 @@ module DiscourseDonations
subject.add_to_group(grp.name) subject.add_to_group(grp.name)
end end
it 'grants the user a badge' do describe '.grant_badge' do
badge = Fabricate(:badge) let(:badge) { Fabricate(:badge) }
BadgeGranter.expects(:grant).with(badge, user)
subject.grant_badge(badge.name)
end
it 'does not grant the user a badge' do before { SiteSetting.stubs(:enable_badges).returns(true) }
BadgeGranter.expects(:grant).never
expect(subject.grant_badge('does not exist')).to be_falsy it 'grants the user a badge' do
BadgeGranter.expects(:grant).with(badge, user)
subject.grant_badge(badge.name)
end
it 'does not grant the user a badge when the badge does not exist' do
Badge.stubs(:find_by_name).returns(nil)
BadgeGranter.expects(:grant).never
expect(subject.grant_badge('does not exist')).to be_falsy
end
it 'does not grant the user a badge when badges are disabled' do
SiteSetting.stubs(:enable_badges).returns(false)
BadgeGranter.expects(:grant).never
subject.grant_badge(badge.name)
end
end end
end end
end end