only grant badge when they are enabled
This commit is contained in:
commit
0a87d8274f
|
@ -15,6 +15,7 @@ module DiscourseDonations
|
|||
end
|
||||
|
||||
def grant_badge(name)
|
||||
return unless SiteSetting.enable_badges
|
||||
badge = ::Badge.find_by_name(name)
|
||||
return if badge.nil?
|
||||
BadgeGranter.grant(badge, user)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
# name: discourse-donations
|
||||
# about: Integrating Discourse with Stripe for donations
|
||||
# version: 1.9.0
|
||||
# version: 1.9.1
|
||||
# url: https://github.com/choiceaustralia/discourse-donations
|
||||
# authors: Rimian Perkins
|
||||
|
||||
gem 'stripe', '2.4.0'
|
||||
gem 'stripe', '2.8.0'
|
||||
|
||||
load File.expand_path('../lib/discourse_donations/engine.rb', __FILE__)
|
||||
|
||||
|
|
|
@ -25,15 +25,27 @@ module DiscourseDonations
|
|||
subject.add_to_group(grp.name)
|
||||
end
|
||||
|
||||
it 'grants the user a badge' do
|
||||
badge = Fabricate(:badge)
|
||||
BadgeGranter.expects(:grant).with(badge, user)
|
||||
subject.grant_badge(badge.name)
|
||||
end
|
||||
describe '.grant_badge' do
|
||||
let(:badge) { Fabricate(:badge) }
|
||||
|
||||
it 'does not grant the user a badge' do
|
||||
BadgeGranter.expects(:grant).never
|
||||
expect(subject.grant_badge('does not exist')).to be_falsy
|
||||
before { SiteSetting.stubs(:enable_badges).returns(true) }
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue