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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
805bbe88
Commit
805bbe88
authored
Dec 20, 2016
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adds specs for respective behaviour
parent
9b66aa6e
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
123 additions
and
19 deletions
+123
-19
app/controllers/concerns/kaminari_pagination.rb
app/controllers/concerns/kaminari_pagination.rb
+0
-8
app/controllers/dashboard/todos_controller.rb
app/controllers/dashboard/todos_controller.rb
+4
-3
app/controllers/projects/issues_controller.rb
app/controllers/projects/issues_controller.rb
+4
-2
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+4
-2
app/controllers/projects/snippets_controller.rb
app/controllers/projects/snippets_controller.rb
+4
-2
spec/controllers/dashboard/todos_controller_spec.rb
spec/controllers/dashboard/todos_controller_spec.rb
+36
-0
spec/controllers/projects/issues_controller_spec.rb
spec/controllers/projects/issues_controller_spec.rb
+29
-0
spec/controllers/projects/merge_requests_controller_spec.rb
spec/controllers/projects/merge_requests_controller_spec.rb
+20
-2
spec/controllers/projects/snippets_controller_spec.rb
spec/controllers/projects/snippets_controller_spec.rb
+22
-0
No files found.
app/controllers/concerns/kaminari_pagination.rb
deleted
100644 → 0
View file @
9b66aa6e
module
KaminariPagination
extend
ActiveSupport
::
Concern
def
bounded_pagination
(
items
,
page_number
)
items
=
items
.
page
(
page_number
)
items
.
to_a
.
empty?
?
items
.
page
(
items
.
total_pages
)
:
items
end
end
app/controllers/dashboard/todos_controller.rb
View file @
805bbe88
class
Dashboard::TodosController
<
Dashboard
::
ApplicationController
include
KaminariPagination
before_action
:find_todos
,
only:
[
:index
,
:destroy_all
]
def
index
@sort
=
params
[
:sort
]
@todos
=
bounded_pagination
(
@todos
,
params
[
:page
])
@todos
=
@todos
.
page
(
params
[
:page
])
if
@todos
.
out_of_range?
&&
@todos
.
total_pages
!=
0
redirect_to
dashboard_todos_path
(
page:
@todos
.
total_pages
)
end
end
def
destroy
...
...
app/controllers/projects/issues_controller.rb
View file @
805bbe88
...
...
@@ -5,7 +5,6 @@ class Projects::IssuesController < Projects::ApplicationController
include
ToggleAwardEmoji
include
IssuableCollections
include
SpammableActions
include
KaminariPagination
before_action
:redirect_to_external_issue_tracker
,
only:
[
:index
,
:new
]
before_action
:module_enabled
...
...
@@ -25,7 +24,10 @@ class Projects::IssuesController < Projects::ApplicationController
def
index
@issues
=
issues_collection
@issues
=
bounded_pagination
(
@issues
,
params
[
:page
])
@issues
=
@issues
.
page
(
params
[
:page
])
if
@issues
.
out_of_range?
&&
@issues
.
total_pages
!=
0
return
redirect_to
namespace_project_issues_path
(
page:
@issues
.
total_pages
)
end
if
params
[
:label_name
].
present?
@labels
=
LabelsFinder
.
new
(
current_user
,
project_id:
@project
.
id
,
title:
params
[
:label_name
]).
execute
...
...
app/controllers/projects/merge_requests_controller.rb
View file @
805bbe88
...
...
@@ -6,7 +6,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
include
NotesHelper
include
ToggleAwardEmoji
include
IssuableCollections
include
KaminariPagination
before_action
:module_enabled
before_action
:merge_request
,
only:
[
...
...
@@ -38,7 +37,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def
index
@merge_requests
=
merge_requests_collection
@merge_requests
=
bounded_pagination
(
@merge_requests
,
params
[
:page
])
@merge_requests
=
@merge_requests
.
page
(
params
[
:page
])
if
@merge_requests
.
out_of_range?
&&
@merge_requests
.
total_pages
!=
0
return
redirect_to
namespace_project_merge_requests_path
(
page:
@merge_requests
.
total_pages
)
end
if
params
[
:label_name
].
present?
labels_params
=
{
project_id:
@project
.
id
,
title:
params
[
:label_name
]
}
...
...
app/controllers/projects/snippets_controller.rb
View file @
805bbe88
class
Projects::SnippetsController
<
Projects
::
ApplicationController
include
ToggleAwardEmoji
include
KaminariPagination
before_action
:module_enabled
before_action
:snippet
,
only:
[
:show
,
:edit
,
:destroy
,
:update
,
:raw
,
:toggle_award_emoji
]
...
...
@@ -26,7 +25,10 @@ class Projects::SnippetsController < Projects::ApplicationController
project:
@project
,
scope:
params
[
:scope
]
)
@snippets
=
bounded_pagination
(
@snippets
,
params
[
:page
])
@snippets
=
@snippets
.
page
(
params
[
:page
])
if
@snippets
.
out_of_range?
&&
@snippets
.
total_pages
!=
0
redirect_to
namespace_project_snippets_path
(
page:
@snippets
.
total_pages
)
end
end
def
new
...
...
spec/controllers/dashboard/todos_controller_spec.rb
0 → 100644
View file @
805bbe88
require
'spec_helper'
describe
Dashboard
::
TodosController
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:todo_service
)
{
TodoService
.
new
}
describe
'GET #index'
do
before
do
sign_in
(
user
)
project
.
team
<<
[
user
,
:developer
]
end
context
'when using pagination'
do
let
(
:last_page
)
{
user
.
todos
.
page
().
total_pages
}
let!
(
:issues
)
{
create_list
(
:issue
,
30
,
project:
project
,
assignee:
user
)
}
before
do
issues
.
each
{
|
issue
|
todo_service
.
new_issue
(
issue
,
user
)
}
end
it
'redirects to last_page if page number is larger than number of pages'
do
get
:index
,
page:
(
last_page
+
1
).
to_param
expect
(
response
).
to
redirect_to
(
dashboard_todos_path
(
page:
last_page
))
end
it
'redirects to correspondent page'
do
get
:index
,
page:
last_page
expect
(
assigns
(
:todos
).
current_page
).
to
eq
(
last_page
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
end
spec/controllers/projects/issues_controller_spec.rb
View file @
805bbe88
...
...
@@ -52,6 +52,35 @@ describe Projects::IssuesController do
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
'with page param'
do
let
(
:last_page
)
{
project
.
issues
.
page
().
total_pages
}
let!
(
:issue_list
)
{
create_list
(
:issue
,
30
,
project:
project
)
}
before
do
sign_in
(
user
)
project
.
team
<<
[
user
,
:developer
]
end
it
'redirects to last_page if page number is larger than number of pages'
do
get
:index
,
namespace_id:
project
.
namespace
.
path
.
to_param
,
project_id:
project
.
path
.
to_param
,
page:
(
last_page
+
1
).
to_param
expect
(
response
).
to
redirect_to
(
namespace_project_issues_path
(
page:
last_page
))
end
it
'redirects to specified page'
do
get
:index
,
namespace_id:
project
.
namespace
.
path
.
to_param
,
project_id:
project
.
path
.
to_param
,
page:
last_page
.
to_param
expect
(
assigns
(
:issues
).
current_page
).
to
eq
(
last_page
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
describe
'GET #new'
do
...
...
spec/controllers/projects/merge_requests_controller_spec.rb
View file @
805bbe88
...
...
@@ -127,11 +127,29 @@ describe Projects::MergeRequestsController do
end
describe
'GET index'
do
def
get_merge_requests
let
(
:last_page
)
{
project
.
merge_requests
.
page
().
total_pages
}
let!
(
:merge_request
)
{
create
(
:merge_request_with_diffs
,
target_project:
project
,
source_project:
project
)
}
def
get_merge_requests
(
page
=
nil
)
get
:index
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
state:
'opened'
state:
'opened'
,
page:
page
.
to_param
end
context
'when page param'
do
it
'redirects to last_page if page number is larger than number of pages'
do
get_merge_requests
(
last_page
+
1
)
expect
(
response
).
to
redirect_to
(
namespace_project_merge_requests_path
(
page:
last_page
))
end
it
'redirects to specified page'
do
get_merge_requests
(
last_page
)
expect
(
assigns
(
:merge_requests
).
current_page
).
to
eq
(
last_page
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
context
'when filtering by opened state'
do
...
...
spec/controllers/projects/snippets_controller_spec.rb
View file @
805bbe88
...
...
@@ -11,6 +11,28 @@ describe Projects::SnippetsController do
end
describe
'GET #index'
do
context
'when page param'
do
let
(
:last_page
)
{
project
.
snippets
.
page
().
total_pages
}
let!
(
:project_snippet
)
{
create
(
:project_snippet
,
:public
,
project:
project
,
author:
user
)
}
it
'redirects to last_page if page number is larger than number of pages'
do
get
:index
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
page:
(
last_page
+
1
).
to_param
expect
(
response
).
to
redirect_to
(
namespace_project_snippets_path
(
page:
last_page
))
end
it
'redirects to specified page'
do
get
:index
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
page:
(
last_page
).
to_param
expect
(
assigns
(
:snippets
).
current_page
).
to
eq
(
last_page
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
context
'when the project snippet is private'
do
let!
(
:project_snippet
)
{
create
(
:project_snippet
,
:private
,
project:
project
,
author:
user
)
}
...
...
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