BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
ee75c493
Commit
ee75c493
authored
Mar 04, 2016
by
Yorick Peterse
Committed by
Robert Speicher
Mar 11, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make Namespace.search case-insensitive
This ensures searching namespaces works exactly the same as searching for any other resource.
parent
d7d59375
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
6 deletions
+35
-6
namespace.rb
app/models/namespace.rb
+11
-1
namespace_spec.rb
spec/models/namespace_spec.rb
+24
-5
No files found.
app/models/namespace.rb
View file @
ee75c493
...
...
@@ -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
)
...
...
spec/models/namespace_spec.rb
View file @
ee75c493
...
...
@@ -41,13 +41,32 @@ describe Namespace, models: true do
it
{
expect
(
namespace
.
human_name
).
to
eq
(
namespace
.
owner_name
)
}
end
describe
:search
do
before
do
@namespace
=
create
:namespace
describe
'#search'
do
let
(
:namespace
)
{
create
(
:namespace
)
}
it
'returns namespaces with a matching name'
do
expect
(
described_class
.
search
(
namespace
.
name
)).
to
eq
([
namespace
])
end
it
'returns namespaces with a partially matching name'
do
expect
(
described_class
.
search
(
namespace
.
name
[
0
..
2
])).
to
eq
([
namespace
])
end
it
'returns namespaces with a matching name regardless of the casing'
do
expect
(
described_class
.
search
(
namespace
.
name
.
upcase
)).
to
eq
([
namespace
])
end
it
'returns namespaces with a matching path'
do
expect
(
described_class
.
search
(
namespace
.
path
)).
to
eq
([
namespace
])
end
it
{
expect
(
Namespace
.
search
(
@namespace
.
path
)).
to
eq
([
@namespace
])
}
it
{
expect
(
Namespace
.
search
(
'unknown'
)).
to
eq
([])
}
it
'returns namespaces with a partially matching path'
do
expect
(
described_class
.
search
(
namespace
.
path
[
0
..
2
])).
to
eq
([
namespace
])
end
it
'returns namespaces with a matching path regardless of the casing'
do
expect
(
described_class
.
search
(
namespace
.
path
.
upcase
)).
to
eq
([
namespace
])
end
end
describe
:move_dir
do
...
...
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