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
Jérome Perrin
gitlab-ce
Commits
5681bf63
Commit
5681bf63
authored
Jun 28, 2017
by
Alejandro Rodríguez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix a bug where an invalid sort param value was passed to Gitaly
parent
9f44687a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
1 deletion
+50
-1
lib/gitlab/gitaly_client/ref.rb
lib/gitlab/gitaly_client/ref.rb
+2
-0
spec/features/projects/branches_spec.rb
spec/features/projects/branches_spec.rb
+39
-1
spec/lib/gitlab/gitaly_client/ref_spec.rb
spec/lib/gitlab/gitaly_client/ref_spec.rb
+9
-0
No files found.
lib/gitlab/gitaly_client/ref.rb
View file @
5681bf63
...
@@ -59,6 +59,8 @@ module Gitlab
...
@@ -59,6 +59,8 @@ module Gitlab
end
end
def
sort_by_param
(
sort_by
)
def
sort_by_param
(
sort_by
)
sort_by
=
'name'
if
sort_by
==
'name_asc'
enum_value
=
Gitaly
::
FindLocalBranchesRequest
::
SortBy
.
resolve
(
sort_by
.
upcase
.
to_sym
)
enum_value
=
Gitaly
::
FindLocalBranchesRequest
::
SortBy
.
resolve
(
sort_by
.
upcase
.
to_sym
)
raise
ArgumentError
,
"Invalid sort_by key `
#{
sort_by
}
`"
unless
enum_value
raise
ArgumentError
,
"Invalid sort_by key `
#{
sort_by
}
`"
unless
enum_value
enum_value
enum_value
...
...
spec/features/projects/branches_spec.rb
View file @
5681bf63
...
@@ -21,10 +21,48 @@ describe 'Branches', feature: true do
...
@@ -21,10 +21,48 @@ describe 'Branches', feature: true do
it
'shows all the branches'
do
it
'shows all the branches'
do
visit
namespace_project_branches_path
(
project
.
namespace
,
project
)
visit
namespace_project_branches_path
(
project
.
namespace
,
project
)
repository
.
branches
{
|
branch
|
expect
(
page
).
to
have_content
(
"
#{
branch
.
name
}
"
)
}
repository
.
branches_sorted_by
(
:name
).
first
(
20
).
each
do
|
branch
|
expect
(
page
).
to
have_content
(
"
#{
branch
.
name
}
"
)
end
expect
(
page
).
to
have_content
(
"Protected branches can be managed in project settings"
)
expect
(
page
).
to
have_content
(
"Protected branches can be managed in project settings"
)
end
end
it
'sorts the branches by name'
do
visit
namespace_project_branches_path
(
project
.
namespace
,
project
)
click_button
"Name"
# Open sorting dropdown
click_link
"Name"
sorted
=
repository
.
branches_sorted_by
(
:name
).
first
(
20
).
map
do
|
branch
|
Regexp
.
escape
(
branch
.
name
)
end
expect
(
page
).
to
have_content
(
/
#{
sorted
.
join
(
".*"
)
}
/
)
end
it
'sorts the branches by last updated'
do
visit
namespace_project_branches_path
(
project
.
namespace
,
project
)
click_button
"Name"
# Open sorting dropdown
click_link
"Last updated"
sorted
=
repository
.
branches_sorted_by
(
:updated_desc
).
first
(
20
).
map
do
|
branch
|
Regexp
.
escape
(
branch
.
name
)
end
expect
(
page
).
to
have_content
(
/
#{
sorted
.
join
(
".*"
)
}
/
)
end
it
'sorts the branches by oldest updated'
do
visit
namespace_project_branches_path
(
project
.
namespace
,
project
)
click_button
"Name"
# Open sorting dropdown
click_link
"Oldest updated"
sorted
=
repository
.
branches_sorted_by
(
:updated_asc
).
first
(
20
).
map
do
|
branch
|
Regexp
.
escape
(
branch
.
name
)
end
expect
(
page
).
to
have_content
(
/
#{
sorted
.
join
(
".*"
)
}
/
)
end
it
'avoids a N+1 query in branches index'
do
it
'avoids a N+1 query in branches index'
do
control_count
=
ActiveRecord
::
QueryRecorder
.
new
{
visit
namespace_project_branches_path
(
project
.
namespace
,
project
)
}.
count
control_count
=
ActiveRecord
::
QueryRecorder
.
new
{
visit
namespace_project_branches_path
(
project
.
namespace
,
project
)
}.
count
...
...
spec/lib/gitlab/gitaly_client/ref_spec.rb
View file @
5681bf63
...
@@ -69,6 +69,15 @@ describe Gitlab::GitalyClient::Ref do
...
@@ -69,6 +69,15 @@ describe Gitlab::GitalyClient::Ref do
client
.
local_branches
(
sort_by:
'updated_desc'
)
client
.
local_branches
(
sort_by:
'updated_desc'
)
end
end
it
'translates known mismatches on sort param values'
do
expect_any_instance_of
(
Gitaly
::
Ref
::
Stub
)
.
to
receive
(
:find_local_branches
)
.
with
(
gitaly_request_with_params
(
sort_by: :NAME
),
kind_of
(
Hash
))
.
and_return
([])
client
.
local_branches
(
sort_by:
'name_asc'
)
end
it
'raises an argument error if an invalid sort_by parameter is passed'
do
it
'raises an argument error if an invalid sort_by parameter is passed'
do
expect
{
client
.
local_branches
(
sort_by:
'invalid_sort'
)
}.
to
raise_error
(
ArgumentError
)
expect
{
client
.
local_branches
(
sort_by:
'invalid_sort'
)
}.
to
raise_error
(
ArgumentError
)
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