From d28aa37ed20e464967404d0de3145bfdda5d3393 Mon Sep 17 00:00:00 2001 From: Mac Siri Date: Wed, 6 Apr 2022 15:41:20 -0400 Subject: [PATCH] Add Oauth check to AwardContributorFromGithub (#17155) * Add oauth check to AwardContributorFromGithub * Add spec * Simplify spec --- app/services/badges/award_contributor_from_github.rb | 2 ++ .../services/badges/award_contributor_from_github_spec.rb | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/app/services/badges/award_contributor_from_github.rb b/app/services/badges/award_contributor_from_github.rb index 60a05cbee..d4d514f8c 100644 --- a/app/services/badges/award_contributor_from_github.rb +++ b/app/services/badges/award_contributor_from_github.rb @@ -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) diff --git a/spec/services/badges/award_contributor_from_github_spec.rb b/spec/services/badges/award_contributor_from_github_spec.rb index bc4d4ec7c..23dbc1b74 100644 --- a/spec/services/badges/award_contributor_from_github_spec.rb +++ b/spec/services/badges/award_contributor_from_github_spec.rb @@ -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")