diff --git a/db/fixtures/01_application_settings.rb b/db/fixtures/01_application_settings.rb index 11c5213c0..1ea57ad5e 100644 --- a/db/fixtures/01_application_settings.rb +++ b/db/fixtures/01_application_settings.rb @@ -2,7 +2,7 @@ ApplicationSetting.seed_once :setting do |s| s.setting = :user_registration_enabled - s.value = true + s.value = false end ApplicationSetting.seed_once :setting do |s| diff --git a/extensions/ee/spec/services/ee/users/identity/register_service_spec.rb b/extensions/ee/spec/services/ee/users/identity/register_service_spec.rb index 3cfe0a00c..28bb0f596 100644 --- a/extensions/ee/spec/services/ee/users/identity/register_service_spec.rb +++ b/extensions/ee/spec/services/ee/users/identity/register_service_spec.rb @@ -40,6 +40,7 @@ def setup_identity_provider(identity) context 'when user limit of license is reached' do before do + stub_application_settings(user_registration_enabled: true) create(:license, restrictions: { user_count: 0 }) end diff --git a/extensions/ee/spec/services/ee/users/register_service_spec.rb b/extensions/ee/spec/services/ee/users/register_service_spec.rb index bfb74086b..4ace1378d 100644 --- a/extensions/ee/spec/services/ee/users/register_service_spec.rb +++ b/extensions/ee/spec/services/ee/users/register_service_spec.rb @@ -11,6 +11,7 @@ context 'when user limit of license is reached' do before do + stub_application_settings(user_registration_enabled: true) create(:license, restrictions: { user_count: 0 }) end diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index 596839ec7..f511694b9 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -191,6 +191,16 @@ describe '.current' do it { expect(described_class.current.keys).to eq(described_class::SETTINGS.keys) } + it 'defaults user registration to disabled' do + described_class.delete_all + SeedFu.seed(SeedFu.fixture_paths, /01_application_settings/) + + expect(described_class.current[:user_registration_enabled]).to be false + ensure + described_class.delete_all + SeedFu.seed(SeedFu.fixture_paths, /01_application_settings/) + end + it 'raises if settings are missing', :recreating_settings do described_class.first.delete diff --git a/spec/requests/graphql/mutation/users/identity/register_spec.rb b/spec/requests/graphql/mutation/users/identity/register_spec.rb index 8acfa9ae9..33a5559f2 100644 --- a/spec/requests/graphql/mutation/users/identity/register_spec.rb +++ b/spec/requests/graphql/mutation/users/identity/register_spec.rb @@ -44,6 +44,8 @@ def setup_identity_provider(identity) end before do + stub_application_settings(user_registration_enabled: true) + setup_identity_provider Code0::Identities::Identity.new(:google, 'identifier', 'username', 'test@code0.tech', 'firstname', 'lastname') diff --git a/spec/requests/graphql/mutation/users/register_spec.rb b/spec/requests/graphql/mutation/users/register_spec.rb index a15454616..2d3fc70e0 100644 --- a/spec/requests/graphql/mutation/users/register_spec.rb +++ b/spec/requests/graphql/mutation/users/register_spec.rb @@ -36,7 +36,10 @@ let(:variables) { { input: input } } - before { post_graphql mutation, variables: variables } + before do + stub_application_settings(user_registration_enabled: true) + post_graphql mutation, variables: variables + end it 'creates the user' do expect(graphql_data_at(:users_register, :user_session, :user, :id)).to be_present diff --git a/spec/services/application_settings_update_service_spec.rb b/spec/services/application_settings_update_service_spec.rb index 3d92501aa..4375877a9 100644 --- a/spec/services/application_settings_update_service_spec.rb +++ b/spec/services/application_settings_update_service_spec.rb @@ -41,6 +41,10 @@ let(:current_user) { create(:user, :admin) } let(:params) { { user_registration_enabled: false } } + before do + ApplicationSetting.user_registration_enabled.update!(value: true) + end + it { is_expected.to be_success } it { expect(service_response.payload).to include(user_registration_enabled: false) } diff --git a/spec/services/users/identity/register_service_spec.rb b/spec/services/users/identity/register_service_spec.rb index e095c0d6b..29fecf66a 100644 --- a/spec/services/users/identity/register_service_spec.rb +++ b/spec/services/users/identity/register_service_spec.rb @@ -15,6 +15,10 @@ def setup_identity_provider(identity) allow(provider).to receive(:load_identity).and_return identity end + before do + stub_application_settings(user_registration_enabled: true) + end + context 'when user is valid' do let(:provider_id) do :google diff --git a/spec/services/users/register_service_spec.rb b/spec/services/users/register_service_spec.rb index 9e5e66f35..cab636044 100644 --- a/spec/services/users/register_service_spec.rb +++ b/spec/services/users/register_service_spec.rb @@ -5,6 +5,10 @@ RSpec.describe Users::RegisterService do subject(:service_response) { described_class.new(username, email, password).execute } + before do + stub_application_settings(user_registration_enabled: true) + end + context 'when user is valid' do let(:username) { generate(:username) } let(:email) { generate(:email) } diff --git a/spec/support/helpers/stub_application_settings.rb b/spec/support/helpers/stub_application_settings.rb index d4ac12627..84e2b7cca 100644 --- a/spec/support/helpers/stub_application_settings.rb +++ b/spec/support/helpers/stub_application_settings.rb @@ -4,6 +4,8 @@ module StubApplicationSettings def stub_application_settings(settings) current_settings = ApplicationSetting.current + allow(current_settings).to receive(:[]).and_call_original + settings.each do |key, value| allow(current_settings).to receive(:[]).with(key.to_sym).and_return(value) allow(current_settings).to receive(:[]).with(key.to_s).and_return(value)