blob: d94e65a903e613130987ba331dc2cbb4541f0160 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe NamespaceSettings::UpdateService do
let(:user) { create(:user) }
let(:group) { create(:group) }
let(:settings) { {} }
subject(:service) { described_class.new(user, group, settings) }
describe "#execute" do
context "group has no namespace_settings" do
before do
group.namespace_settings.destroy!
end
it "builds out a new namespace_settings record" do
expect do
service.execute
end.to change { NamespaceSetting.count }.by(1)
end
end
context "group has a namespace_settings" do
before do
service.execute
end
it "doesn't create a new namespace_setting record" do
expect do
service.execute
end.not_to change { NamespaceSetting.count }
end
end
context "updating :default_branch_name" do
let(:example_branch_name) { "example_branch_name" }
let(:settings) { { default_branch_name: example_branch_name } }
it "changes settings" do
expect { service.execute }
.to change { group.namespace_settings.default_branch_name }
.from(nil).to(example_branch_name)
end
end
context "updating :resource_access_token_creation_allowed" do
let(:settings) { { resource_access_token_creation_allowed: false } }
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.resource_access_token_creation_allowed }
.from(true).to(false)
end
end
context 'when user is not a group owner' do
before do
group.add_developer(user)
end
it "does not change settings" do
expect { service.execute }.not_to change { group.namespace_settings.resource_access_token_creation_allowed }
end
it 'returns the group owner error' do
service.execute
expect(group.namespace_settings.errors.messages[:resource_access_token_creation_allowed]).to include('can only be changed by a group admin.')
end
end
end
context "updating :prevent_sharing_groups_outside_hierarchy" do
let(:settings) { { prevent_sharing_groups_outside_hierarchy: true } }
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
end
context 'when user is not a group owner' do
before do
group.add_maintainer(user)
end
it 'does not change settings' do
expect { service.execute }.not_to change { group.namespace_settings.prevent_sharing_groups_outside_hierarchy }
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.')
end
end
context 'with a subgroup' do
let(:subgroup) { create(:group, parent: group) }
before do
group.add_owner(user)
end
it 'does not change settings' do
service = described_class.new(user, subgroup, settings)
expect { service.execute }.not_to change { group.namespace_settings.prevent_sharing_groups_outside_hierarchy }
expect(subgroup.namespace_settings.errors.messages[:prevent_sharing_groups_outside_hierarchy]).to include('only available on top-level groups.')
end
end
end
end
end
|