* Split Settings::Authentication from SiteConfig * Move specs * Sort fields * Update settings usages * Update recaptcha usages * Add data update script * Update spec * Rename SiteConfigParams concern * Fixes, new route, new controller * Controller and service refactoring * More controller and service updates * Spec updates * More spec fixes * Move file * Fix FeedbackMessagesController * Update admin/configs_spec * Fix remaining specs in admin/configs_spec * Fix configs API * Formatting * Clean up old service object * Various fixes * Update DUS * Add model argument to admin_config_label * Fix key name * Fix specs * Add distinct request caches for settings classes * Fix e2e tests * Fix remaining system spec * Make DUS idempotent * Move routes block * Cleanup * Switch to ActiveSupport::CurrentAttributes * Pinned rails-settings-cached * Update e2e test * Update lib/data_update_scripts/20210316091354_move_authentication_settings.rb Co-authored-by: rhymes <rhymes@hey.com> * Add guard to DUS * Temporarily re-add two SiteConfig fields * Fix config show view Co-authored-by: rhymes <rhymes@hey.com>
59 lines
1.8 KiB
Ruby
59 lines
1.8 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe Authentication::Providers, type: :service do
|
|
describe ".get!" do
|
|
it "raises an exception if a provider is not available" do
|
|
expect do
|
|
described_class.get!(:unknown)
|
|
end.to raise_error(Authentication::Errors::ProviderNotFound)
|
|
end
|
|
|
|
it "raises an exception if a provider is available but not enabled" do
|
|
allow(Settings::Authentication).to receive(:providers).and_return(%w[github])
|
|
|
|
expect do
|
|
described_class.get!(:twitter)
|
|
end.to raise_error(Authentication::Errors::ProviderNotEnabled)
|
|
end
|
|
|
|
it "loads the correct provider class" do
|
|
allow(Settings::Authentication).to receive(:providers).and_return(described_class.available)
|
|
|
|
is_subclass_of = (
|
|
described_class.get!(:twitter) < Authentication::Providers::Provider
|
|
)
|
|
expect(is_subclass_of).to be(true)
|
|
end
|
|
end
|
|
|
|
describe ".available" do
|
|
it "lists the available providers" do
|
|
available_providers = %i[apple facebook github twitter]
|
|
expect(described_class.available).to eq(available_providers)
|
|
end
|
|
end
|
|
|
|
describe ".enabled" do
|
|
context "when one of the available providers is disabled" do
|
|
it "only lists those that remain enabled" do
|
|
allow(Settings::Authentication).to receive(:providers).and_return(%w[github])
|
|
|
|
expect(described_class.enabled).to eq(%i[github])
|
|
end
|
|
end
|
|
end
|
|
|
|
describe ".enabled?" do
|
|
it "returns true if a provider is enabled" do
|
|
allow(Settings::Authentication).to receive(:providers).and_return(%w[github])
|
|
|
|
expect(described_class.enabled?(:github)).to be(true)
|
|
end
|
|
|
|
it "returns false if a provider is not enabled" do
|
|
allow(Settings::Authentication).to receive(:providers).and_return(%w[twitter])
|
|
|
|
expect(described_class.enabled?(:github)).to be(false)
|
|
end
|
|
end
|
|
end
|