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
f9331db1
Commit
f9331db1
authored
Dec 22, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for pagination module extracted from API
parent
d57faaa0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
94 additions
and
0 deletions
+94
-0
spec/lib/api/helpers/pagination_spec.rb
spec/lib/api/helpers/pagination_spec.rb
+94
-0
No files found.
spec/lib/api/helpers/pagination_spec.rb
0 → 100644
View file @
f9331db1
require
'spec_helper'
describe
API
::
Helpers
::
Pagination
do
let
(
:resource
)
{
Project
.
all
}
subject
do
Class
.
new
.
include
(
described_class
).
new
end
describe
'#paginate'
do
let
(
:value
)
{
spy
(
'return value'
)
}
before
do
allow
(
value
).
to
receive
(
:to_query
).
and_return
(
value
)
allow
(
subject
).
to
receive
(
:header
).
and_return
(
value
)
allow
(
subject
).
to
receive
(
:params
).
and_return
(
value
)
allow
(
subject
).
to
receive
(
:request
).
and_return
(
value
)
end
describe
'required instance methods'
do
let
(
:return_spy
)
{
spy
}
it
'requires some instance methods'
do
expect_message
(
:header
)
expect_message
(
:params
)
expect_message
(
:request
)
subject
.
paginate
(
resource
)
end
end
context
'when resource can be paginated'
do
before
do
create_list
(
:empty_project
,
3
)
end
describe
'first page'
do
before
do
allow
(
subject
).
to
receive
(
:params
)
.
and_return
({
page:
1
,
per_page:
2
})
end
it
'returns appropriate amount of resources'
do
expect
(
subject
.
paginate
(
resource
).
count
).
to
eq
2
end
it
'adds appropriate headers'
do
expect_header
(
'X-Total'
,
'3'
)
expect_header
(
'X-Total-Pages'
,
'2'
)
expect_header
(
'X-Per-Page'
,
'2'
)
expect_header
(
'X-Page'
,
'1'
)
expect_header
(
'X-Next-Page'
,
'2'
)
expect_header
(
'X-Prev-Page'
,
''
)
expect_header
(
'Link'
,
any_args
)
subject
.
paginate
(
resource
)
end
end
describe
'second page'
do
before
do
allow
(
subject
).
to
receive
(
:params
)
.
and_return
({
page:
2
,
per_page:
2
})
end
it
'returns appropriate amount of resources'
do
expect
(
subject
.
paginate
(
resource
).
count
).
to
eq
1
end
it
'adds appropriate headers'
do
expect_header
(
'X-Total'
,
'3'
)
expect_header
(
'X-Total-Pages'
,
'2'
)
expect_header
(
'X-Per-Page'
,
'2'
)
expect_header
(
'X-Page'
,
'2'
)
expect_header
(
'X-Next-Page'
,
''
)
expect_header
(
'X-Prev-Page'
,
'1'
)
expect_header
(
'Link'
,
any_args
)
subject
.
paginate
(
resource
)
end
end
end
def
expect_header
(
name
,
value
)
expect
(
subject
).
to
receive
(
:header
).
with
(
name
,
value
)
end
def
expect_message
(
method
)
expect
(
subject
).
to
receive
(
method
)
.
at_least
(
:once
).
and_return
(
value
)
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