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
97b69862
Commit
97b69862
authored
Aug 31, 2016
by
tiagonbotelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add specs for tags finder
parent
6c9c33f4
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
115 additions
and
3 deletions
+115
-3
app/controllers/projects/tags_controller.rb
app/controllers/projects/tags_controller.rb
+4
-1
app/finders/tags_finder.rb
app/finders/tags_finder.rb
+29
-0
app/views/projects/tags/index.html.haml
app/views/projects/tags/index.html.haml
+3
-2
spec/finders/tags_finder_spec.rb
spec/finders/tags_finder_spec.rb
+79
-0
No files found.
app/controllers/projects/tags_controller.rb
View file @
97b69862
class
Projects::TagsController
<
Projects
::
ApplicationController
include
SortingHelper
# Authorize
before_action
:require_non_empty_project
before_action
:authorize_download_code!
...
...
@@ -7,7 +8,9 @@ class Projects::TagsController < Projects::ApplicationController
before_action
:authorize_admin_project!
,
only:
[
:destroy
]
def
index
@sort
=
params
[
:sort
]
||
'name'
params
[
:sort
]
=
params
[
:sort
].
presence
||
'name'
@sort
=
params
[
:sort
]
@tags
=
TagsFinder
.
new
(
@repository
,
params
).
execute
@tags
=
Kaminari
.
paginate_array
(
@tags
).
page
(
params
[
:page
])
...
...
app/finders/tags_finder.rb
0 → 100644
View file @
97b69862
class
TagsFinder
def
initialize
(
repository
,
params
)
@repository
=
repository
@params
=
params
end
def
execute
tags
=
@repository
.
tags_sorted_by
(
sort
)
filter_by_name
(
tags
)
end
private
def
sort
@params
[
:sort
].
presence
end
def
search
@params
[
:search
].
presence
end
def
filter_by_name
(
tags
)
if
search
tags
.
select
{
|
tag
|
tag
.
name
.
include?
(
search
)
}
else
tags
end
end
end
app/views/projects/tags/index.html.haml
View file @
97b69862
...
...
@@ -12,7 +12,8 @@
=
search_field_tag
:search
,
params
[
:search
],
{
placeholder:
'Filter by tag name'
,
id:
'tag-search'
,
class:
'form-control search-text-input input-short'
,
spellcheck:
false
}
.dropdown.inline
%button
.dropdown-toggle.btn
{
type:
'button'
,
data:
{
toggle:
'dropdown'
}
}
%span
.light
=
@sort
.
humanize
%span
.light
=
@sort
.
humanize
%b
.caret
%ul
.dropdown-menu.dropdown-menu-align-right
%li
...
...
@@ -22,7 +23,7 @@
=
sort_title_recently_updated
=
link_to
filter_tags_path
(
sort:
sort_value_oldest_updated
)
do
=
sort_title_oldest_updated
-
if
can?
current_user
,
:push_code
,
@project
-
if
can?
(
current_user
,
:push_code
,
@project
)
=
link_to
new_namespace_project_tag_path
(
@project
.
namespace
,
@project
),
class:
'btn btn-create new-tag-btn'
do
New tag
...
...
spec/finders/tags_finder_spec.rb
0 → 100644
View file @
97b69862
require
'spec_helper'
describe
TagsFinder
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:repository
)
{
project
.
repository
}
describe
'#execute'
do
context
'sort only'
do
it
'sorts by name'
do
tags_finder
=
described_class
.
new
(
repository
,
{})
result
=
tags_finder
.
execute
expect
(
result
.
first
.
name
).
to
eq
(
"v1.0.0"
)
end
it
'sorts by recently_updated'
do
tags_finder
=
described_class
.
new
(
repository
,
{
sort:
'updated_desc'
})
result
=
tags_finder
.
execute
recently_updated_tag
=
repository
.
tags
.
max
do
|
a
,
b
|
repository
.
commit
(
a
.
target
).
committed_date
<=>
repository
.
commit
(
b
.
target
).
committed_date
end
expect
(
result
.
first
.
name
).
to
eq
(
recently_updated_tag
.
name
)
end
it
'sorts by last_updated'
do
tags_finder
=
described_class
.
new
(
repository
,
{
sort:
'updated_asc'
})
result
=
tags_finder
.
execute
expect
(
result
.
first
.
name
).
to
eq
(
'v1.0.0'
)
end
end
context
'filter only'
do
it
'filters tags by name'
do
tags_finder
=
described_class
.
new
(
repository
,
{
search:
'1.0.0'
})
result
=
tags_finder
.
execute
expect
(
result
.
first
.
name
).
to
eq
(
'v1.0.0'
)
expect
(
result
.
count
).
to
eq
(
1
)
end
it
'does not find any tags with that name'
do
tags_finder
=
described_class
.
new
(
repository
,
{
search:
'hey'
})
result
=
tags_finder
.
execute
expect
(
result
.
count
).
to
eq
(
0
)
end
end
context
'filter and sort'
do
it
'filters tags by name and sorts by recently_updated'
do
params
=
{
sort:
'updated_desc'
,
search:
'v1'
}
tags_finder
=
described_class
.
new
(
repository
,
params
)
result
=
tags_finder
.
execute
expect
(
result
.
first
.
name
).
to
eq
(
'v1.1.0'
)
expect
(
result
.
count
).
to
eq
(
2
)
end
it
'filters tags by name and sorts by last_updated'
do
params
=
{
sort:
'updated_asc'
,
search:
'v1'
}
tags_finder
=
described_class
.
new
(
repository
,
params
)
result
=
tags_finder
.
execute
expect
(
result
.
first
.
name
).
to
eq
(
'v1.0.0'
)
expect
(
result
.
count
).
to
eq
(
2
)
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