diff options
Diffstat (limited to 'spec/models/clusters/cluster_spec.rb')
-rw-r--r-- | spec/models/clusters/cluster_spec.rb | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/spec/models/clusters/cluster_spec.rb b/spec/models/clusters/cluster_spec.rb index 0f476e68698..4807957152c 100644 --- a/spec/models/clusters/cluster_spec.rb +++ b/spec/models/clusters/cluster_spec.rb @@ -10,6 +10,7 @@ RSpec.describe Clusters::Cluster, :use_clean_rails_memory_store_caching do subject { build(:cluster) } + it { is_expected.to include_module(HasEnvironmentScope) } it { is_expected.to belong_to(:user) } it { is_expected.to belong_to(:management_project).class_name('::Project') } it { is_expected.to have_many(:cluster_projects) } @@ -289,6 +290,79 @@ RSpec.describe Clusters::Cluster, :use_clean_rails_memory_store_caching do describe 'validations' do subject { cluster.valid? } + context 'when validates unique_environment_scope' do + context 'for a project cluster' do + let(:project) { create(:project) } + + before do + create(:cluster, projects: [project], environment_scope: 'product/*') + end + + context 'when identical environment scope exists in project' do + let(:cluster) { build(:cluster, projects: [project], environment_scope: 'product/*') } + + it { is_expected.to be_falsey } + end + + context 'when identical environment scope does not exist in project' do + let(:cluster) { build(:cluster, projects: [project], environment_scope: '*') } + + it { is_expected.to be_truthy } + end + + context 'when identical environment scope exists in different project' do + let(:project2) { create(:project) } + let(:cluster) { build(:cluster, projects: [project2], environment_scope: 'product/*') } + + 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 + + context 'for an instance cluster' do + before do + create(:cluster, :instance, environment_scope: 'product/*') + end + + context 'identical environment scope exists' do + let(:cluster) { build(:cluster, :instance, environment_scope: 'product/*') } + + it { is_expected.to be_falsey } + end + + context 'identical environment scope does not exist' do + let(:cluster) { build(:cluster, :instance, environment_scope: '*') } + + it { is_expected.to be_truthy } + end + end + end + context 'when validates name' do context 'when provided by user' do let!(:cluster) { build(:cluster, :provided_by_user, name: name) } |