<commit_before>require "spec_helper"

describe AuthHelper do
  describe "button_based_providers" do
    it 'returns all enabled providers from devise' do
      allow(helper).to receive(:auth_providers) { [:twitter, :github] }
      expect(helper.button_based_providers).to include(*[:twitter, :github])
    end

    it 'does not return ldap provider' do
      allow(helper).to receive(:auth_providers) { [:twitter, :ldapmain] }
      expect(helper.button_based_providers).to include(:twitter)
    end

    it 'returns empty array' do
      allow(helper).to receive(:auth_providers) { [] }
      expect(helper.button_based_providers).to eq([])
    end
  end

  describe 'enabled_button_based_providers' do
    it 'returns all the enabled providers from settings' do
      allow(helper).to receive(:auth_providers) { [:twitter, :github] }
      expect(helper.enabled_button_based_providers).to include(*['twitter', 'github'])
    end

    it "should not return github as provider because it's disabled from settings" do
      stub_application_setting(
        disabled_oauth_sign_in_sources: ['github']
      )

      allow(helper).to receive(:auth_providers) { [:twitter, :github] }

      expect(helper.enabled_button_based_providers).to include('twitter')
      expect(helper.enabled_button_based_providers).to_not include('github')
    end

    it 'returns true for button_based_providers_enabled? because there providers' do
      allow(helper).to receive(:auth_providers) { [:twitter, :github] }

      expect(helper.button_based_providers_enabled?).to be true
    end

    it 'returns false for button_based_providers_enabled? because there providers' do
      stub_application_setting(
        disabled_oauth_sign_in_sources: ['github', 'twitter']
      )

      allow(helper).to receive(:auth_providers) { [:twitter, :github] }

      expect(helper.button_based_providers_enabled?).to be false
    end
  end
end<commit_msg>DRYing enabled_button_based_providers tests<commit_after>require "spec_helper"

describe AuthHelper do
  describe "button_based_providers" do
    it 'returns all enabled providers from devise' do
      allow(helper).to receive(:auth_providers) { [:twitter, :github] }
      expect(helper.button_based_providers).to include(*[:twitter, :github])
    end

    it 'does not return ldap provider' do
      allow(helper).to receive(:auth_providers) { [:twitter, :ldapmain] }
      expect(helper.button_based_providers).to include(:twitter)
    end

    it 'returns empty array' do
      allow(helper).to receive(:auth_providers) { [] }
      expect(helper.button_based_providers).to eq([])
    end
  end

  describe 'enabled_button_based_providers' do
    before do
      allow(helper).to receive(:auth_providers) { [:twitter, :github] }
    end

    it 'returns all the enabled providers from settings' do
      expect(helper.enabled_button_based_providers).to include(*['twitter', 'github'])
    end

    it "should not return github as provider because it's disabled from settings" do
      stub_application_setting(
        disabled_oauth_sign_in_sources: ['github']
      )

      expect(helper.enabled_button_based_providers).to include('twitter')
      expect(helper.enabled_button_based_providers).to_not include('github')
    end

    it 'returns true for button_based_providers_enabled? because there providers' do
      expect(helper.button_based_providers_enabled?).to be true
    end

    it 'returns false for button_based_providers_enabled? because there providers' do
      stub_application_setting(
        disabled_oauth_sign_in_sources: ['github', 'twitter']
      )

      expect(helper.button_based_providers_enabled?).to be false
    end
  end
end
{'fraction_non_alphanumeric': 0.09664320519761777, 'fraction_numerical': 0.0, 'mean_word_length': 4.054719562243502, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5979972', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1061, 'n_words': 260}