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
e913cf3f
Commit
e913cf3f
authored
Dec 14, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add pagination util and spec
parent
c1ed642f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
0 deletions
+55
-0
lib/gitlab/pagination_util.rb
lib/gitlab/pagination_util.rb
+21
-0
spec/lib/gitlab/pagination_util_spec.rb
spec/lib/gitlab/pagination_util_spec.rb
+34
-0
No files found.
lib/gitlab/pagination_util.rb
0 → 100644
View file @
e913cf3f
module
Gitlab
module
PaginationUtil
delegate
:total_count
,
:total_pages
,
:current_page
,
:limit_value
,
:first_page?
,
:prev_page
,
:last_page?
,
:next_page
,
to: :pagination_delegate
# requires a Gitlab::PaginationDelegate instance with the default configuration.
# Example:
# @pagination_delegate ||= Gitlab::PaginationDelegate.new(page: 1,
# per_page: 10,
# count: 20)
def
pagination_delegate
raise
NotImplementedError
.
new
(
"Expected
#{
self
.
class
.
name
}
to implement
#{
__method__
}
"
)
end
end
end
spec/lib/gitlab/pagination_util_spec.rb
0 → 100644
View file @
e913cf3f
require
'spec_helper'
describe
Gitlab
::
PaginationUtil
,
lib:
true
do
context
'class with no pagination delegate defined'
do
let
(
:pagination_class
)
{
Class
.
new
{
extend
Gitlab
::
PaginationUtil
}
}
it
'throws an error calling the method'
do
expect
{
pagination_class
.
pagination_delegate
}.
to
raise_error
(
NotImplementedError
)
end
end
context
'class with no pagination delegate defined'
do
let
(
:pagination_class
)
{
Class
.
new
{
extend
Gitlab
::
PaginationUtil
}
}
let
(
:pagination_delegate
)
{
Gitlab
::
PaginationDelegate
.
new
(
page:
1
,
per_page:
10
,
count:
20
)
}
let
(
:delegated_methods
)
{
%i[total_count total_pages current_page limit_value first_page? prev_page last_page? next_page]
}
before
do
allow
(
pagination_class
).
to
receive
(
:pagination_delegate
).
and_return
(
pagination_delegate
)
end
it
'does not throw an error'
do
expect
{
pagination_class
.
pagination_delegate
}.
not_to
raise_error
end
it
'includes the delegated methods'
do
expect
(
pagination_class
.
public_methods
).
to
include
(
*
delegated_methods
)
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