Commit b81b8f3a authored by Thong Kuah's avatar Thong Kuah

Unique environment scope for group clusters

We allow setting of environment scopes in EE. Add validations for group
clusters.
parent 51679f61
......@@ -15,6 +15,11 @@ module EE
return false
end
if group && group.clusters.where(environment_scope: environment_scope).where.not(id: self.id).exists?
errors.add(:base, 'cannot add duplicated environment scope')
return false
end
true
end
end
......
......@@ -7,6 +7,7 @@ describe Clusters::Cluster do
subject { cluster.valid? }
context 'when validates unique_environment_scope' do
context 'for a project cluster' do
let(:project) { create(:project) }
before do
......@@ -32,5 +33,32 @@ describe Clusters::Cluster do
it { is_expected.to be_truthy }
end
end
context 'for a group cluster' do
let(:group) { create(:group) }
before do
create(:cluster, cluster_type: :group_type, groups: [group], environment_scope: 'product/*')
end
context 'when identical environment scope exists in group' do
let(:cluster) { build(:cluster, cluster_type: :group_type, groups: [group], environment_scope: 'product/*') }
it { is_expected.to be_falsey }
end
context 'when identical environment scope does not exist in group' do
let(:cluster) { build(:cluster, cluster_type: :group_type, groups: [group], environment_scope: '*') }
it { is_expected.to be_truthy }
end
context 'when identical environment scope exists in different group' do
let(:cluster) { build(:cluster, :group, environment_scope: 'product/*') }
it { is_expected.to be_truthy }
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment