Skip to content

Commit

Permalink
Add tests for allow_overflow_page_number
Browse files Browse the repository at this point in the history
  • Loading branch information
drewolson committed Apr 4, 2019
1 parent e18965a commit e3efdca
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions test/scrivener/paginator/ecto/query_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -213,52 +213,42 @@ defmodule Scrivener.Paginator.Ecto.QueryTest do
assert page.page_size == 10
end

test "will respect the total_entries configuration" do
test "will respect total_entries passed to paginate" do
create_posts()

config = %Scrivener.Config{
module: Scrivener.Ecto.Repo,
page_number: 2,
page_size: 4,
options: [total_entries: 130]
}

page =
Post
|> Post.published()
|> Scrivener.paginate(config)
|> Scrivener.Ecto.Repo.paginate(options: [total_entries: 130])

assert page.total_entries == 130
end

test "will respect total_entries passed to paginate" do
create_posts()
test "will use total_pages if page_numer is too large" do
posts = create_posts()

page =
Post
|> Post.published()
|> Scrivener.Ecto.Repo.paginate(options: [total_entries: 130])
|> Scrivener.Ecto.Repo.paginate(page: 3)

assert page.total_entries == 130
assert page.page_number == 2
assert page.entries == posts |> Enum.reverse() |> Enum.take(1)
end

test "will use total_pages if page_numer is too large" do
posts = create_posts()

config = %Scrivener.Config{
module: Scrivener.Ecto.Repo,
page_number: 2,
page_size: length(posts),
options: []
}
test "allows overflow page numbers if option is specified" do
create_posts()

page =
Post
|> Post.published()
|> Scrivener.paginate(config)
|> Scrivener.Ecto.Repo.paginate(
page: 3,
options: [allow_overflow_page_number: true]
)

assert page.page_number == 1
assert page.entries == posts
assert page.page_number == 3
assert page.entries == []
end

test "can be used on a table with any primary key" do
Expand Down

0 comments on commit e3efdca

Please sign in to comment.