diff options
Diffstat (limited to 'spec/services/namespace_settings/update_service_spec.rb')
-rw-r--r-- | spec/services/namespace_settings/update_service_spec.rb | 73 |
1 files changed, 42 insertions, 31 deletions
diff --git a/spec/services/namespace_settings/update_service_spec.rb b/spec/services/namespace_settings/update_service_spec.rb index d94e65a903e..e0f32cb3821 100644 --- a/spec/services/namespace_settings/update_service_spec.rb +++ b/spec/services/namespace_settings/update_service_spec.rb @@ -76,50 +76,61 @@ RSpec.describe NamespaceSettings::UpdateService do end end - context "updating :prevent_sharing_groups_outside_hierarchy" do - let(:settings) { { prevent_sharing_groups_outside_hierarchy: true } } + describe 'validating settings param for root group' do + using RSpec::Parameterized::TableSyntax - context 'when user is a group owner' do - before do - group.add_owner(user) - end - - it 'changes settings' do - expect { service.execute } - .to change { group.namespace_settings.prevent_sharing_groups_outside_hierarchy } - .from(false).to(true) - end + where(:setting_key, :setting_changes_from, :setting_changes_to) do + :prevent_sharing_groups_outside_hierarchy | false | true + :new_user_signups_cap | nil | 100 end - context 'when user is not a group owner' do - before do - group.add_maintainer(user) + with_them do + let(:settings) do + { setting_key => setting_changes_to } end - it 'does not change settings' do - expect { service.execute }.not_to change { group.namespace_settings.prevent_sharing_groups_outside_hierarchy } - end + context 'when user is not a group owner' do + before do + group.add_maintainer(user) + end - it 'returns the group owner error' do - service.execute + it 'does not change settings' do + expect { service.execute }.not_to change { group.namespace_settings.public_send(setting_key) } + end + + it 'returns the group owner error' do + service.execute - expect(group.namespace_settings.errors.messages[:prevent_sharing_groups_outside_hierarchy]).to include('can only be changed by a group admin.') + expect(group.namespace_settings.errors.messages[setting_key]).to include('can only be changed by a group admin.') + end end - end - context 'with a subgroup' do - let(:subgroup) { create(:group, parent: group) } + context 'with a subgroup' do + let(:subgroup) { create(:group, parent: group) } - before do - group.add_owner(user) - end + before do + group.add_owner(user) + end + + it 'does not change settings' do + service = described_class.new(user, subgroup, settings) - it 'does not change settings' do - service = described_class.new(user, subgroup, settings) + expect { service.execute }.not_to change { group.namespace_settings.public_send(setting_key) } + + expect(subgroup.namespace_settings.errors.messages[setting_key]).to include('only available on top-level groups.') + end + end - expect { service.execute }.not_to change { group.namespace_settings.prevent_sharing_groups_outside_hierarchy } + context 'when user is a group owner' do + before do + group.add_owner(user) + end - expect(subgroup.namespace_settings.errors.messages[:prevent_sharing_groups_outside_hierarchy]).to include('only available on top-level groups.') + it 'changes settings' do + expect { service.execute } + .to change { group.namespace_settings.public_send(setting_key) } + .from(setting_changes_from).to(setting_changes_to) + end end end end |