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
Tatuya Kamada
gitlab-ce
Commits
2076bdb6
Commit
2076bdb6
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 CI runners
parent
ce5e831b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
3 deletions
+45
-3
app/models/ci/runner.rb
app/models/ci/runner.rb
+17
-3
spec/models/ci/runner_spec.rb
spec/models/ci/runner_spec.rb
+28
-0
No files found.
app/models/ci/runner.rb
View file @
2076bdb6
...
...
@@ -23,7 +23,7 @@ module Ci
LAST_CONTACT_TIME
=
5
.
minutes
.
ago
AVAILABLE_SCOPES
=
[
'specific'
,
'shared'
,
'active'
,
'paused'
,
'online'
]
has_many
:builds
,
class_name:
'Ci::Build'
has_many
:runner_projects
,
dependent: :destroy
,
class_name:
'Ci::RunnerProject'
has_many
:projects
,
through: :runner_projects
,
class_name:
'::Project'
,
foreign_key: :gl_project_id
...
...
@@ -46,9 +46,23 @@ module Ci
acts_as_taggable
# Searches for runners matching the given query.
#
# This method uses ILIKE on PostgreSQL and LIKE on MySQL.
#
# This method performs a *partial* match on tokens, thus a query for "a"
# will match any runner where the token contains the letter "a". As a result
# you should *not* use this method for non-admin purposes as otherwise users
# might be able to query a list of all runners.
#
# query - The search query as a String
#
# Returns an ActiveRecord::Relation.
def
self
.
search
(
query
)
where
(
'LOWER(ci_runners.token) LIKE :query OR LOWER(ci_runners.description) like :query'
,
query:
"%
#{
query
.
try
(
:downcase
)
}
%"
)
t
=
Ci
::
Runner
.
arel_table
pattern
=
"%
#{
query
}
%"
where
(
t
[
:token
].
matches
(
pattern
).
or
(
t
[
:description
].
matches
(
pattern
)))
end
def
set_default_values
...
...
spec/models/ci/runner_spec.rb
View file @
2076bdb6
...
...
@@ -132,4 +132,32 @@ describe Ci::Runner, models: true do
expect
(
runner
.
belongs_to_one_project?
).
to
be_truthy
end
end
describe
'#search'
do
let
(
:runner
)
{
create
(
:ci_runner
,
token:
'123abc'
)
}
it
'returns runners with a matching token'
do
expect
(
described_class
.
search
(
runner
.
token
)).
to
eq
([
runner
])
end
it
'returns runners with a partially matching token'
do
expect
(
described_class
.
search
(
runner
.
token
[
0
..
2
])).
to
eq
([
runner
])
end
it
'returns runners with a matching token regardless of the casing'
do
expect
(
described_class
.
search
(
runner
.
token
.
upcase
)).
to
eq
([
runner
])
end
it
'returns runners with a matching description'
do
expect
(
described_class
.
search
(
runner
.
description
)).
to
eq
([
runner
])
end
it
'returns runners with a partially matching description'
do
expect
(
described_class
.
search
(
runner
.
description
[
0
..
2
])).
to
eq
([
runner
])
end
it
'returns runners with a matching description regardless of the casing'
do
expect
(
described_class
.
search
(
runner
.
description
.
upcase
)).
to
eq
([
runner
])
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