From 88c13f11a28e76a732ee3756c18657de9dd7c2e5 Mon Sep 17 00:00:00 2001 From: Rimian Perkins Date: Mon, 1 May 2017 10:48:40 +1000 Subject: [PATCH 1/3] upgrade stripe 2.4.0 > 2.8.0 --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index a41f6ec..9656321 100644 --- a/plugin.rb +++ b/plugin.rb @@ -4,7 +4,7 @@ # 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__) From 9c6cd58a593c913a7e49ad7f66345be88d0f3fda Mon Sep 17 00:00:00 2001 From: Rimian Perkins Date: Mon, 1 May 2017 10:58:14 +1000 Subject: [PATCH 2/3] do not grant badge if badges are disabled --- app/services/discourse_donations/rewards.rb | 1 + .../discourse_donations/rewards_spec.rb | 28 +++++++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/app/services/discourse_donations/rewards.rb b/app/services/discourse_donations/rewards.rb index a901dd3..70eba2a 100644 --- a/app/services/discourse_donations/rewards.rb +++ b/app/services/discourse_donations/rewards.rb @@ -16,6 +16,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) diff --git a/spec/services/discourse_donations/rewards_spec.rb b/spec/services/discourse_donations/rewards_spec.rb index 9daa820..f2ce760 100644 --- a/spec/services/discourse_donations/rewards_spec.rb +++ b/spec/services/discourse_donations/rewards_spec.rb @@ -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 From b99ec2e9e8727322272449ba71a5bd762e11971f Mon Sep 17 00:00:00 2001 From: Rimian Perkins Date: Mon, 1 May 2017 11:31:11 +1000 Subject: [PATCH 3/3] only grant badge when they are enabled --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index 9656321..bcf6e3a 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,6 +1,6 @@ # 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