Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion db/fixtures/01_application_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions spec/models/application_setting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
5 changes: 4 additions & 1 deletion spec/requests/graphql/mutation/users/register_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/services/application_settings_update_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down
4 changes: 4 additions & 0 deletions spec/services/users/identity/register_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/services/users/register_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
2 changes: 2 additions & 0 deletions spec/support/helpers/stub_application_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down