This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/spec/lib/validators/enable_sso_validator_spec.rb
David Taylor c9dab6fd08
DEV: Automatically require 'rails_helper' in all specs (#16077)
It's very easy to forget to add `require 'rails_helper'` at the top of every core/plugin spec file, and omissions can cause some very confusing/sporadic errors.

By setting this flag in `.rspec`, we can remove the need for `require 'rails_helper'` entirely.
2022-03-01 17:50:50 +00:00

67 lines
1.6 KiB
Ruby

# frozen_string_literal: true
RSpec.describe EnableSsoValidator do
subject { described_class.new }
describe '#valid_value?' do
describe "when 'sso url' is empty" do
before do
SiteSetting.discourse_connect_url = ""
end
describe 'when val is false' do
it 'should be valid' do
expect(subject.valid_value?('f')).to eq(true)
end
end
describe 'when value is true' do
it 'should not be valid' do
expect(subject.valid_value?('t')).to eq(false)
expect(subject.error_message).to eq(I18n.t(
'site_settings.errors.discourse_connect_url_is_empty'
))
end
end
end
describe "when invite_only is set" do
before do
SiteSetting.invite_only = true
SiteSetting.discourse_connect_url = 'https://example.com/sso'
end
it 'allows a false value' do
expect(subject.valid_value?('f')).to eq(true)
end
it "doesn't allow true" do
expect(subject.valid_value?('t')).to eq(false)
expect(subject.error_message).to eq(I18n.t(
'site_settings.errors.discourse_connect_invite_only'
))
end
end
describe "when 'sso url' is present" do
before do
SiteSetting.discourse_connect_url = "https://www.example.com/sso"
end
describe 'when value is false' do
it 'should be valid' do
expect(subject.valid_value?('f')).to eq(true)
end
end
describe 'when value is true' do
it 'should be valid' do
expect(subject.valid_value?('t')).to eq(true)
end
end
end
end
end