diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f8611c3..2f76225 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -64,6 +64,12 @@ jobs: otp: "19.3" - elixir: "1.11" otp: "20.0" + - elixir: "1.9" + otp: "23.0" + - elixir: "1.7" + otp: "23.0" + - elixir: "1.8" + otp: "23.0" steps: - name: Checkout diff --git a/lib/paginator.ex b/lib/paginator.ex index 8370d53..7c1cae1 100644 --- a/lib/paginator.ex +++ b/lib/paginator.ex @@ -207,7 +207,11 @@ defmodule Paginator do iex> Paginator.cursor_for_record(%Paginator.Customer{id: 1, name: "Alice"}, [id: :asc, name: :desc]) "g3QAAAACZAACaWRhAWQABG5hbWVtAAAABUFsaWNl" """ - @spec cursor_for_record(any(), [atom() | {atom(), atom()}], (map(), atom() | {atom(), atom()} -> any())) :: binary() + @spec cursor_for_record( + any(), + [atom() | {atom(), atom()}], + (map(), atom() | {atom(), atom()} -> any()) + ) :: binary() def cursor_for_record( record, cursor_fields, diff --git a/lib/paginator/config.ex b/lib/paginator/config.ex index 8116084..a98d1aa 100644 --- a/lib/paginator/config.ex +++ b/lib/paginator/config.ex @@ -20,6 +20,10 @@ defmodule Paginator.Config do :total_count_limit ] + defmodule ArgumentError do + defexception [:message] + end + @default_total_count_primary_key_field :id @default_limit 50 @minimum_limit 1 @@ -55,15 +59,19 @@ defmodule Paginator.Config do def validate!(%__MODULE__{} = config) do unless config.cursor_fields do - raise(ArgumentError, "expected `:cursor_fields` to be set") + raise(Paginator.Config.ArgumentError, message: "expected `:cursor_fields` to be set") end if !cursor_values_match_cursor_fields?(config.after_values, config.cursor_fields) do - raise(ArgumentError, message: "expected `:after` cursor to match `:cursor_fields`") + raise(Paginator.Config.ArgumentError, + message: "expected `:after` cursor to match `:cursor_fields`" + ) end if !cursor_values_match_cursor_fields?(config.before_values, config.cursor_fields) do - raise(ArgumentError, message: "expected `:before` cursor to match `:cursor_fields`") + raise(Paginator.Config.ArgumentError, + message: "expected `:before` cursor to match `:cursor_fields`" + ) end end diff --git a/test/paginator/config_test.exs b/test/paginator/config_test.exs index 0b56e79..dfa3da8 100644 --- a/test/paginator/config_test.exs +++ b/test/paginator/config_test.exs @@ -120,7 +120,7 @@ defmodule Paginator.ConfigTest do test "raises ArgumentError when cursor_fields are not set" do config = Config.new([]) - assert_raise ArgumentError, "expected `:cursor_fields` to be set", fn -> + assert_raise Config.ArgumentError, "expected `:cursor_fields` to be set", fn -> Config.validate!(config) end end @@ -128,9 +128,11 @@ defmodule Paginator.ConfigTest do test "raises ArgumentError when after cursor does not match the cursor_fields" do config = Config.new(cursor_fields: [:date], after: complex_after()) - assert_raise ArgumentError, "expected `:after` cursor to match `:cursor_fields`", fn -> - Config.validate!(config) - end + assert_raise Config.ArgumentError, + "expected `:after` cursor to match `:cursor_fields`", + fn -> + Config.validate!(config) + end end test "raises ArgumentError when after cursor does not match cursor_fields with schema" do @@ -144,9 +146,11 @@ defmodule Paginator.ConfigTest do }) ) - assert_raise ArgumentError, "expected `:after` cursor to match `:cursor_fields`", fn -> - Config.validate!(config) - end + assert_raise Config.ArgumentError, + "expected `:after` cursor to match `:cursor_fields`", + fn -> + Config.validate!(config) + end end test "ok when after cursor matches cursor_fields with schema" do @@ -166,9 +170,11 @@ defmodule Paginator.ConfigTest do test "raises ArgumentError when before cursor does not match the cursor_fields" do config = Config.new(cursor_fields: [:id], before: complex_before()) - assert_raise ArgumentError, "expected `:before` cursor to match `:cursor_fields`", fn -> - Config.validate!(config) - end + assert_raise Config.ArgumentError, + "expected `:before` cursor to match `:cursor_fields`", + fn -> + Config.validate!(config) + end end end diff --git a/test/paginator_test.exs b/test/paginator_test.exs index 7f4c316..ff9bfe5 100644 --- a/test/paginator_test.exs +++ b/test/paginator_test.exs @@ -970,9 +970,7 @@ defmodule PaginatorTest do end for field0_order <- @available_sorting_order, field1_order <- @available_sorting_order do - test "paginates correctly when pages contains nulls - order by charged_at #{field0_order}, id #{ - field1_order - }" do + test "paginates correctly when pages contains nulls - order by charged_at #{field0_order}, id #{field1_order}" do customer = insert(:customer) now = NaiveDateTime.utc_now()