Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-03-04 14:06:25 +0300
committerRobert Speicher <rspeicher@gmail.com>2016-03-11 23:25:24 +0300
commitee75c49313127f53fe60a0701f40024b897a15e8 (patch)
tree048894c69e46e0a2ee4134aade7aed6565a667d7 /app/models/namespace.rb
parentd7d5937531350283f6cbd68dead5750227e6d962 (diff)
Make Namespace.search case-insensitive
This ensures searching namespaces works exactly the same as searching for any other resource.
Diffstat (limited to 'app/models/namespace.rb')
-rw-r--r--app/models/namespace.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb
index bdb33f37495..55842df1e2d 100644
--- a/app/models/namespace.rb
+++ b/app/models/namespace.rb
@@ -52,8 +52,18 @@ class Namespace < ActiveRecord::Base
find_by("lower(path) = :path OR lower(name) = :path", path: path.downcase)
end
+ # Searches for namespaces matching the given query.
+ #
+ # This method uses ILIKE on PostgreSQL and LIKE on MySQL.
+ #
+ # query - The search query as a String
+ #
+ # Returns an ActiveRecord::Relation
def search(query)
- where("name LIKE :query OR path LIKE :query", query: "%#{query}%")
+ t = arel_table
+ pattern = "%#{query}%"
+
+ where(t[:name].matches(pattern).or(t[:path].matches(pattern)))
end
def clean_path(path)