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
Léo-Paul Géneau
gitlab-ce
Commits
508b6b46
Commit
508b6b46
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 notes
parent
1f5284e5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
4 deletions
+20
-4
app/models/note.rb
app/models/note.rb
+11
-1
spec/models/note_spec.rb
spec/models/note_spec.rb
+9
-3
No files found.
app/models/note.rb
View file @
508b6b46
...
@@ -105,8 +105,18 @@ class Note < ActiveRecord::Base
...
@@ -105,8 +105,18 @@ class Note < ActiveRecord::Base
[
:discussion
,
type
.
try
(
:underscore
),
id
,
line_code
].
join
(
"-"
).
to_sym
[
:discussion
,
type
.
try
(
:underscore
),
id
,
line_code
].
join
(
"-"
).
to_sym
end
end
# Searches for notes 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(note) like :query"
,
query:
"%
#{
query
.
downcase
}
%"
)
table
=
Note
.
arel_table
pattern
=
"%
#{
query
}
%"
where
(
table
[
:note
].
matches
(
pattern
))
end
end
def
grouped_awards
def
grouped_awards
...
...
spec/models/note_spec.rb
View file @
508b6b46
...
@@ -140,10 +140,16 @@ describe Note, models: true do
...
@@ -140,10 +140,16 @@ describe Note, models: true do
end
end
end
end
describe
:search
do
describe
'.search'
do
let
!
(
:note
)
{
create
(
:note
,
note:
"WoW"
)
}
let
(
:note
)
{
create
(
:note
,
note:
'WoW'
)
}
it
{
expect
(
Note
.
search
(
'wow'
)).
to
include
(
note
)
}
it
'returns notes with matching content'
do
expect
(
described_class
.
search
(
note
.
note
)).
to
eq
([
note
])
end
it
'returns notes with matching content regardless of the casing'
do
expect
(
described_class
.
search
(
'WOW'
)).
to
eq
([
note
])
end
end
end
describe
:grouped_awards
do
describe
:grouped_awards
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