diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /spec/models/environment_spec.rb | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) | |
download | gitlab-ce-9f46488805e86b1bc341ea1620b866016c2ce5ed.tar.gz |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/models/environment_spec.rb')
-rw-r--r-- | spec/models/environment_spec.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index d0305d878e3..c0b2a4ae984 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -1311,4 +1311,25 @@ describe Environment, :use_clean_rails_memory_store_caching do expect { environment.destroy }.to change { project.commit(deployment.ref_path) }.to(nil) end end + + describe '.count_by_state' do + context 'when environments are not empty' do + let!(:environment1) { create(:environment, project: project, state: 'stopped') } + let!(:environment2) { create(:environment, project: project, state: 'available') } + let!(:environment3) { create(:environment, project: project, state: 'stopped') } + + it 'returns the environments count grouped by state' do + expect(project.environments.count_by_state).to eq({ stopped: 2, available: 1 }) + end + + it 'returns the environments count grouped by state with zero value' do + environment2.update(state: 'stopped') + expect(project.environments.count_by_state).to eq({ stopped: 3, available: 0 }) + end + end + + it 'returns zero state counts when environments are empty' do + expect(project.environments.count_by_state).to eq({ stopped: 0, available: 0 }) + end + end end |