Commit a4f87c71 authored by Jason Goodman's avatar Jason Goodman Committed by Thong Kuah

Match Environment Spec Search Case Insensitively

parent f1883d40
...@@ -54,7 +54,7 @@ class Environment < ApplicationRecord ...@@ -54,7 +54,7 @@ class Environment < ApplicationRecord
# Search environments which have names like the given query. # Search environments which have names like the given query.
# Do not set a large limit unless you've confirmed that it works on gitlab.com scale. # Do not set a large limit unless you've confirmed that it works on gitlab.com scale.
scope :for_name_like, -> (query, limit: 5) do scope :for_name_like, -> (query, limit: 5) do
where('name LIKE ?', "#{sanitize_sql_like(query)}%").limit(limit) where(arel_table[:name].matches("#{sanitize_sql_like query}%")).limit(limit)
end end
scope :for_project, -> (project) { where(project_id: project) } scope :for_project, -> (project) { where(project_id: project) }
......
---
title: Match environment names case insensitively for feature flag spec search
merge_request: 16691
author:
type: fixed
...@@ -701,6 +701,16 @@ describe Projects::EnvironmentsController do ...@@ -701,6 +701,16 @@ describe Projects::EnvironmentsController do
expect(response).to have_gitlab_http_status(:no_content) expect(response).to have_gitlab_http_status(:no_content)
end end
end end
context 'when query matches case insensitively' do
let(:query) { 'Prod' }
it 'returns matched results' do
get :search, params: environment_params(format: :json, query: query)
expect(json_response).to contain_exactly('production')
end
end
end end
def environment_params(opts = {}) def environment_params(opts = {})
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment