2015-07-02 10:33:38 -04:00
|
|
|
require "spec_helper"
|
|
|
|
|
|
|
|
describe AuthHelper do
|
|
|
|
describe "button_based_providers" do
|
2016-05-04 10:04:54 -04:00
|
|
|
it 'returns all enabled providers from devise' do
|
2015-07-02 10:33:38 -04:00
|
|
|
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
|
2016-05-09 03:42:57 -04:00
|
|
|
end
|
2016-05-04 10:04:54 -04:00
|
|
|
|
2016-05-09 03:42:57 -04:00
|
|
|
describe 'enabled_button_based_providers' do
|
2016-05-09 03:51:24 -04:00
|
|
|
before do
|
2016-05-04 10:04:54 -04:00
|
|
|
allow(helper).to receive(:auth_providers) { [:twitter, :github] }
|
2016-05-09 03:51:24 -04:00
|
|
|
end
|
|
|
|
|
2016-05-10 04:17:37 -04:00
|
|
|
context 'all providers are enabled to sign in' do
|
|
|
|
it 'returns all the enabled providers from settings' do
|
|
|
|
expect(helper.enabled_button_based_providers).to include('twitter', 'github')
|
|
|
|
end
|
2016-05-04 10:04:54 -04:00
|
|
|
end
|
|
|
|
|
2016-05-10 04:17:37 -04:00
|
|
|
context 'GitHub OAuth sign in is disabled from application setting' do
|
|
|
|
it "doesn't return github as provider" do
|
|
|
|
stub_application_setting(
|
|
|
|
disabled_oauth_sign_in_sources: ['github']
|
|
|
|
)
|
2016-05-04 10:04:54 -04:00
|
|
|
|
2016-05-10 04:17:37 -04:00
|
|
|
expect(helper.enabled_button_based_providers).to include('twitter')
|
2016-05-23 19:37:59 -04:00
|
|
|
expect(helper.enabled_button_based_providers).not_to include('github')
|
2016-05-10 04:17:37 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'button_based_providers_enabled?' do
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:auth_providers) { [:twitter, :github] }
|
2016-05-04 10:04:54 -04:00
|
|
|
end
|
2016-05-04 10:06:07 -04:00
|
|
|
|
2016-05-10 04:17:37 -04:00
|
|
|
context 'button based providers enabled' do
|
|
|
|
it 'returns true' do
|
|
|
|
expect(helper.button_based_providers_enabled?).to be true
|
|
|
|
end
|
2016-05-04 10:06:07 -04:00
|
|
|
end
|
|
|
|
|
2016-05-10 04:17:37 -04:00
|
|
|
context 'all the button based providers are disabled via application_setting' do
|
|
|
|
it 'returns false' do
|
|
|
|
stub_application_setting(
|
|
|
|
disabled_oauth_sign_in_sources: ['github', 'twitter']
|
|
|
|
)
|
2016-05-04 10:06:07 -04:00
|
|
|
|
2016-05-10 04:17:37 -04:00
|
|
|
expect(helper.button_based_providers_enabled?).to be false
|
|
|
|
end
|
2016-05-04 10:06:07 -04:00
|
|
|
end
|
2015-07-02 10:33:38 -04:00
|
|
|
end
|
|
|
|
end
|