summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2019-02-06 10:39:23 +0000
committerSean McGivern <sean@gitlab.com>2019-02-06 10:39:23 +0000
commit561ce0c09516cf62125a0832ff3656a1ed93470f (patch)
treef84194c4ea185e94dd6a58d3d5c1226d7e05fcec /spec/models
parent880afe2246440739fa71fc80d6446679074fc325 (diff)
parente8d9df83a6f5638b3207885220b9441b7b894e46 (diff)
downloadgitlab-ce-561ce0c09516cf62125a0832ff3656a1ed93470f.tar.gz
Merge branch 'introduce-environment-search-endpoint' into 'master'
Introduce Internal API for searching environment names See merge request gitlab-org/gitlab-ce!24923
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/environment_spec.rb70
1 files changed, 70 insertions, 0 deletions
diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb
index 9a3f1f1c5a1..2d554326f05 100644
--- a/spec/models/environment_spec.rb
+++ b/spec/models/environment_spec.rb
@@ -41,6 +41,76 @@ describe Environment do
end
end
+ describe '.for_name_like' do
+ subject { project.environments.for_name_like(query, limit: limit) }
+
+ let!(:environment) { create(:environment, name: 'production', project: project) }
+ let(:query) { 'pro' }
+ let(:limit) { 5 }
+
+ it 'returns a found name' do
+ is_expected.to include(environment)
+ end
+
+ context 'when query is production' do
+ let(:query) { 'production' }
+
+ it 'returns a found name' do
+ is_expected.to include(environment)
+ end
+ end
+
+ context 'when query is productionA' do
+ let(:query) { 'productionA' }
+
+ it 'returns empty array' do
+ is_expected.to be_empty
+ end
+ end
+
+ context 'when query is empty' do
+ let(:query) { '' }
+
+ it 'returns a found name' do
+ is_expected.to include(environment)
+ end
+ end
+
+ context 'when query is nil' do
+ let(:query) { }
+
+ it 'raises an error' do
+ expect { subject }.to raise_error(NoMethodError)
+ end
+ end
+
+ context 'when query is partially matched in the middle of environment name' do
+ let(:query) { 'duction' }
+
+ it 'returns empty array' do
+ is_expected.to be_empty
+ end
+ end
+
+ context 'when query contains a wildcard character' do
+ let(:query) { 'produc%' }
+
+ it 'prevents wildcard injection' do
+ is_expected.to be_empty
+ end
+ end
+ end
+
+ describe '.pluck_names' do
+ subject { described_class.pluck_names }
+
+ let!(:environment) { create(:environment, name: 'production', project: project) }
+
+ it 'plucks names' do
+ is_expected.to eq(%w[production])
+ end
+ end
+
describe '#expire_etag_cache' do
let(:store) { Gitlab::EtagCaching::Store.new }