Commit bed44b61 authored by Thong Kuah's avatar Thong Kuah

Merge branch 'case-insensitive-env-search' into 'master'

Match Environment Spec Search Case Insensitively

Closes #12692

See merge request gitlab-org/gitlab!16691
parents f1883d40 a4f87c71
......@@ -54,7 +54,7 @@ class Environment < ApplicationRecord
# 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.
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
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
expect(response).to have_gitlab_http_status(:no_content)
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
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