summaryrefslogtreecommitdiff
path: root/spec/finders
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-08 00:09:30 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-08 00:09:30 +0000
commit060c842402c00f830a810702600cbe39dfa6cf62 (patch)
tree743bd65ac0c1d4d6518ae8cdd4af5718ec7fb890 /spec/finders
parent6867eff1f997a881cd3ea64109f7ba2d4b42fde4 (diff)
downloadgitlab-ce-060c842402c00f830a810702600cbe39dfa6cf62.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/finders')
-rw-r--r--spec/finders/environments_finder_spec.rb63
1 files changed, 56 insertions, 7 deletions
diff --git a/spec/finders/environments_finder_spec.rb b/spec/finders/environments_finder_spec.rb
index 850d160506c..66e404f5236 100644
--- a/spec/finders/environments_finder_spec.rb
+++ b/spec/finders/environments_finder_spec.rb
@@ -3,15 +3,15 @@
require 'spec_helper'
describe EnvironmentsFinder do
- describe '#execute' do
- let(:project) { create(:project, :repository) }
- let(:user) { project.creator }
- let(:environment) { create(:environment, project: project) }
+ let(:project) { create(:project, :repository) }
+ let(:user) { project.creator }
+ let(:environment) { create(:environment, :available, project: project) }
- before do
- project.add_maintainer(user)
- end
+ before do
+ project.add_maintainer(user)
+ end
+ describe '#execute' do
context 'tagged deployment' do
let(:environment_two) { create(:environment, project: project) }
# Environments need to include commits, so rewind two commits to fit
@@ -124,4 +124,53 @@ describe EnvironmentsFinder do
end
end
end
+
+ describe '#find' do
+ context 'with states parameter' do
+ let(:stopped_environment) { create(:environment, :stopped, project: project) }
+
+ it 'returns environments with the requested state' do
+ result = described_class.new(project, user, states: 'available').find
+
+ expect(result).to contain_exactly(environment)
+ end
+
+ it 'returns environments with any of the requested states' do
+ result = described_class.new(project, user, states: %w(available stopped)).find
+
+ expect(result).to contain_exactly(environment, stopped_environment)
+ end
+
+ it 'raises exception when requested state is invalid' do
+ expect { described_class.new(project, user, states: %w(invalid stopped)).find }.to(
+ raise_error(described_class::InvalidStatesError, 'Requested states are invalid')
+ )
+ end
+
+ context 'works with symbols' do
+ it 'returns environments with the requested state' do
+ result = described_class.new(project, user, states: :available).find
+
+ expect(result).to contain_exactly(environment)
+ end
+
+ it 'returns environments with any of the requested states' do
+ result = described_class.new(project, user, states: [:available, :stopped]).find
+
+ expect(result).to contain_exactly(environment, stopped_environment)
+ end
+ end
+ end
+
+ context 'with search and states' do
+ let(:environment2) { create(:environment, :stopped, name: 'test2', project: project) }
+ let(:environment3) { create(:environment, :available, name: 'test3', project: project) }
+
+ it 'searches environments by name and state' do
+ result = described_class.new(project, user, search: 'test', states: :available).find
+
+ expect(result).to contain_exactly(environment3)
+ end
+ end
+ end
end