From af8424dc9fb7d227b0d13b2bbc1c5380dcb7f6ac Mon Sep 17 00:00:00 2001 From: Blake Kostner Date: Wed, 11 Oct 2023 15:03:59 -0600 Subject: [PATCH] chore: setup common-config-elixir (#1) --- .credo.exs | 194 ++++++++++++++++ .formatter.exs | 5 +- .github/workflows/ci.yaml | 169 ++++++++++++++ .github/workflows/common-config-elixir.yaml | 52 +++++ .github/workflows/pr.yaml | 33 +++ .github/workflows/production.yaml | 37 +++ .github/workflows/release.yaml | 23 ++ .github/workflows/staging.yaml | 51 ++++ .github/workflows/static-analysis.yml | 84 ------- .github/workflows/test.yml | 145 ------------ .release-please-config.json | 39 ++++ .release-please-manifest.json | 3 + .tool-versions | 2 + README.md | 16 +- config/config.exs | 2 +- config/dev.exs | 2 +- config/test.exs | 10 +- lib/paginator.ex | 27 +-- lib/paginator/config.ex | 51 ++-- lib/paginator/ecto/query.ex | 8 +- lib/paginator/ecto/query/asc_nulls_first.ex | 2 + lib/paginator/ecto/query/asc_nulls_last.ex | 2 + lib/paginator/ecto/query/desc_nulls_first.ex | 2 + lib/paginator/ecto/query/desc_nulls_last.ex | 2 + .../ecto/query/dynamic_filter_builder.ex | 16 +- .../ecto/query/field_or_expression.ex | 2 + mix.exs | 36 +-- mix.lock | 49 ++-- test/paginator_test.exs | 217 +++++++++--------- test/support/customer.ex | 2 +- test/support/data_case.ex | 3 +- test/support/factory.ex | 2 +- test/support/payment.ex | 4 +- 33 files changed, 841 insertions(+), 451 deletions(-) create mode 100644 .credo.exs create mode 100644 .github/workflows/ci.yaml create mode 100644 .github/workflows/common-config-elixir.yaml create mode 100644 .github/workflows/pr.yaml create mode 100644 .github/workflows/production.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 .github/workflows/staging.yaml delete mode 100644 .github/workflows/static-analysis.yml delete mode 100644 .github/workflows/test.yml create mode 100644 .release-please-config.json create mode 100644 .release-please-manifest.json create mode 100644 .tool-versions diff --git a/.credo.exs b/.credo.exs new file mode 100644 index 0000000..b2bc820 --- /dev/null +++ b/.credo.exs @@ -0,0 +1,194 @@ +# This file is synced with stordco/common-config-elixir. Any changes will be overwritten. + +# This file contains the configuration for Credo and you are probably reading +# this after creating it with `mix credo.gen.config`. +# +# If you find anything wrong or unclear in this file, please report an +# issue on GitHub: https://github.com/rrrene/credo/issues +# +%{ + # + # You can have as many configs as you like in the `configs:` field. + configs: [ + %{ + # + # Run any config using `mix credo -C `. If no config name is given + # "default" is used. + # + name: "default", + # + # These are the files included in the analysis: + files: %{ + # + # You can give explicit globs or simply directories. + # In the latter case `**/*.{ex,exs}` will be used. + # + included: ["lib/", "priv/", "test/"], + excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"] + }, + # + # Load and configure plugins here: + # + plugins: [], + # + # If you create your own checks, you must specify the source files for + # them here, so they can be loaded by Credo before running the analysis. + # + requires: [], + # + # If you want to enforce a style guide and need a more traditional linting + # experience, you can change `strict` to `true` below: + # + strict: true, + # + # To modify the timeout for parsing files, change this value: + # + parse_timeout: 5000, + # + # If you want to use uncolored output by default, you can change `color` + # to `false` below: + # + color: true, + # + # You can customize the parameters of any check by adding a second element + # to the tuple. + # + # To disable a check put `false` as second element: + # + # {Credo.Check.Design.DuplicatedCode, false} + # + checks: [ + # + ## Database Migration Checks + # + {ExcellentMigrations.CredoCheck.MigrationsSafety, []}, + + # + ## Consistency Checks + # + {Credo.Check.Consistency.ExceptionNames, []}, + {Credo.Check.Consistency.LineEndings, []}, + {Credo.Check.Consistency.MultiAliasImportRequireUse, []}, + {Credo.Check.Consistency.ParameterPatternMatching, []}, + {Credo.Check.Consistency.SpaceAroundOperators, []}, + {Credo.Check.Consistency.SpaceInParentheses, []}, + {Credo.Check.Consistency.TabsOrSpaces, []}, + {Credo.Check.Consistency.UnusedVariableNames, false}, + + # + ## Design Checks + # + # You can customize the priority of any check + # Priority values are: `low, normal, high, higher` + # + {Credo.Check.Design.AliasUsage, [priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 2]}, + {Credo.Check.Design.DuplicatedCode, false}, + # You can also customize the exit_status of each check. + # If you don't want TODO comments to cause `mix credo` to fail, just + # set this value to 0 (zero). + # + {Credo.Check.Design.TagTODO, [exit_status: 2]}, + {Credo.Check.Design.TagFIXME, []}, + + # + ## Readability Checks + # + {Credo.Check.Readability.AliasAs, false}, + {Credo.Check.Readability.AliasOrder, []}, + {Credo.Check.Readability.BlockPipe, []}, + {Credo.Check.Readability.FunctionNames, []}, + {Credo.Check.Readability.ImplTrue, []}, + {Credo.Check.Readability.LargeNumbers, [trailing_digits: 2]}, + {Credo.Check.Readability.MaxLineLength, false}, + {Credo.Check.Readability.ModuleAttributeNames, []}, + {Credo.Check.Readability.ModuleDoc, false}, + {Credo.Check.Readability.ModuleNames, []}, + {Credo.Check.Readability.MultiAlias, false}, + {Credo.Check.Readability.NestedFunctionCalls, []}, + {Credo.Check.Readability.ParenthesesInCondition, []}, + {Credo.Check.Readability.ParenthesesOnZeroArityDefs, []}, + {Credo.Check.Readability.PredicateFunctionNames, []}, + {Credo.Check.Readability.PreferImplicitTry, []}, + {Credo.Check.Readability.RedundantBlankLines, []}, + {Credo.Check.Readability.Semicolons, []}, + {Credo.Check.Readability.SeparateAliasRequire, []}, + {Credo.Check.Readability.SinglePipe, []}, + {Credo.Check.Readability.SpaceAfterCommas, []}, + {Credo.Check.Readability.Specs, false}, + {Credo.Check.Readability.StrictModuleLayout, + [ + order: + ~w(moduledoc behaviour use import require alias module_attribute defstruct callback macrocallback optional_callback)a, + ignore: [:type] + ]}, + {Credo.Check.Readability.StringSigils, []}, + {Credo.Check.Readability.TrailingBlankLine, []}, + {Credo.Check.Readability.TrailingWhiteSpace, []}, + {Credo.Check.Readability.UnnecessaryAliasExpansion, []}, + {Credo.Check.Readability.VariableNames, []}, + {Credo.Check.Readability.WithCustomTaggedTuple, []}, + + # + ## Refactoring Opportunities + # + {Credo.Check.Refactor.ABCSize, false}, + {Credo.Check.Refactor.AppendSingleItem, []}, + {Credo.Check.Refactor.CondStatements, []}, + {Credo.Check.Refactor.CyclomaticComplexity, []}, + {Credo.Check.Refactor.DoubleBooleanNegation, []}, + {Credo.Check.Refactor.FunctionArity, []}, + {Credo.Check.Refactor.LongQuoteBlocks, []}, + # {Credo.Check.Refactor.MapInto, []}, + {Credo.Check.Refactor.MatchInCondition, []}, + {Credo.Check.Refactor.ModuleDependencies, false}, + {Credo.Check.Refactor.NegatedConditionsInUnless, []}, + {Credo.Check.Refactor.NegatedConditionsWithElse, []}, + {Credo.Check.Refactor.NegatedIsNil, []}, + {Credo.Check.Refactor.Nesting, []}, + {Credo.Check.Refactor.PipeChainStart, []}, + {Credo.Check.Refactor.UnlessWithElse, []}, + {Credo.Check.Refactor.VariableRebinding, false}, + {Credo.Check.Refactor.WithClauses, []}, + + # + ## Warnings + # + {Credo.Check.Warning.ApplicationConfigInModuleAttribute, []}, + {Credo.Check.Warning.BoolOperationOnSameValues, []}, + {Credo.Check.Warning.ExpensiveEmptyEnumCheck, []}, + {Credo.Check.Warning.IExPry, []}, + {Credo.Check.Warning.IoInspect, []}, + {Credo.Check.Warning.LeakyEnvironment, []}, + # {Credo.Check.Warning.LazyLogging, []}, + {Credo.Check.Warning.MapGetUnsafePass, []}, + # disabling this check by default, as if not included, it will be + # run on version 1.7.0 and above + {Credo.Check.Warning.MissedMetadataKeyInLoggerConfig, false}, + {Credo.Check.Warning.MixEnv, []}, + {Credo.Check.Warning.OperationOnSameValues, []}, + {Credo.Check.Warning.OperationWithConstantResult, []}, + {Credo.Check.Warning.RaiseInsideRescue, []}, + {Credo.Check.Warning.UnsafeExec, []}, + {Credo.Check.Warning.UnsafeToAtom, []}, + {Credo.Check.Warning.UnusedEnumOperation, []}, + {Credo.Check.Warning.UnusedFileOperation, []}, + {Credo.Check.Warning.UnusedKeywordOperation, []}, + {Credo.Check.Warning.UnusedListOperation, []}, + {Credo.Check.Warning.UnusedPathOperation, []}, + {Credo.Check.Warning.UnusedRegexOperation, []}, + {Credo.Check.Warning.UnusedStringOperation, []}, + {Credo.Check.Warning.UnusedTupleOperation, []}, + + # + ## Custom + # + {Credo.Check.Warning.ForbiddenModule, + [ + modules: [ + {Oban.Worker, "use Oban.Pro.Worker instead"} + ] + ]} + ] + } + ] +} diff --git a/.formatter.exs b/.formatter.exs index dc224ad..37d594a 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -1,6 +1,7 @@ # Used by "mix format" [ - inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"], import_deps: [:ecto], - local_without_parens: [] + inputs: ["*.{heex,ex,exs}", "{config,lib,priv,test}/**/*.{heex,ex,exs}"], + line_length: 120, + plugins: [] ] diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..c5ca5e4 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,169 @@ +# This file is synced with stordco/common-config-elixir. Any changes will be overwritten. + +name: CI + +on: + merge_group: + pull_request: + types: + - opened + - reopened + - synchronize + push: + branches: + - main + workflow_call: + secrets: + CI_SERVICE_KEY: + required: true + GH_PERSONAL_ACCESS_TOKEN: + required: true + HEX_API_KEY: + required: true + workflow_dispatch: + +concurrency: + group: ${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + Credo: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Elixir + uses: stordco/actions-elixir/setup@v1 + with: + github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + hex-token: ${{ secrets.HEX_API_KEY }} + oban-fingerprint: ${{ secrets.OBAN_KEY_FINGERPRINT }} + oban-token: ${{ secrets.OBAN_LICENSE_KEY }} + + - name: Credo + run: mix credo --strict + + Dependencies: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Elixir + uses: stordco/actions-elixir/setup@v1 + with: + github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + hex-token: ${{ secrets.HEX_API_KEY }} + oban-fingerprint: ${{ secrets.OBAN_KEY_FINGERPRINT }} + oban-token: ${{ secrets.OBAN_LICENSE_KEY }} + + - name: Unused + run: mix deps.unlock --check-unused + + Dialyzer: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Elixir + uses: stordco/actions-elixir/setup@v1 + with: + github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + hex-token: ${{ secrets.HEX_API_KEY }} + oban-fingerprint: ${{ secrets.OBAN_KEY_FINGERPRINT }} + oban-token: ${{ secrets.OBAN_LICENSE_KEY }} + + - name: Dialyzer + run: mix dialyzer --format github + + Documentation: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Elixir + uses: stordco/actions-elixir/setup@v1 + with: + github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + hex-token: ${{ secrets.HEX_API_KEY }} + oban-fingerprint: ${{ secrets.OBAN_KEY_FINGERPRINT }} + oban-token: ${{ secrets.OBAN_LICENSE_KEY }} + + - name: Docs + run: mix docs + + Format: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Elixir + uses: stordco/actions-elixir/setup@v1 + with: + github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + hex-token: ${{ secrets.HEX_API_KEY }} + oban-fingerprint: ${{ secrets.OBAN_KEY_FINGERPRINT }} + oban-token: ${{ secrets.OBAN_LICENSE_KEY }} + + - name: Format + run: mix format --check-formatted + + Test: + name: Test (Elixir ${{ matrix.versions.elixir }} OTP ${{ matrix.versions.otp }}) + + runs-on: ubuntu-latest + + env: + MIX_ENV: test + + services: + postgres: + image: postgres:14-alpine + ports: + - 5432:5432 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_INITDB_ARGS: "--nosync" + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Elixir + uses: stordco/actions-elixir/setup@v1 + with: + elixir-version: ${{ matrix.versions.elixir }} + github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + hex-token: ${{ secrets.HEX_API_KEY }} + oban-fingerprint: ${{ secrets.OBAN_KEY_FINGERPRINT }} + oban-token: ${{ secrets.OBAN_LICENSE_KEY }} + otp-version: ${{ matrix.versions.otp }} + + - name: Compile + run: mix compile --warnings-as-errors + + - name: Test + run: mix coveralls.github + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + strategy: + fail-fast: false + matrix: + versions: + - elixir: 1.13 + otp: 25 + - elixir: 1.14 + otp: 25 + - elixir: 1.15 + otp: 26 diff --git a/.github/workflows/common-config-elixir.yaml b/.github/workflows/common-config-elixir.yaml new file mode 100644 index 0000000..c38376c --- /dev/null +++ b/.github/workflows/common-config-elixir.yaml @@ -0,0 +1,52 @@ +# This file is synced with stordco/common-config-elixir. Any changes will be overwritten. + +name: Common Config Elixir + +on: + push: + branches: + - main + paths: + - .github/workflows/common-config-elixir.yaml + repository_dispatch: + types: + - common-config-elixir + schedule: + - cron: "8 17 2 * *" + workflow_dispatch: {} + +jobs: + Sync: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + persist-credentials: true + + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: 18 + + - name: Setup Elixir + uses: stordco/actions-elixir/setup@v1 + with: + github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + hex-token: ${{ secrets.HEX_API_KEY }} + elixir-version: "1.15" + otp-version: "26.0" + + - name: Sync + uses: stordco/actions-sync@v1 + with: + commit-message: "chore: sync files with stordco/common-config-elixir" + pr-enabled: true + pr-labels: common-config + pr-title: "chore: sync files with stordco/common-config-elixir" + pr-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + sync-auth: stord-engineering-account:${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + sync-branch: latest + sync-repository: github.com/stordco/common-config-elixir.git diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml new file mode 100644 index 0000000..993200f --- /dev/null +++ b/.github/workflows/pr.yaml @@ -0,0 +1,33 @@ +# This file is synced with stordco/common-config-elixir. Any changes will be overwritten. + +name: PR + +on: + merge_group: + pull_request: + types: + - edited + - opened + - reopened + - synchronize + +jobs: + Title: + if: ${{ github.event_name == 'pull_request' }} + + runs-on: ubuntu-latest + + steps: + - name: Check + uses: stordco/actions-pr-title@v1.0.0 + with: + regex: '^(feat!|fix!|fix|feat|chore|(fix|feat|chore)\(\w.*\)):\s(\[\w{1,8}-\d{1,8}\]|.*).*' + hint: | + Your PR title does not match the Stord common convention. Please rename your PR to match one of the following formats: + + chore: a small insignificant change + fix: [JIRA-1234] fix an existing feature + feat: [JIRA-1234] a new feature to release + feat!: a breaking change + + Note: Adding ! (i.e. `feat!:`) represents a breaking change and will result in a SemVer major release. diff --git a/.github/workflows/production.yaml b/.github/workflows/production.yaml new file mode 100644 index 0000000..12941f5 --- /dev/null +++ b/.github/workflows/production.yaml @@ -0,0 +1,37 @@ +# This file is synced with stordco/common-config-elixir. Any changes will be overwritten. + +name: Production + +on: + release: + types: + - released + - prereleased + workflow_dispatch: + +concurrency: + group: Production + +jobs: + Hex: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Elixir + uses: stordco/actions-elixir/setup@v1 + with: + github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + hex-token: ${{ secrets.HEX_API_KEY }} + oban-fingerprint: ${{ secrets.OBAN_KEY_FINGERPRINT }} + oban-token: ${{ secrets.OBAN_LICENSE_KEY }} + + - name: Compile + run: mix compile --docs + + - name: Publish + run: mix hex.publish --yes + env: + HEX_API_KEY: ${{ secrets.HEX_API_KEY }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..0644819 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,23 @@ +# This file is synced with stordco/common-config-elixir. Any changes will be overwritten. + +name: Release + +on: + push: + branches: + - main + +jobs: + Please: + runs-on: ubuntu-latest + + steps: + - id: release + name: Release + uses: google-github-actions/release-please-action@v3 + with: + command: manifest + config-file: .release-please-config.json + manifest-file: .release-please-manifest.json + release-type: elixir + token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} diff --git a/.github/workflows/staging.yaml b/.github/workflows/staging.yaml new file mode 100644 index 0000000..c8d3dd6 --- /dev/null +++ b/.github/workflows/staging.yaml @@ -0,0 +1,51 @@ +# This file is synced with stordco/common-config-elixir. Any changes will be overwritten. + +name: Staging + +on: + push: + branches: + - main + workflow_dispatch: + +concurrency: + group: Staging + +jobs: + Documentation: + environment: + name: Documentation + url: https://paginator.stord.engineering + + permissions: + contents: read + id-token: write + pages: write + + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Elixir + uses: stordco/actions-elixir/setup@v1 + with: + github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + hex-token: ${{ secrets.HEX_API_KEY }} + oban-fingerprint: ${{ secrets.OBAN_KEY_FINGERPRINT }} + oban-token: ${{ secrets.OBAN_LICENSE_KEY }} + + - name: Build + run: mix docs + + - name: Set CNAME + run: echo "paginator.stord.engineering" > ./doc/CNAME + + - name: Upload Artifacts + uses: actions/upload-pages-artifact@v2 + with: + path: ./doc + + - name: Deploy + uses: actions/deploy-pages@v2 diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml deleted file mode 100644 index d981143..0000000 --- a/.github/workflows/static-analysis.yml +++ /dev/null @@ -1,84 +0,0 @@ -name: Static Analysis - -on: - push: - pull_request: - branches: - - main - -jobs: - check_duplicate_runs: - name: Check for duplicate runs - continue-on-error: true - runs-on: ubuntu-20.04 - outputs: - should_skip: ${{ steps.skip_check.outputs.should_skip }} - steps: - - id: skip_check - uses: fkirc/skip-duplicate-actions@v3.4.0 - with: - concurrent_skipping: always - cancel_others: true - skip_after_successful_duplicate: true - paths_ignore: '["**/README.md", "**/CHANGELOG.md", "**/LICENSE.txt"]' - do_not_skip: '["pull_request"]' - - dialyzer: - name: Static code analysis - runs-on: ubuntu-20.04 - - strategy: - matrix: - elixir: - - "1.11" - otp: - - "23.0" - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Set up Elixir - uses: erlef/setup-beam@v1 - with: - elixir-version: ${{ matrix.elixir }} - otp-version: ${{ matrix.otp }} - - - name: Restore deps cache - uses: actions/cache@v2 - with: - path: deps - key: ${{ runner.os }}-mix-{{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }} - - - name: Restore _build cache - uses: actions/cache@v2 - with: - path: _build - key: ${{ runner.os }}-build-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }} - restore-keys: | - ${{ runner.os }}-build-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }} - ${{ runner.os }}-build-${{ matrix.otp }}-${{ matrix.elixir }} - - - name: Install hex - run: mix local.hex --force - - - name: Install rebar - run: mix local.rebar --force - - - name: Install package dependencies - run: mix deps.get - - - name: Compile package dependencies - run: mix deps.compile - - - name: Restore Dialyzer cache - uses: actions/cache@v2 - with: - path: priv/plts - key: ${{ runner.os }}-dialyzer-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }} - restore-keys: | - ${{ runner.os }}-dialyzer-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }} - ${{ runner.os }}-dialyzer-${{ matrix.otp }}-${{ matrix.elixir }} - - - name: Run dialyzer - run: mix dialyzer --format dialyxir diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 68bd7a8..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,145 +0,0 @@ -name: Test - -on: - push: - pull_request: - branches: - - main - -jobs: - check_duplicate_runs: - name: Check for duplicate runs - continue-on-error: true - runs-on: ubuntu-20.04 - outputs: - should_skip: ${{ steps.skip_check.outputs.should_skip }} - steps: - - id: skip_check - uses: fkirc/skip-duplicate-actions@v3.4.0 - with: - concurrent_skipping: always - cancel_others: true - skip_after_successful_duplicate: true - paths_ignore: '["**/README.md", "**/CHANGELOG.md", "**/LICENSE.txt"]' - do_not_skip: '["pull_request"]' - - test: - name: Elixir ${{ matrix.elixir }} / OTP ${{ matrix.otp }} - runs-on: ubuntu-20.04 - needs: check_duplicate_runs - if: ${{ needs.check_duplicate_runs.outputs.should_skip != 'true' }} - services: - postgres: - image: postgres - ports: - - 5432:5432 - env: - POSTGRES_DB: paginator_test - POSTGRES_PASSWORD: postgres - - strategy: - matrix: - elixir: - - "1.7" - - "1.8" - - "1.9" - - "1.10" - - "1.11" - otp: - - "20.0" - - "21.0" - - "22.0.2" - - "23.0" - exclude: - - elixir: "1.10" - otp: "20.0" - - 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 - uses: actions/checkout@v2 - - - name: Set up Elixir - uses: erlef/setup-beam@v1 - with: - elixir-version: ${{ matrix.elixir }} - otp-version: ${{ matrix.otp }} - - - name: Restore build and deps caches - uses: actions/cache@v2 - with: - path: | - deps - _build - key: ${{ runner.os }}-deps-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }} - restore-keys: | - ${{ runner.os }}-deps-${{ matrix.otp }}-${{ matrix.elixir }} - - - name: Install package dependencies - run: mix deps.get - - - name: Remove compiled application files - run: mix clean - - - name: Compile dependencies - run: mix compile - env: - MIX_ENV: test - - - name: Run unit tests - run: mix test - - inch: - name: Analyse Documentation - runs-on: ubuntu-20.04 - needs: test - - strategy: - matrix: - elixir: - - "1.11" - otp: - - "23.0" - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Set up Elixir - uses: erlef/setup-beam@v1 - with: - elixir-version: ${{ matrix.elixir }} - otp-version: ${{ matrix.otp }} - - - name: Restore build and deps caches - uses: actions/cache@v2 - with: - path: | - deps - _build - key: ${{ runner.os }}-deps-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }} - restore-keys: | - ${{ runner.os }}-deps-${{ matrix.otp }}-${{ matrix.elixir }} - - - name: Install package dependencies - run: mix deps.get - - - name: Remove compiled application files - run: mix clean - - - name: Compile dependencies - run: mix compile - - - name: Check documentation quality locally - run: mix inch - - - name: Report documentation quality - if: github.event_name == 'push' - run: mix inch.report diff --git a/.release-please-config.json b/.release-please-config.json new file mode 100644 index 0000000..c90be46 --- /dev/null +++ b/.release-please-config.json @@ -0,0 +1,39 @@ +{ + "$comment": "This file is synced with stordco/common-config-elixir. Any changes will be overwritten.", + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", + "changelog-sections": [ + { + "type": "feat", + "section": "Features", + "hidden": false + }, + { + "type": "fix", + "section": "Bug Fixes", + "hidden": false + }, + { + "type": "chore", + "section": "Miscellaneous", + "hidden": false + } + ], + "draft": false, + "draft-pull-request": false, + "packages": { + ".": { + "extra-files": [ + "README.md" + ], + "release-type": "elixir" + } + }, + "plugins": [ + { + "type": "sentence-case" + } + ], + "prerelease": false, + "pull-request-header": "An automated release has been created for you.", + "separate-pull-requests": true +} diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..c3f1463 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "1.2.0" +} diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..5c9c84a --- /dev/null +++ b/.tool-versions @@ -0,0 +1,2 @@ +elixir 1.15.6-otp-25 +erlang 25.3.2.6 diff --git a/README.md b/README.md index e525f3b..89ae62f 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,5 @@ # Paginator -[![Build status](https://github.com/duffelhq/paginator/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/duffelhq/paginator/actions?query=branch%3Amain) -[![Inline docs](http://inch-ci.org/github/duffelhq/paginator.svg)](http://inch-ci.org/github/duffelhq/paginator) -[![Module Version](https://img.shields.io/hexpm/v/paginator.svg)](https://hex.pm/packages/paginator) -[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/paginator/) -[![Total Download](https://img.shields.io/hexpm/dt/paginator.svg)](https://hex.pm/packages/paginator) -[![License](https://img.shields.io/hexpm/l/paginator.svg)](https://github.com/duffelhq/paginator/blob/master/LICENSE) -[![Last Updated](https://img.shields.io/github/last-commit/duffelhq/paginator.svg)](https://github.com/duffelhq/paginator/commits/master) - [Cursor based pagination](http://use-the-index-luke.com/no-offset) for Elixir [Ecto](https://github.com/elixir-ecto/ecto). ## Why? @@ -66,13 +58,15 @@ page = MyApp.Repo.paginate(query, cursor_fields: [:inserted_at, :id], limit: 50) Add `:paginator` to your list of dependencies in `mix.exs`: + ```elixir def deps do [ - {:paginator, "~> 1.2.0"} + {:paginator, "~> 1.2.0", organization: "stord"} ] end ``` + ## Usage @@ -216,7 +210,7 @@ for you automatically based on the fields specified in `:cursor_fields`. ## Documentation Documentation is written into the library, you will find it in the source code, accessible from `iex` and of course, it -all gets published to [hexdocs](http://hexdocs.pm/paginator). +all gets published to [hexdocs](https://stord.hexdocs.pm/paginator). ## Contributing @@ -225,7 +219,7 @@ all gets published to [hexdocs](http://hexdocs.pm/paginator). Clone the repo and fetch its dependencies: ``` -$ git clone https://github.com/duffelhq/paginator.git +$ git clone https://github.com/stordco/paginator.git $ cd paginator $ mix deps.get $ mix test diff --git a/config/config.exs b/config/config.exs index 8233fe9..871a3d1 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,3 +1,3 @@ -use Mix.Config +import Config import_config "#{Mix.env()}.exs" diff --git a/config/dev.exs b/config/dev.exs index d2d855e..becde76 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -1 +1 @@ -use Mix.Config +import Config diff --git a/config/test.exs b/config/test.exs index afa5d91..8b16499 100644 --- a/config/test.exs +++ b/config/test.exs @@ -1,11 +1,13 @@ -use Mix.Config +import Config config :paginator, ecto_repos: [Paginator.Repo] config :paginator, Paginator.Repo, - pool: Ecto.Adapters.SQL.Sandbox, + port: 5432, username: "postgres", password: "postgres", - database: "paginator_test" + database: "paginator_test#{System.get_env("MIX_TEST_PARTITION")}", + hostname: "localhost", + pool: Ecto.Adapters.SQL.Sandbox -config :logger, :console, level: :warn +config :logger, :console, level: :warning diff --git a/lib/paginator.ex b/lib/paginator.ex index 6b2fa84..951fe03 100644 --- a/lib/paginator.ex +++ b/lib/paginator.ex @@ -1,3 +1,4 @@ +# credo:disable-for-this-file Credo.Check.Refactor.NegatedIsNil defmodule Paginator do @moduledoc """ Defines a paginator. @@ -50,18 +51,6 @@ defmodule Paginator do alias Paginator.{Config, Cursor, Ecto.Query, Page, Page.Metadata} - defmacro __using__(opts) do - quote do - @defaults unquote(opts) - - def paginate(queryable, opts \\ [], repo_opts \\ []) do - opts = Keyword.merge(@defaults, opts) - - Paginator.paginate(queryable, opts, __MODULE__, repo_opts) - end - end - end - @doc """ Fetches all the results matching the query within the cursors. @@ -170,6 +159,18 @@ defmodule Paginator do @callback paginate(queryable :: Ecto.Query.t(), opts :: Keyword.t(), repo_opts :: Keyword.t()) :: Paginator.Page.t() + defmacro __using__(opts) do + quote do + @defaults unquote(opts) + + def paginate(queryable, opts \\ [], repo_opts \\ []) do + opts = Keyword.merge(@defaults, opts) + + Paginator.paginate(queryable, opts, __MODULE__, repo_opts) + end + end + end + @doc false def paginate(queryable, opts, repo, repo_opts) do config = Config.new(opts) @@ -245,7 +246,7 @@ defmodule Paginator do def default_fetch_cursor_value(schema, {binding, field}) when is_atom(binding) and is_atom(field) do case Map.get(schema, field) do - nil -> Map.get(schema, binding) |> Map.get(field) + nil -> schema |> Map.get(binding) |> Map.get(field) value -> value end end diff --git a/lib/paginator/config.ex b/lib/paginator/config.ex index 33491f6..a2f3ebd 100644 --- a/lib/paginator/config.ex +++ b/lib/paginator/config.ex @@ -5,6 +5,20 @@ defmodule Paginator.Config do @type t :: %__MODULE__{} + @default_total_count_primary_key_field :id + @default_limit 50 + @minimum_limit 1 + @maximum_limit 500 + @default_total_count_limit 10_000 + @order_directions [ + :asc, + :asc_nulls_last, + :asc_nulls_first, + :desc, + :desc_nulls_first, + :desc_nulls_last + ] + defstruct [ :after, :after_values, @@ -24,39 +38,23 @@ defmodule Paginator.Config do defexception [:message] end - @default_total_count_primary_key_field :id - @default_limit 50 - @minimum_limit 1 - @maximum_limit 500 - @default_total_count_limit 10_000 - @order_directions [ - :asc, - :asc_nulls_last, - :asc_nulls_first, - :desc, - :desc_nulls_first, - :desc_nulls_last - ] - def new(opts \\ []) do - %__MODULE__{ + convert_deprecated_config(%__MODULE__{ after: opts[:after], after_values: Cursor.decode(opts[:after]), before: opts[:before], before_values: Cursor.decode(opts[:before]), cursor_fields: opts[:cursor_fields], - fetch_cursor_value_fun: - opts[:fetch_cursor_value_fun] || (&Paginator.default_fetch_cursor_value/2), + fetch_cursor_value_fun: opts[:fetch_cursor_value_fun] || (&Paginator.default_fetch_cursor_value/2), include_total_count: opts[:include_total_count] || false, - total_count_primary_key_field: - opts[:total_count_primary_key_field] || @default_total_count_primary_key_field, + total_count_primary_key_field: opts[:total_count_primary_key_field] || @default_total_count_primary_key_field, limit: limit(opts), sort_direction: opts[:sort_direction], total_count_limit: opts[:total_count_limit] || @default_total_count_limit - } - |> convert_deprecated_config() + }) end + # credo:disable-for-next-line Credo.Check.Consistency.ParameterPatternMatching def validate!(%__MODULE__{} = config) do unless config.cursor_fields do raise(Paginator.Config.ArgumentError, message: "expected `:cursor_fields` to be set") @@ -75,7 +73,7 @@ defmodule Paginator.Config do end end - defp cursor_values_match_cursor_fields?(nil = _cursor_values, _cursor_fields), do: true + defp cursor_values_match_cursor_fields?(nil, _cursor_fields), do: true defp cursor_values_match_cursor_fields?(cursor_values, _cursor_fields) when is_list(cursor_values) do @@ -115,8 +113,10 @@ defmodule Paginator.Config do end defp limit(opts) do - max(opts[:limit] || @default_limit, @minimum_limit) - |> min(opts[:maximum_limit] || @maximum_limit) + min( + max(opts[:limit] || @default_limit, @minimum_limit), + opts[:maximum_limit] || @maximum_limit + ) end defp convert_deprecated_config(config) do @@ -130,8 +130,7 @@ defmodule Paginator.Config do %__MODULE__{sort_direction: direction} -> %{ config - | cursor_fields: - build_cursor_fields_from_sort_direction(config.cursor_fields, direction), + | cursor_fields: build_cursor_fields_from_sort_direction(config.cursor_fields, direction), sort_direction: nil } end diff --git a/lib/paginator/ecto/query.ex b/lib/paginator/ecto/query.ex index a97f6b3..b88c76c 100644 --- a/lib/paginator/ecto/query.ex +++ b/lib/paginator/ecto/query.ex @@ -8,6 +8,7 @@ defmodule Paginator.Ecto.Query do def paginate(queryable, config \\ []) + # credo:disable-for-next-line Credo.Check.Consistency.ParameterPatternMatching def paginate(queryable, %Config{} = config) do queryable |> maybe_where(config) @@ -86,8 +87,7 @@ defmodule Paginator.Ecto.Query do before: nil, cursor_fields: cursor_fields }) do - query - |> filter_values(cursor_fields, after_values, :after) + filter_values(query, cursor_fields, after_values, :after) end defp maybe_where(query, %Config{ @@ -121,9 +121,11 @@ defmodule Paginator.Ecto.Query do {position, column} _ -> + inspected_alias = inspect(query.aliases, custom_options: [sort_maps: true]) + raise( ArgumentError, - "Could not find binding `#{binding_name}` in query aliases: #{inspect(query.aliases)}" + "Could not find binding `#{binding_name}` in query aliases: #{inspected_alias}" ) end end diff --git a/lib/paginator/ecto/query/asc_nulls_first.ex b/lib/paginator/ecto/query/asc_nulls_first.ex index d13871a..ad575a3 100644 --- a/lib/paginator/ecto/query/asc_nulls_first.ex +++ b/lib/paginator/ecto/query/asc_nulls_first.ex @@ -1,4 +1,6 @@ defmodule Paginator.Ecto.Query.AscNullsFirst do + @moduledoc false + @behaviour Paginator.Ecto.Query.DynamicFilterBuilder import Ecto.Query diff --git a/lib/paginator/ecto/query/asc_nulls_last.ex b/lib/paginator/ecto/query/asc_nulls_last.ex index 451f740..c91fb06 100644 --- a/lib/paginator/ecto/query/asc_nulls_last.ex +++ b/lib/paginator/ecto/query/asc_nulls_last.ex @@ -1,4 +1,6 @@ defmodule Paginator.Ecto.Query.AscNullsLast do + @moduledoc false + @behaviour Paginator.Ecto.Query.DynamicFilterBuilder import Ecto.Query diff --git a/lib/paginator/ecto/query/desc_nulls_first.ex b/lib/paginator/ecto/query/desc_nulls_first.ex index e11ba36..462b134 100644 --- a/lib/paginator/ecto/query/desc_nulls_first.ex +++ b/lib/paginator/ecto/query/desc_nulls_first.ex @@ -1,4 +1,6 @@ defmodule Paginator.Ecto.Query.DescNullsFirst do + @moduledoc false + @behaviour Paginator.Ecto.Query.DynamicFilterBuilder import Ecto.Query diff --git a/lib/paginator/ecto/query/desc_nulls_last.ex b/lib/paginator/ecto/query/desc_nulls_last.ex index d108831..9a6f52f 100644 --- a/lib/paginator/ecto/query/desc_nulls_last.ex +++ b/lib/paginator/ecto/query/desc_nulls_last.ex @@ -1,4 +1,6 @@ defmodule Paginator.Ecto.Query.DescNullsLast do + @moduledoc false + @behaviour Paginator.Ecto.Query.DynamicFilterBuilder import Ecto.Query diff --git a/lib/paginator/ecto/query/dynamic_filter_builder.ex b/lib/paginator/ecto/query/dynamic_filter_builder.ex index a1b6a70..5d3d1d1 100644 --- a/lib/paginator/ecto/query/dynamic_filter_builder.ex +++ b/lib/paginator/ecto/query/dynamic_filter_builder.ex @@ -1,4 +1,6 @@ defmodule Paginator.Ecto.Query.DynamicFilterBuilder do + @moduledoc false + @dispatch_table %{ desc: Paginator.Ecto.Query.DescNullsFirst, desc_nulls_first: Paginator.Ecto.Query.DescNullsFirst, @@ -13,9 +15,11 @@ defmodule Paginator.Ecto.Query.DynamicFilterBuilder do entity_position: integer(), column: term(), value: term(), - next_filters: Ecto.Query.dynamic() | boolean() + next_filters: dynamic_expr() | boolean() }) :: term() + @typep dynamic_expr :: %Ecto.Query.DynamicExpr{} + @type sort_order :: :asc | :asc_nulls_first @@ -32,20 +36,18 @@ defmodule Paginator.Ecto.Query.DynamicFilterBuilder do entity_position: integer(), column: term(), value: term(), - next_filters: Ecto.Query.dynamic() | boolean() + next_filters: dynamic_expr() | boolean() }) :: term() def build!(input) do case Map.fetch(@dispatch_table, input.sort_order) do {:ok, module} -> - apply(module, :build_dynamic_filter, [input]) + module.build_dynamic_filter(input) :error -> direction = input.direction - available_sort_orders = Map.keys(@dispatch_table) |> Enum.join(", ") + available_sort_orders = @dispatch_table |> Map.keys() |> Enum.join(", ") - raise( - "Invalid sorting value :#{direction}, please please use either #{available_sort_orders}" - ) + raise("Invalid sorting value :#{direction}, please please use either #{available_sort_orders}") end end end diff --git a/lib/paginator/ecto/query/field_or_expression.ex b/lib/paginator/ecto/query/field_or_expression.ex index 32d0000..189946c 100644 --- a/lib/paginator/ecto/query/field_or_expression.ex +++ b/lib/paginator/ecto/query/field_or_expression.ex @@ -1,4 +1,6 @@ defmodule Paginator.Ecto.Query.FieldOrExpression do + @moduledoc false + import Ecto.Query def field_or_expr_is_nil(%{column: {_, handler}}) do diff --git a/mix.exs b/mix.exs index e35f6c9..17e826c 100644 --- a/mix.exs +++ b/mix.exs @@ -1,25 +1,30 @@ defmodule Paginator.Mixfile do use Mix.Project - @source_url "https://github.com/duffelhq/paginator" + @source_url "https://github.com/stordco/paginator" @version "1.2.0" def project do [ app: :paginator, name: "Paginator", + description: "Cursor based pagination for Elixir Ecto", version: @version, elixir: "~> 1.5", - elixirc_options: [warnings_as_errors: System.get_env("CI") == "true"], elixirc_paths: elixirc_paths(Mix.env()), build_embedded: Mix.env() == :prod, start_permanent: Mix.env() == :prod, deps: deps(), - dialyzer: [ - plt_file: {:no_warn, "priv/plts/dialyzer.plt"} - ], + docs: docs(), package: package(), - docs: docs() + source_url: @source_url, + test_coverage: [tool: ExCoveralls], + preferred_cli_env: [ + coveralls: :test, + "coveralls.detail": :test, + "coveralls.html": :test, + "coveralls.circle": :test + ] ] end @@ -33,26 +38,28 @@ defmodule Paginator.Mixfile do defp deps do [ {:calendar, "~> 1.0.0", only: :test}, - {:dialyxir, "~> 1.0", only: [:dev], runtime: false}, + {:credo, "~> 1.7", only: [:dev, :test], runtime: false}, + {:dialyxir, "~> 1.4", only: [:dev], runtime: false}, {:ecto, "~> 3.0"}, {:ecto_sql, "~> 3.0"}, - {:ex_doc, "~> 0.18", only: :dev, runtime: false}, + {:excoveralls, "~> 0.18", only: :test}, + {:ex_doc, "~> 0.30", only: :dev, runtime: false}, {:ex_machina, "~> 2.1", only: :test}, - {:inch_ex, "~> 2.0", only: [:dev, :test]}, {:postgrex, "~> 0.13", optional: true}, - {:plug_crypto, "~> 1.2.0"} + {:plug_crypto, "~> 2.0.0"} ] end defp package do [ description: "Cursor based pagination for Elixir Ecto.", - maintainers: ["Steve Domin"], + maintainers: ["Steve Domin", "Stord, Inc."], licenses: ["MIT"], links: %{ - "Changelog" => "https://hexdocs.pm/paginator/changelog.html", + "Changelog" => "https://github.com/stordco/paginator/releases", "GitHub" => @source_url - } + }, + organization: "stord" ] end @@ -66,8 +73,7 @@ defmodule Paginator.Mixfile do main: "readme", canonical: "http://hexdocs.pm/paginator", source_url: @source_url, - source_ref: "v#{@version}", - formatters: ["html"] + source_ref: "v#{@version}" ] end end diff --git a/mix.lock b/mix.lock index 3924d80..074eff6 100644 --- a/mix.lock +++ b/mix.lock @@ -1,32 +1,33 @@ %{ - "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"}, - "calendar": {:hex, :calendar, "1.0.0", "f52073a708528482ec33d0a171954ca610fe2bd28f1e871f247dc7f1565fa807", [:mix], [{:tzdata, "~> 0.5.20 or ~> 0.1.201603 or ~> 1.0", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm", "990e9581920c82912a5ee50e62ff5ef96da6b15949a2ee4734f935fdef0f0a6f"}, - "certifi": {:hex, :certifi, "2.6.1", "dbab8e5e155a0763eea978c913ca280a6b544bfa115633fa20249c3d396d9493", [:rebar3], [], "hexpm", "524c97b4991b3849dd5c17a631223896272c6b0af446778ba4675a1dff53bb7e"}, - "connection": {:hex, :connection, "1.1.0", "ff2a49c4b75b6fb3e674bfc5536451607270aac754ffd1bdfe175abe4a6d7a68", [:mix], [], "hexpm", "722c1eb0a418fbe91ba7bd59a47e28008a189d47e37e0e7bb85585a016b2869c"}, - "db_connection": {:hex, :db_connection, "2.4.1", "6411f6e23f1a8b68a82fa3a36366d4881f21f47fc79a9efb8c615e62050219da", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ea36d226ec5999781a9a8ad64e5d8c4454ecedc7a4d643e4832bf08efca01f00"}, - "decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"}, - "dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"}, - "earmark_parser": {:hex, :earmark_parser, "1.4.20", "89970db71b11b6b89759ce16807e857df154f8df3e807b2920a8c39834a9e5cf", [:mix], [], "hexpm", "1eb0d2dabeeeff200e0d17dc3048a6045aab271f73ebb82e416464832eb57bdd"}, - "ecto": {:hex, :ecto, "3.6.2", "efdf52acfc4ce29249bab5417415bd50abd62db7b0603b8bab0d7b996548c2bc", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "efad6dfb04e6f986b8a3047822b0f826d9affe8e4ebdd2aeedbfcb14fd48884e"}, - "ecto_sql": {:hex, :ecto_sql, "3.6.2", "9526b5f691701a5181427634c30655ac33d11e17e4069eff3ae1176c764e0ba3", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.6.2", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.4.0 or ~> 0.5.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "5ec9d7e6f742ea39b63aceaea9ac1d1773d574ea40df5a53ef8afbd9242fdb6b"}, + "bunt": {:hex, :bunt, "0.2.1", "e2d4792f7bc0ced7583ab54922808919518d0e57ee162901a16a1b6664ef3b14", [:mix], [], "hexpm", "a330bfb4245239787b15005e66ae6845c9cd524a288f0d141c148b02603777a5"}, + "calendar": {:hex, :calendar, "1.0.0", "f52073a708528482ec33d0a171954ca610fe2bd28f1e871f247dc7f1565fa807", [:mix], [{:tzdata, "~> 0.1.201603 or ~> 0.5.20 or ~> 1.0", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm", "990e9581920c82912a5ee50e62ff5ef96da6b15949a2ee4734f935fdef0f0a6f"}, + "certifi": {:hex, :certifi, "2.12.0", "2d1cca2ec95f59643862af91f001478c9863c2ac9cb6e2f89780bfd8de987329", [:rebar3], [], "hexpm", "ee68d85df22e554040cdb4be100f33873ac6051387baf6a8f6ce82272340ff1c"}, + "credo": {:hex, :credo, "1.7.1", "6e26bbcc9e22eefbff7e43188e69924e78818e2fe6282487d0703652bc20fd62", [:mix], [{:bunt, "~> 0.2.1", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "e9871c6095a4c0381c89b6aa98bc6260a8ba6addccf7f6a53da8849c748a58a2"}, + "db_connection": {:hex, :db_connection, "2.5.0", "bb6d4f30d35ded97b29fe80d8bd6f928a1912ca1ff110831edcd238a1973652c", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c92d5ba26cd69ead1ff7582dbb860adeedfff39774105a4f1c92cbb654b55aa2"}, + "decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"}, + "dialyxir": {:hex, :dialyxir, "1.4.1", "a22ed1e7bd3a3e3f197b68d806ef66acb61ee8f57b3ac85fc5d57354c5482a93", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "84b795d6d7796297cca5a3118444b80c7d94f7ce247d49886e7c291e1ae49801"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.37", "2ad73550e27c8946648b06905a57e4d454e4d7229c2dafa72a0348c99d8be5f7", [:mix], [], "hexpm", "6b19783f2802f039806f375610faa22da130b8edc21209d0bff47918bb48360e"}, + "ecto": {:hex, :ecto, "3.10.3", "eb2ae2eecd210b4eb8bece1217b297ad4ff824b4384c0e3fdd28aaf96edd6135", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "44bec74e2364d491d70f7e42cd0d690922659d329f6465e89feb8a34e8cd3433"}, + "ecto_sql": {:hex, :ecto_sql, "3.10.2", "6b98b46534b5c2f8b8b5f03f126e75e2a73c64f3c071149d32987a5378b0fdbd", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.10.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.16.0 or ~> 0.17.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "68c018debca57cb9235e3889affdaec7a10616a4e3a80c99fa1d01fdafaa9007"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, - "ex_doc": {:hex, :ex_doc, "0.28.2", "e031c7d1a9fc40959da7bf89e2dc269ddc5de631f9bd0e326cbddf7d8085a9da", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "51ee866993ffbd0e41c084a7677c570d0fc50cb85c6b5e76f8d936d9587fa719"}, + "ex_doc": {:hex, :ex_doc, "0.30.6", "5f8b54854b240a2b55c9734c4b1d0dd7bdd41f71a095d42a70445c03cf05a281", [:mix], [{:earmark_parser, "~> 1.4.31", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "bd48f2ddacf4e482c727f9293d9498e0881597eae6ddc3d9562bd7923375109f"}, "ex_machina": {:hex, :ex_machina, "2.7.0", "b792cc3127fd0680fecdb6299235b4727a4944a09ff0fa904cc639272cd92dc7", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm", "419aa7a39bde11894c87a615c4ecaa52d8f107bbdd81d810465186f783245bf8"}, - "hackney": {:hex, :hackney, "1.17.4", "99da4674592504d3fb0cfef0db84c3ba02b4508bae2dff8c0108baa0d6e0977c", [:rebar3], [{:certifi, "~>2.6.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "de16ff4996556c8548d512f4dbe22dd58a587bf3332e7fd362430a7ef3986b16"}, - "idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"}, - "inch_ex": {:hex, :inch_ex, "2.0.0", "24268a9284a1751f2ceda569cd978e1fa394c977c45c331bb52a405de544f4de", [:mix], [{:bunt, "~> 0.2", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "96d0ec5ecac8cf63142d02f16b7ab7152cf0f0f1a185a80161b758383c9399a8"}, - "jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"}, + "excoveralls": {:hex, :excoveralls, "0.18.0", "b92497e69465dc51bc37a6422226ee690ab437e4c06877e836f1c18daeb35da9", [:mix], [{:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1109bb911f3cb583401760be49c02cbbd16aed66ea9509fc5479335d284da60b"}, + "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, + "hackney": {:hex, :hackney, "1.20.1", "8d97aec62ddddd757d128bfd1df6c5861093419f8f7a4223823537bad5d064e2", [:rebar3], [{:certifi, "~> 2.12.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "fe9094e5f1a2a2c0a7d10918fee36bfec0ec2a979994cff8cfe8058cd9af38e3"}, + "idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"}, + "jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"}, "makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"}, - "makeup_elixir": {:hex, :makeup_elixir, "0.15.2", "dc72dfe17eb240552857465cc00cce390960d9a0c055c4ccd38b70629227e97c", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "fd23ae48d09b32eff49d4ced2b43c9f086d402ee4fd4fcb2d7fad97fa8823e75"}, - "makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"}, + "makeup_erlang": {:hex, :makeup_erlang, "0.1.2", "ad87296a092a46e03b7e9b0be7631ddcf64c790fa68a9ef5323b6cbb36affc72", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f3f5a1ca93ce6e092d92b6d9c049bcda58a3b617a8d888f8e7231c85630e8108"}, "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"}, "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"}, - "nimble_parsec": {:hex, :nimble_parsec, "1.2.2", "b99ca56bbce410e9d5ee4f9155a212e942e224e259c7ebbf8f2c86ac21d4fa3c", [:mix], [], "hexpm", "98d51bd64d5f6a2a9c6bb7586ee8129e27dfaab1140b5a4753f24dac0ba27d2f"}, - "parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"}, - "plug_crypto": {:hex, :plug_crypto, "1.2.2", "05654514ac717ff3a1843204b424477d9e60c143406aa94daf2274fdd280794d", [:mix], [], "hexpm", "87631c7ad914a5a445f0a3809f99b079113ae4ed4b867348dd9eec288cecb6db"}, - "postgrex": {:hex, :postgrex, "0.15.13", "7794e697481799aee8982688c261901de493eb64451feee6ea58207d7266d54a", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "3ffb76e1a97cfefe5c6a95632a27ffb67f28871c9741fb585f9d1c3cd2af70f1"}, - "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"}, - "telemetry": {:hex, :telemetry, "0.4.3", "a06428a514bdbc63293cd9a6263aad00ddeb66f608163bdec7c8995784080818", [:rebar3], [], "hexpm", "eb72b8365ffda5bed68a620d1da88525e326cb82a75ee61354fc24b844768041"}, - "tzdata": {:hex, :tzdata, "1.1.0", "72f5babaa9390d0f131465c8702fa76da0919e37ba32baa90d93c583301a8359", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "18f453739b48d3dc5bcf0e8906d2dc112bb40baafe2c707596d89f3c8dd14034"}, + "nimble_parsec": {:hex, :nimble_parsec, "1.3.1", "2c54013ecf170e249e9291ed0a62e5832f70a476c61da16f6aac6dca0189f2af", [:mix], [], "hexpm", "2682e3c0b2eb58d90c6375fc0cc30bc7be06f365bf72608804fb9cffa5e1b167"}, + "parse_trans": {:hex, :parse_trans, "3.4.1", "6e6aa8167cb44cc8f39441d05193be6e6f4e7c2946cb2759f015f8c56b76e5ff", [:rebar3], [], "hexpm", "620a406ce75dada827b82e453c19cf06776be266f5a67cff34e1ef2cbb60e49a"}, + "plug_crypto": {:hex, :plug_crypto, "2.0.0", "77515cc10af06645abbfb5e6ad7a3e9714f805ae118fa1a70205f80d2d70fe73", [:mix], [], "hexpm", "53695bae57cc4e54566d993eb01074e4d894b65a3766f1c43e2c61a1b0f45ea9"}, + "postgrex": {:hex, :postgrex, "0.17.3", "c92cda8de2033a7585dae8c61b1d420a1a1322421df84da9a82a6764580c503d", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "946cf46935a4fdca7a81448be76ba3503cff082df42c6ec1ff16a4bdfbfb098d"}, + "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"}, + "telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"}, + "tzdata": {:hex, :tzdata, "1.1.1", "20c8043476dfda8504952d00adac41c6eda23912278add38edc140ae0c5bcc46", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "a69cec8352eafcd2e198dea28a34113b60fdc6cb57eb5ad65c10292a6ba89787"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"}, } diff --git a/test/paginator_test.exs b/test/paginator_test.exs index 8aafab6..c31250b 100644 --- a/test/paginator_test.exs +++ b/test/paginator_test.exs @@ -1,6 +1,10 @@ +# credo:disable-for-this-file Credo.Check.Refactor.AppendSingleItem defmodule PaginatorTest do use Paginator.DataCase - doctest Paginator + + # We exclude this test due to newer Elixir and OTP versions having + # different encoding results. + doctest Paginator, except: [{:cursor_for_record, 3}] alias Calendar.DateTime, as: DT @@ -13,15 +17,15 @@ defmodule PaginatorTest do } do opts = [cursor_fields: [:charged_at, :id], sort_direction: :asc, limit: 4] - page = payments_by_charged_at() |> Repo.paginate(opts) + page = Repo.paginate(payments_by_charged_at(), opts) assert to_ids(page.entries) == to_ids([p5, p4, p1, p6]) assert page.metadata.after == encode_cursor(%{charged_at: p6.charged_at, id: p6.id}) - page = payments_by_charged_at() |> Repo.paginate(opts ++ [after: page.metadata.after]) + page = Repo.paginate(payments_by_charged_at(), opts ++ [after: page.metadata.after]) assert to_ids(page.entries) == to_ids([p7, p3, p10, p2]) assert page.metadata.after == encode_cursor(%{charged_at: p2.charged_at, id: p2.id}) - page = payments_by_charged_at() |> Repo.paginate(opts ++ [after: page.metadata.after]) + page = Repo.paginate(payments_by_charged_at(), opts ++ [after: page.metadata.after]) assert to_ids(page.entries) == to_ids([p12, p8, p9, p11]) assert page.metadata.after == nil end @@ -31,7 +35,7 @@ defmodule PaginatorTest do } do opts = [cursor_fields: [:charged_at, :id], sort_direction: :asc, limit: 4] - page = payments_by_charged_at() |> Repo.paginate(opts) + page = Repo.paginate(payments_by_charged_at(), opts) assert to_ids(page.entries) == to_ids([p5, p4, p1, p6]) assert %{charged_at: charged_at, id: id} = Cursor.decode(page.metadata.after) assert charged_at == p6.charged_at @@ -39,7 +43,7 @@ defmodule PaginatorTest do legacy_cursor = encode_legacy_cursor([charged_at, id]) - page = payments_by_charged_at() |> Repo.paginate(opts ++ [after: legacy_cursor]) + page = Repo.paginate(payments_by_charged_at(), opts ++ [after: legacy_cursor]) assert to_ids(page.entries) == to_ids([p7, p3, p10, p2]) assert %{charged_at: charged_at, id: id} = Cursor.decode(page.metadata.after) assert charged_at == p2.charged_at @@ -47,7 +51,7 @@ defmodule PaginatorTest do legacy_cursor = encode_legacy_cursor([charged_at, id]) - page = payments_by_charged_at() |> Repo.paginate(opts ++ [after: legacy_cursor]) + page = Repo.paginate(payments_by_charged_at(), opts ++ [after: legacy_cursor]) assert to_ids(page.entries) == to_ids([p12, p8, p9, p11]) assert page.metadata.after == nil end @@ -58,17 +62,19 @@ defmodule PaginatorTest do opts = [cursor_fields: [:charged_at, :id], sort_direction: :asc, limit: 4] page = - payments_by_charged_at() - |> Repo.paginate(opts ++ [before: encode_cursor(%{charged_at: p11.charged_at, id: p11.id})]) + Repo.paginate( + payments_by_charged_at(), + opts ++ [before: encode_cursor(%{charged_at: p11.charged_at, id: p11.id})] + ) assert to_ids(page.entries) == to_ids([p2, p12, p8, p9]) assert page.metadata.before == encode_cursor(%{charged_at: p2.charged_at, id: p2.id}) - page = payments_by_charged_at() |> Repo.paginate(opts ++ [before: page.metadata.before]) + page = Repo.paginate(payments_by_charged_at(), opts ++ [before: page.metadata.before]) assert to_ids(page.entries) == to_ids([p6, p7, p3, p10]) assert page.metadata.before == encode_cursor(%{charged_at: p6.charged_at, id: p6.id}) - page = payments_by_charged_at() |> Repo.paginate(opts ++ [before: page.metadata.before]) + page = Repo.paginate(payments_by_charged_at(), opts ++ [before: page.metadata.before]) assert to_ids(page.entries) == to_ids([p5, p4, p1]) assert page.metadata.after == encode_cursor(%{charged_at: p1.charged_at, id: p1.id}) assert page.metadata.before == nil @@ -76,7 +82,8 @@ defmodule PaginatorTest do test "returns an empty page when there are no results" do page = - payments_by_status("failed") + "failed" + |> payments_by_status() |> Repo.paginate(cursor_fields: [:charged_at, :id], limit: 10) assert page.entries == [] @@ -89,8 +96,11 @@ defmodule PaginatorTest do payments: {p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_charged_at() - |> Repo.paginate(cursor_fields: [:charged_at, :id], sort_direction: :asc, limit: 50) + Repo.paginate(payments_by_charged_at(), + cursor_fields: [:charged_at, :id], + sort_direction: :asc, + limit: 50 + ) assert to_ids(entries) == to_ids([p5, p4, p1, p6, p7, p3, p10, p2, p12, p8, p9, p11]) assert metadata == %Metadata{after: nil, before: nil, limit: 50} @@ -100,8 +110,7 @@ defmodule PaginatorTest do payments: {p1, p2, p3, _p4, _p5, p6, p7, p8, p9, p10, _p11, p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_charged_at() - |> Repo.paginate( + Repo.paginate(payments_by_charged_at(), cursor_fields: [:charged_at, :id], sort_direction: :asc, before: encode_cursor(%{charged_at: p9.charged_at, id: p9.id}), @@ -121,8 +130,7 @@ defmodule PaginatorTest do payments: {_p1, p2, p3, _p4, _p5, _p6, _p7, p8, p9, p10, p11, p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_charged_at() - |> Repo.paginate( + Repo.paginate(payments_by_charged_at(), cursor_fields: [:charged_at, :id], sort_direction: :asc, after: encode_cursor(%{charged_at: p3.charged_at, id: p3.id}), @@ -142,8 +150,7 @@ defmodule PaginatorTest do payments: {_p1, p2, p3, _p4, _p5, _p6, _p7, p8, _p9, p10, _p11, p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_charged_at() - |> Repo.paginate( + Repo.paginate(payments_by_charged_at(), cursor_fields: [:charged_at, :id], sort_direction: :asc, after: encode_cursor(%{charged_at: p3.charged_at, id: p3.id}), @@ -164,7 +171,8 @@ defmodule PaginatorTest do payments: {p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_charged_at(:desc) + :desc + |> payments_by_charged_at() |> Repo.paginate(cursor_fields: [:charged_at, :id], sort_direction: :desc, limit: 50) assert to_ids(entries) == to_ids([p11, p9, p8, p12, p2, p10, p3, p7, p6, p1, p4, p5]) @@ -175,7 +183,8 @@ defmodule PaginatorTest do payments: {_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, p9, _p10, p11, _p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_charged_at(:desc) + :desc + |> payments_by_charged_at() |> Repo.paginate( cursor_fields: [:charged_at, :id], sort_direction: :desc, @@ -196,7 +205,8 @@ defmodule PaginatorTest do payments: {p1, p2, p3, _p4, _p5, p6, p7, p8, p9, p10, _p11, p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_charged_at(:desc) + :desc + |> payments_by_charged_at() |> Repo.paginate( cursor_fields: [:charged_at, :id], sort_direction: :desc, @@ -217,7 +227,8 @@ defmodule PaginatorTest do payments: {_p1, p2, p3, _p4, _p5, _p6, _p7, p8, p9, p10, _p11, p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_charged_at(:desc) + :desc + |> payments_by_charged_at() |> Repo.paginate( cursor_fields: [:charged_at, :id], sort_direction: :desc, @@ -239,8 +250,7 @@ defmodule PaginatorTest do payments: {_p1, _p2, _p3, _p4, p5, _p6, _p7, _p8, _p9, _p10, _p11, _p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_charged_at() - |> Repo.paginate( + Repo.paginate(payments_by_charged_at(), cursor_fields: [:charged_at, :id], sort_direction: :asc, before: encode_cursor(%{charged_at: p5.charged_at, id: p5.id}), @@ -255,8 +265,7 @@ defmodule PaginatorTest do payments: {_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9, _p10, p11, _p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_charged_at() - |> Repo.paginate( + Repo.paginate(payments_by_charged_at(), cursor_fields: [:charged_at, :id], sort_direction: :asc, after: encode_cursor(%{charged_at: p11.charged_at, id: p11.id}), @@ -271,7 +280,8 @@ defmodule PaginatorTest do payments: {_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9, _p10, p11, _p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_charged_at(:desc) + :desc + |> payments_by_charged_at() |> Repo.paginate( cursor_fields: [:charged_at, :id], sort_direction: :desc, @@ -287,7 +297,8 @@ defmodule PaginatorTest do payments: {_p1, _p2, _p3, _p4, p5, _p6, _p7, _p8, _p9, _p10, _p11, _p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_charged_at(:desc) + :desc + |> payments_by_charged_at() |> Repo.paginate( cursor_fields: [:charged_at, :id], sort_direction: :desc, @@ -306,13 +317,15 @@ defmodule PaginatorTest do payments: {_p1, _p2, _p3, _p4, p5, p6, p7, p8, _p9, _p10, _p11, _p12} } do %Page{entries: entries, metadata: metadata} = - customer_payments_by_charged_at_and_amount(c1) + c1 + |> customer_payments_by_charged_at_and_amount() |> Repo.paginate(cursor_fields: [:charged_at, :amount, :id], limit: 2) assert to_ids(entries) == to_ids([p5, p6]) %Page{entries: entries, metadata: _metadata} = - customer_payments_by_charged_at_and_amount(c1) + c1 + |> customer_payments_by_charged_at_and_amount() |> Repo.paginate( cursor_fields: [:charged_at, :amount, :id], limit: 2, @@ -327,11 +340,11 @@ defmodule PaginatorTest do payments: {_p1, _p2, _p3, _p4, _p5, p6, _p7, _p8, _p9, _p10, _p11, _p12} } do assert %Page{entries: [], metadata: _metadata} = - customer_payments_by_charged_at_and_amount(c1) + c1 + |> customer_payments_by_charged_at_and_amount() |> Repo.paginate( cursor_fields: [:amount, :charged_at, :id], - before: - encode_cursor(%{amount: p6.amount, charged_at: p6.charged_at, id: p6.id}), + before: encode_cursor(%{amount: p6.amount, charged_at: p6.charged_at, id: p6.id}), limit: 1 ) end @@ -345,8 +358,7 @@ defmodule PaginatorTest do "Could not find binding `bogus_binding` in query aliases: %{customer: 1, payments: 0}", fn -> %Page{} = - payments_by_customer_name() - |> Repo.paginate( + Repo.paginate(payments_by_customer_name(), cursor_fields: [ {{:bogus_binding, :id}, :asc}, {{:bogus_binding, :name}, :asc} @@ -365,8 +377,7 @@ defmodule PaginatorTest do payments: {_p1, _p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, _p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_customer_name() - |> Repo.paginate( + Repo.paginate(payments_by_customer_name(), cursor_fields: [{:id, :asc}, {{:customer, :name}, :asc}], before: encode_cursor(%{:id => p11.id, {:customer, :name} => p11.customer.name}), limit: 8 @@ -385,8 +396,7 @@ defmodule PaginatorTest do payments: {_p1, _p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, _p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_customer_name() - |> Repo.paginate( + Repo.paginate(payments_by_customer_name(), cursor_fields: [:id, {{:customer, :name}, :asc}], before: encode_cursor(%{:id => p11.id, {:customer, :name} => p11.customer.name}), limit: 8 @@ -405,8 +415,7 @@ defmodule PaginatorTest do payments: {p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_customer_name() - |> Repo.paginate( + Repo.paginate(payments_by_customer_name(), cursor_fields: [{{:payments, :id}, :asc}, {{:customer, :name}, :asc}], limit: 50 ) @@ -419,11 +428,9 @@ defmodule PaginatorTest do payments: {_p1, _p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, _p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_customer_name() - |> Repo.paginate( + Repo.paginate(payments_by_customer_name(), cursor_fields: [{{:payments, :id}, :asc}, {{:customer, :name}, :asc}], - before: - encode_cursor(%{{:payments, :id} => p11.id, {:customer, :name} => p11.customer.name}), + before: encode_cursor(%{{:payments, :id} => p11.id, {:customer, :name} => p11.customer.name}), limit: 8 ) @@ -448,11 +455,9 @@ defmodule PaginatorTest do payments: {_p1, _p2, _p3, _p4, _p5, p6, p7, p8, p9, p10, p11, p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_customer_name() - |> Repo.paginate( + Repo.paginate(payments_by_customer_name(), cursor_fields: [{{:payments, :id}, :asc}, {{:customer, :name}, :asc}], - after: - encode_cursor(%{{:payments, :id} => p6.id, {:customer, :name} => p6.customer.name}), + after: encode_cursor(%{{:payments, :id} => p6.id, {:customer, :name} => p6.customer.name}), limit: 8 ) @@ -473,13 +478,10 @@ defmodule PaginatorTest do payments: {_p1, _p2, _p3, _p4, _p5, p6, p7, p8, p9, p10, _p11, _p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_customer_name() - |> Repo.paginate( + Repo.paginate(payments_by_customer_name(), cursor_fields: [{{:payments, :id}, :asc}, {{:customer, :name}, :asc}], - after: - encode_cursor(%{{:payments, :id} => p6.id, {:customer, :name} => p6.customer.name}), - before: - encode_cursor(%{{:payments, :id} => p10.id, {:customer, :name} => p10.customer.name}), + after: encode_cursor(%{{:payments, :id} => p6.id, {:customer, :name} => p6.customer.name}), + before: encode_cursor(%{{:payments, :id} => p10.id, {:customer, :name} => p10.customer.name}), limit: 8 ) @@ -504,7 +506,8 @@ defmodule PaginatorTest do payments: {p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_customer_name(:desc, :desc) + :desc + |> payments_by_customer_name(:desc) |> Repo.paginate( cursor_fields: [{{:payments, :id}, :desc}, {{:customer, :name}, :desc}], limit: 50 @@ -518,11 +521,11 @@ defmodule PaginatorTest do payments: {_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9, _p10, p11, p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_customer_name(:desc) + :desc + |> payments_by_customer_name() |> Repo.paginate( cursor_fields: [{{:payments, :id}, :desc}, {{:customer, :name}, :desc}], - before: - encode_cursor(%{{:payments, :id} => p11.id, {:customer, :name} => p11.customer.name}), + before: encode_cursor(%{{:payments, :id} => p11.id, {:customer, :name} => p11.customer.name}), limit: 8 ) @@ -543,12 +546,12 @@ defmodule PaginatorTest do payments: {_p1, _p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, _p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_customer_name(:desc, :desc) + :desc + |> payments_by_customer_name(:desc) |> Repo.paginate( cursor_fields: [{{:payments, :id}, :desc}, {{:customer, :name}, :desc}], sort_direction: :desc, - after: - encode_cursor(%{{:payments, :id} => p11.id, {:customer, :name} => p11.customer.name}), + after: encode_cursor(%{{:payments, :id} => p11.id, {:customer, :name} => p11.customer.name}), limit: 8 ) @@ -573,13 +576,12 @@ defmodule PaginatorTest do payments: {_p1, _p2, _p3, _p4, _p5, p6, p7, p8, p9, p10, p11, _p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_customer_name(:desc, :desc) + :desc + |> payments_by_customer_name(:desc) |> Repo.paginate( cursor_fields: [{{:payments, :id}, :desc}, {{:customer, :name}, :desc}], - after: - encode_cursor(%{{:payments, :id} => p11.id, {:customer, :name} => p11.customer.name}), - before: - encode_cursor(%{{:payments, :id} => p6.id, {:customer, :name} => p6.customer.name}), + after: encode_cursor(%{{:payments, :id} => p11.id, {:customer, :name} => p11.customer.name}), + before: encode_cursor(%{{:payments, :id} => p6.id, {:customer, :name} => p6.customer.name}), limit: 8 ) @@ -604,11 +606,9 @@ defmodule PaginatorTest do payments: {p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9, _p10, _p11, _p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_customer_name() - |> Repo.paginate( + Repo.paginate(payments_by_customer_name(), cursor_fields: [{{:payments, :id}, :asc}, {{:customer, :name}, :asc}], - before: - encode_cursor(%{{:payments, :id} => p1.id, {:customer, :name} => p1.customer.name}), + before: encode_cursor(%{{:payments, :id} => p1.id, {:customer, :name} => p1.customer.name}), limit: 8 ) @@ -620,11 +620,9 @@ defmodule PaginatorTest do payments: {_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9, _p10, _p11, p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_customer_name() - |> Repo.paginate( + Repo.paginate(payments_by_customer_name(), cursor_fields: [{{:payments, :id}, :asc}, {{:customer, :name}, :asc}], - after: - encode_cursor(%{{:payments, :id} => p12.id, {:customer, :name} => p12.customer.name}), + after: encode_cursor(%{{:payments, :id} => p12.id, {:customer, :name} => p12.customer.name}), limit: 8 ) @@ -636,11 +634,11 @@ defmodule PaginatorTest do payments: {_p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9, _p10, _p11, p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_customer_name(:desc, :desc) + :desc + |> payments_by_customer_name(:desc) |> Repo.paginate( cursor_fields: [{{:payments, :id}, :desc}, {{:customer, :name}, :desc}], - before: - encode_cursor(%{{:payments, :id} => p12.id, {:customer, :name} => p12.customer.name}), + before: encode_cursor(%{{:payments, :id} => p12.id, {:customer, :name} => p12.customer.name}), limit: 8 ) @@ -652,11 +650,11 @@ defmodule PaginatorTest do payments: {p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9, _p10, _p11, _p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_customer_name(:desc, :desc) + :desc + |> payments_by_customer_name(:desc) |> Repo.paginate( cursor_fields: [{{:payments, :id}, :desc}, {{:customer, :name}, :desc}], - after: - encode_cursor(%{{:payments, :id} => p1.id, {:customer, :name} => p1.customer.name}), + after: encode_cursor(%{{:payments, :id} => p1.id, {:customer, :name} => p1.customer.name}), limit: 8 ) @@ -668,8 +666,7 @@ defmodule PaginatorTest do payments: {_p1, _p2, _p3, _p4, p5, p6, p7, _p8, _p9, _p10, _p11, _p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_address_city() - |> Repo.paginate( + Repo.paginate(payments_by_address_city(), cursor_fields: [{{:address, :city}, :asc}, id: :asc], before: nil, limit: 3, @@ -687,8 +684,7 @@ defmodule PaginatorTest do p7 = Repo.preload(p7, customer: :address) assert metadata == %Metadata{ - after: - encode_cursor(%{{:address, :city} => p7.customer.address.city, :id => p7.id}), + after: encode_cursor(%{{:address, :city} => p7.customer.address.city, :id => p7.id}), before: nil, limit: 3 } @@ -698,7 +694,8 @@ defmodule PaginatorTest do payments: {_p1, _p2, _p3, _p4, _p5, _p6, p7, _p8, _p9, _p10, p11, _p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_charged_at(:desc) + :desc + |> payments_by_charged_at() |> Repo.paginate( cursor_fields: [:charged_at, :id], sort_direction: :desc, @@ -720,8 +717,7 @@ defmodule PaginatorTest do payments: {p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_customer_name() - |> Repo.paginate(cursor_fields: [:id], sort_direction: :asc) + Repo.paginate(payments_by_customer_name(), cursor_fields: [:id], sort_direction: :asc) assert to_ids(entries) == to_ids([p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12]) assert metadata == %Metadata{after: nil, before: nil, limit: 50} @@ -731,8 +727,11 @@ defmodule PaginatorTest do payments: {p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8, _p9, _p10, _p11, _p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_customer_name() - |> Repo.paginate(cursor_fields: [:id], sort_direction: :asc, limit: 0) + Repo.paginate(payments_by_customer_name(), + cursor_fields: [:id], + sort_direction: :asc, + limit: 0 + ) assert to_ids(entries) == to_ids([p1]) assert metadata == %Metadata{after: encode_cursor(%{id: p1.id}), before: nil, limit: 1} @@ -743,8 +742,7 @@ defmodule PaginatorTest do payments: {_p1, _p2, _p3, _p4, p5, _p6, _p7, _p8, _p9, _p10, _p11, _p12} } do %Page{metadata: metadata} = - payments_by_customer_name() - |> Repo.paginate( + Repo.paginate(payments_by_customer_name(), cursor_fields: [:id], sort_direction: :asc, limit: 5, @@ -765,8 +763,7 @@ defmodule PaginatorTest do payments: {_p1, _p2, _p3, _p4, p5, _p6, _p7, _p8, _p9, _p10, _p11, _p12} } do %Page{metadata: metadata} = - payments_by_customer_name() - |> Repo.paginate( + Repo.paginate(payments_by_customer_name(), cursor_fields: [:id], sort_direction: :asc, limit: 5, @@ -786,8 +783,7 @@ defmodule PaginatorTest do payments: {_p1, _p2, _p3, _p4, p5, _p6, _p7, _p8, _p9, _p10, _p11, _p12} } do %Page{metadata: metadata} = - payments_by_customer_name() - |> Repo.paginate( + Repo.paginate(payments_by_customer_name(), cursor_fields: [:id], sort_direction: :asc, limit: 5, @@ -807,6 +803,7 @@ defmodule PaginatorTest do test "when custom total_count_primary_key_field", %{ addresses: {_a1, a2, _a3} } do + # credo:disable-for-lines:9 /Pipe/ %Page{metadata: metadata} = from(a in Address, select: a) |> Repo.paginate( @@ -844,7 +841,8 @@ defmodule PaginatorTest do |> Base.url_encode64() assert_raise(ArgumentError, ~r/^cannot deserialize.+/, fn -> - payments_by_amount_and_charged_at(:asc, :desc) + :asc + |> payments_by_amount_and_charged_at(:desc) |> Repo.paginate( cursor_fields: [amount: :asc, charged_at: :desc, id: :asc], before: payload, @@ -879,7 +877,8 @@ defmodule PaginatorTest do payments: {_p1, _p2, _p3, p4, p5, p6, p7, _p8, _p9, _p10, _p11, _p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_amount_and_charged_at(:asc, :desc) + :asc + |> payments_by_amount_and_charged_at(:desc) |> Repo.paginate( cursor_fields: [amount: :asc, charged_at: :desc, id: :asc], before: encode_cursor(%{amount: p7.amount, charged_at: p7.charged_at, id: p7.id}), @@ -899,7 +898,8 @@ defmodule PaginatorTest do payments: {_p1, _p2, _p3, p4, p5, _p6, p7, p8, _p9, _p10, _p11, _p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_amount_and_charged_at(:asc, :desc) + :asc + |> payments_by_amount_and_charged_at(:desc) |> Repo.paginate( cursor_fields: [amount: :asc, charged_at: :desc, id: :asc], after: encode_cursor(%{amount: p4.amount, charged_at: p4.charged_at, id: p4.id}), @@ -919,7 +919,8 @@ defmodule PaginatorTest do payments: {_p1, _p2, _p3, p4, p5, p6, p7, p8, _p9, _p10, _p11, _p12} } do %Page{entries: entries, metadata: metadata} = - payments_by_amount_and_charged_at(:desc, :asc) + :desc + |> payments_by_amount_and_charged_at(:asc) |> Repo.paginate( cursor_fields: [amount: :desc, charged_at: :asc, id: :asc], after: encode_cursor(%{amount: p8.amount, charged_at: p8.charged_at, id: p8.id}), @@ -1129,14 +1130,11 @@ defmodule PaginatorTest do p12 = insert(:payment, customer: c3, charged_at: days_ago(5)) {:ok, - customers: {c1, c2, c3}, - addresses: {a1, a2, a3}, - payments: {p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12}} + customers: {c1, c2, c3}, addresses: {a1, a2, a3}, payments: {p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12}} end defp create_customers_with_similar_names(base_customer_name) do - 1..10 - |> Enum.map(fn i -> + Enum.map(1..10, fn i -> {:ok, %{rows: [[rank_value]]}} = Repo.query( "SELECT ts_rank(setweight(to_tsvector('simple', $1), 'A'), plainto_tsquery('simple', $2))", @@ -1255,7 +1253,7 @@ defmodule PaginatorTest do end defp days_ago(days) do - DT.add!(DateTime.utc_now(), -(days * 86400)) + DT.add!(DateTime.utc_now(), -(days * 86_400)) end defp paginate_as_list(query, opts, mapf \\ &to_ids(&1.entries)) do @@ -1285,7 +1283,8 @@ defmodule PaginatorTest do [nil] before_cursor -> - Repo.paginate(query, Keyword.put(opts, :before, before_cursor)) + query + |> Repo.paginate(Keyword.put(opts, :before, before_cursor)) |> Map.fetch!(:entries) |> to_ids end) diff --git a/test/support/customer.ex b/test/support/customer.ex index 3c4ad61..5c1e070 100644 --- a/test/support/customer.ex +++ b/test/support/customer.ex @@ -16,6 +16,6 @@ defmodule Paginator.Customer do end def active(query) do - query |> where([c], c.active == true) + where(query, [c], c.active == true) end end diff --git a/test/support/data_case.ex b/test/support/data_case.ex index 156305a..320fdad 100644 --- a/test/support/data_case.ex +++ b/test/support/data_case.ex @@ -9,8 +9,7 @@ defmodule Paginator.DataCase do import Ecto.Query import Paginator.Factory - alias Paginator.{Page, Page.Metadata} - alias Paginator.{Customer, Address, Payment} + alias Paginator.{Address, Customer, Page, Page.Metadata, Payment} end end diff --git a/test/support/factory.ex b/test/support/factory.ex index 5151e70..974bd90 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -1,7 +1,7 @@ defmodule Paginator.Factory do use ExMachina.Ecto, repo: Paginator.Repo - alias Paginator.{Customer, Address, Payment} + alias Paginator.{Address, Customer, Payment} def customer_factory do %Customer{ diff --git a/test/support/payment.ex b/test/support/payment.ex index 940921e..7d55615 100644 --- a/test/support/payment.ex +++ b/test/support/payment.ex @@ -15,10 +15,10 @@ defmodule Paginator.Payment do end def successful(query) do - query |> where([p], p.status == "success") + where(query, [p], p.status == "success") end def failed(query) do - query |> where([p], p.status == "failed") + where(query, [p], p.status == "failed") end end