auth_helper_spec.rb 2.04 KB
Newer Older
1 2 3 4
require "spec_helper"

describe AuthHelper do
  describe "button_based_providers" do
5 6 7
    let(:settings) { ApplicationSetting.create_from_defaults }

    it 'returns all enabled providers from devise' do
8 9 10 11 12 13 14 15 16 17 18 19 20
      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
21 22 23 24 25 26

    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

Andrei Gliga's avatar
Andrei Gliga committed
27
    it "should not return github as provider because it's disabled from settings" do
28 29 30 31 32 33 34 35 36 37 38
      settings.update_attribute(
        :disabled_oauth_sign_in_sources,
        ['github']
      )

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

      expect(helper.enabled_button_based_providers).to include('twitter')
      expect(helper.enabled_button_based_providers).to_not include('github')
    end
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

    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
      settings.update_attribute(
        :disabled_oauth_sign_in_sources,
        ['github', 'twitter']
      )

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

      expect(helper.button_based_providers_enabled?).to be false
    end
57 58
  end
end