Add Oauth check to AwardContributorFromGithub (#17155)

* Add oauth check to AwardContributorFromGithub

* Add spec

* Simplify spec
This commit is contained in:
Mac Siri 2022-04-06 15:41:20 -04:00 committed by GitHub
parent 0ca5096a9e
commit d28aa37ed2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View file

@ -25,6 +25,8 @@ module Badges
end
def call
return unless Settings::Authentication.providers.include?(:github)
REPOSITORIES.each do |repo|
award_single_commit_contributors(repo)
award_multi_commit_contributors(repo)

View file

@ -6,9 +6,17 @@ RSpec.describe Badges::AwardContributorFromGithub, type: :service, vcr: true do
before do
badge
omniauth_mock_github_payload
allow(Settings::Authentication).to receive(:providers).and_return([:github])
stub_const("#{described_class}::REPOSITORIES", ["forem/DEV-Android"])
end
it "won't work without Github oauth configured" do
allow(Settings::Authentication).to receive(:providers).and_return([])
user = create(:user, :with_identity, identities: ["github"], uid: "389169")
expect { described_class.call }.not_to change(user.badge_achievements, :count)
end
it "awards contributor badge" do
user = create(:user, :with_identity, identities: ["github"], uid: "389169")