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
Kazuhiko Shiozaki
gitlab-ce
Commits
2cf7f3f4
Commit
2cf7f3f4
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 milestones
parent
87e7c3e1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
2 deletions
+41
-2
app/models/milestone.rb
app/models/milestone.rb
+11
-2
spec/models/milestone_spec.rb
spec/models/milestone_spec.rb
+30
-0
No files found.
app/models/milestone.rb
View file @
2cf7f3f4
...
@@ -58,9 +58,18 @@ class Milestone < ActiveRecord::Base
...
@@ -58,9 +58,18 @@ class Milestone < ActiveRecord::Base
alias_attribute
:name
,
:title
alias_attribute
:name
,
:title
class
<<
self
class
<<
self
# Searches for milestones 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
)
query
=
"%
#{
query
}
%"
t
=
arel_table
where
(
"title like ? or description like ?"
,
query
,
query
)
pattern
=
"%
#{
query
}
%"
where
(
t
[
:title
].
matches
(
pattern
).
or
(
t
[
:description
].
matches
(
pattern
)))
end
end
end
end
...
...
spec/models/milestone_spec.rb
View file @
2cf7f3f4
...
@@ -181,4 +181,34 @@ describe Milestone, models: true do
...
@@ -181,4 +181,34 @@ describe Milestone, models: true do
expect
(
issue4
.
position
).
to
eq
(
42
)
expect
(
issue4
.
position
).
to
eq
(
42
)
end
end
end
end
describe
'.search'
do
let
(
:milestone
)
{
create
(
:milestone
,
title:
'foo'
,
description:
'bar'
)
}
it
'returns milestones with a matching title'
do
expect
(
described_class
.
search
(
milestone
.
title
)).
to
eq
([
milestone
])
end
it
'returns milestones with a partially matching title'
do
expect
(
described_class
.
search
(
milestone
.
title
[
0
..
2
])).
to
eq
([
milestone
])
end
it
'returns milestones with a matching title regardless of the casing'
do
expect
(
described_class
.
search
(
milestone
.
title
.
upcase
)).
to
eq
([
milestone
])
end
it
'returns milestones with a matching description'
do
expect
(
described_class
.
search
(
milestone
.
description
)).
to
eq
([
milestone
])
end
it
'returns milestones with a partially matching description'
do
expect
(
described_class
.
search
(
milestone
.
description
[
0
..
2
])).
to
eq
([
milestone
])
end
it
'returns milestones with a matching description regardless of the casing'
do
expect
(
described_class
.
search
(
milestone
.
description
.
upcase
)).
to
eq
([
milestone
])
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