Skip to content

Commit

Permalink
Remove prefix_test and move tests into existing query_test
Browse files Browse the repository at this point in the history
  • Loading branch information
drewolson committed Aug 23, 2020
1 parent 6f160be commit 8ef1736
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 37 deletions.
36 changes: 0 additions & 36 deletions test/scrivener/paginator/ecto/prefix_test.exs

This file was deleted.

28 changes: 27 additions & 1 deletion test/scrivener/paginator/ecto/query_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Scrivener.Paginator.Ecto.QueryTest do
use Scrivener.Ecto.TestCase

alias Scrivener.Ecto.{Comment, KeyValue, Post}
alias Scrivener.Ecto.{Comment, KeyValue, Post, User}

defp create_posts do
unpublished_post =
Expand Down Expand Up @@ -40,6 +40,13 @@ defmodule Scrivener.Paginator.Ecto.QueryTest do
end)
end

defp create_users(number, prefix) do
Enum.map(1..number, fn i ->
%User{email: "user_#{i}@#{prefix}.com"}
|> Scrivener.Ecto.Repo.insert!(prefix: prefix)
end)
end

describe "paginate" do
test "paginates an unconstrained query" do
create_posts()
Expand Down Expand Up @@ -419,5 +426,24 @@ defmodule Scrivener.Paginator.Ecto.QueryTest do
assert page.total_entries == 1
assert page.total_pages == 1
end

test "can specify prefix" do
create_users(6, "tenant_1")
create_users(2, "tenant_2")

page_tenant_1 = Scrivener.Ecto.Repo.paginate(User, options: [prefix: "tenant_1"])

assert page_tenant_1.page_size == 5
assert page_tenant_1.page_number == 1
assert page_tenant_1.total_entries == 6
assert page_tenant_1.total_pages == 2

page_tenant_2 = Scrivener.Ecto.Repo.paginate(User, options: [prefix: "tenant_2"])

assert page_tenant_2.page_size == 5
assert page_tenant_2.page_number == 1
assert page_tenant_2.total_entries == 2
assert page_tenant_2.total_pages == 1
end
end
end

0 comments on commit 8ef1736

Please sign in to comment.