diff options
author | Shinya Maeda <shinya@gitlab.com> | 2019-02-05 16:14:30 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2019-02-06 18:14:18 +0900 |
commit | e8d9df83a6f5638b3207885220b9441b7b894e46 (patch) | |
tree | d28aa89c50dd1916721d2aad562fb95249d40f75 /spec/models | |
parent | 591380a3f1bf1b5220f176f082af297831a1886e (diff) | |
download | gitlab-ce-e8d9df83a6f5638b3207885220b9441b7b894e46.tar.gz |
Inroduce Internal API for searching environment namesintroduce-environment-search-endpoint
Add changelog
Rename word to query
User hash for limit
Do not allow control limit
Rename pluck names and add more specs
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/environment_spec.rb | 70 |
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 } |