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
02f835c1
Commit
02f835c1
authored
Oct 24, 2016
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve readability and add specs for label filtering
parent
ce256c28
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
10 deletions
+21
-10
app/finders/labels_finder.rb
app/finders/labels_finder.rb
+5
-8
spec/finders/labels_finder_spec.rb
spec/finders/labels_finder_spec.rb
+16
-2
No files found.
app/finders/labels_finder.rb
View file @
02f835c1
...
...
@@ -35,13 +35,10 @@ class LabelsFinder < UnionFinder
end
def
with_title
(
items
)
if
title
return
items
if
title
.
nil?
return
items
.
none
if
title
.
blank?
items
.
where
(
title:
title
)
elsif
params
[
:title
]
||
params
[
:name
]
# empty input, should match nothing
items
.
none
else
# not filtering
items
end
end
def
group_id
...
...
@@ -57,7 +54,7 @@ class LabelsFinder < UnionFinder
end
def
title
params
[
:title
]
.
presence
||
params
[
:name
].
presence
params
[
:title
]
||
params
[
:name
]
end
def
project
...
...
spec/finders/labels_finder_spec.rb
View file @
02f835c1
...
...
@@ -38,6 +38,14 @@ describe LabelsFinder do
expect
(
finder
.
execute
).
to
eq
[
group_label_2
,
group_label_3
,
project_label_1
,
group_label_1
,
project_label_2
,
project_label_4
]
end
it
'returns labels available if nil title is supplied'
do
group_2
.
add_developer
(
user
)
# params[:title] will return `nil` regardless whether it is specified
finder
=
described_class
.
new
(
user
,
title:
nil
)
expect
(
finder
.
execute
).
to
eq
[
group_label_2
,
group_label_3
,
project_label_1
,
group_label_1
,
project_label_2
,
project_label_4
]
end
end
context
'filtering by group_id'
do
...
...
@@ -71,13 +79,19 @@ describe LabelsFinder do
expect
(
finder
.
execute
).
to
eq
[
group_label_2
]
end
it
'returns no labels if empty title
s are
supplied'
do
it
'returns no labels if empty title
is
supplied'
do
finder
=
described_class
.
new
(
user
,
title:
[])
expect
(
finder
.
execute
).
to
be_empty
end
it
'returns no labels if empty names are supplied'
do
it
'returns no labels if blank title is supplied'
do
finder
=
described_class
.
new
(
user
,
title:
''
)
expect
(
finder
.
execute
).
to
be_empty
end
it
'returns no labels if empty name is supplied'
do
finder
=
described_class
.
new
(
user
,
name:
[])
expect
(
finder
.
execute
).
to
be_empty
...
...
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