Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
ce5e831b
Commit
ce5e831b
authored
Mar 01, 2016
by
Yorick Peterse
Committed by
Robert Speicher
Mar 11, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use ILIKE/LIKE for searching groups
parent
800aa296
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
1 deletion
+37
-1
app/models/group.rb
app/models/group.rb
+11
-1
spec/models/group_spec.rb
spec/models/group_spec.rb
+26
-0
No files found.
app/models/group.rb
View file @
ce5e831b
...
@@ -33,8 +33,18 @@ class Group < Namespace
...
@@ -33,8 +33,18 @@ class Group < Namespace
after_destroy
:post_destroy_hook
after_destroy
:post_destroy_hook
class
<<
self
class
<<
self
# Searches for groups 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
)
def
search
(
query
)
where
(
"LOWER(namespaces.name) LIKE :query or LOWER(namespaces.path) LIKE :query"
,
query:
"%
#{
query
.
downcase
}
%"
)
table
=
Group
.
arel_table
pattern
=
"%
#{
query
}
%"
where
(
table
[
:name
].
matches
(
pattern
).
or
(
table
[
:path
].
matches
(
pattern
)))
end
end
def
sort
(
method
)
def
sort
(
method
)
...
...
spec/models/group_spec.rb
View file @
ce5e831b
...
@@ -103,4 +103,30 @@ describe Group, models: true do
...
@@ -103,4 +103,30 @@ describe Group, models: true do
expect
(
group
.
avatar_type
).
to
eq
([
"only images allowed"
])
expect
(
group
.
avatar_type
).
to
eq
([
"only images allowed"
])
end
end
end
end
describe
'.search'
do
it
'returns groups with a matching name'
do
expect
(
described_class
.
search
(
group
.
name
)).
to
eq
([
group
])
end
it
'returns groups with a partially matching name'
do
expect
(
described_class
.
search
(
group
.
name
[
0
..
2
])).
to
eq
([
group
])
end
it
'returns groups with a matching name regardless of the casing'
do
expect
(
described_class
.
search
(
group
.
name
.
upcase
)).
to
eq
([
group
])
end
it
'returns groups with a matching path'
do
expect
(
described_class
.
search
(
group
.
path
)).
to
eq
([
group
])
end
it
'returns groups with a partially matching path'
do
expect
(
described_class
.
search
(
group
.
path
[
0
..
2
])).
to
eq
([
group
])
end
it
'returns groups with a matching path regardless of the casing'
do
expect
(
described_class
.
search
(
group
.
path
.
upcase
)).
to
eq
([
group
])
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment