diff --git a/mix.exs b/mix.exs index 03b4752d..8f8c852f 100644 --- a/mix.exs +++ b/mix.exs @@ -21,18 +21,6 @@ defmodule AshPostgres.MixProject do description: @description, elixirc_paths: elixirc_paths(Mix.env()), consolidate_protocols: Mix.env() == :prod, - preferred_cli_env: [ - coveralls: :test, - "coveralls.github": :test, - "test.create": :test, - "test.migrate": :test, - "test.rollback": :test, - "test.migrate_tenants": :test, - "test.check_migrations": :test, - "test.drop": :test, - "test.generate_migrations": :test, - "test.reset": :test - ], dialyzer: [ plt_add_apps: [:ecto, :ash, :mix] ], @@ -264,4 +252,21 @@ defmodule AshPostgres.MixProject do "test.drop": "ash_postgres.drop" ] end + + def cli do + [ + preferred_envs: [ + coveralls: :test, + "coveralls.github": :test, + "test.create": :test, + "test.migrate": :test, + "test.rollback": :test, + "test.migrate_tenants": :test, + "test.check_migrations": :test, + "test.drop": :test, + "test.generate_migrations": :test, + "test.reset": :test + ] + ] + end end diff --git a/mix.lock b/mix.lock index 4be45fd0..909f0618 100644 --- a/mix.lock +++ b/mix.lock @@ -12,7 +12,7 @@ "earmark_parser": {:hex, :earmark_parser, "1.4.44", "f20830dd6b5c77afe2b063777ddbbff09f9759396500cdbe7523efd58d7a339c", [:mix], [], "hexpm", "4778ac752b4701a5599215f7030989c989ffdc4f6df457c5f36938cc2d2a2750"}, "ecto": {:hex, :ecto, "3.13.5", "9d4a69700183f33bf97208294768e561f5c7f1ecf417e0fa1006e4a91713a834", [:mix], [{:decimal, "~> 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", "df9efebf70cf94142739ba357499661ef5dbb559ef902b68ea1f3c1fabce36de"}, "ecto_dev_logger": {:hex, :ecto_dev_logger, "0.15.0", "df5a997ffb17dca9011556857a0f5b7d8cd53ca7c452ef98828664b6e48d4400", [:mix], [{:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:geo, "~> 3.5 or ~> 4.0", [hex: :geo, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.17", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm", "b2c807d7d599a4fcf288139851c09262333b193bdb41f8d65f515853d117e88a"}, - "ecto_sql": {:hex, :ecto_sql, "3.13.3", "81f7067dd1951081888529002dbc71f54e5e891b69c60195040ea44697e1104a", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.13.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.7", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.19 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", "5751caea36c8f5dd0d1de6f37eceffea19d10bd53f20e5bbe31c45f2efc8944a"}, + "ecto_sql": {:hex, :ecto_sql, "3.13.4", "b6e9d07557ddba62508a9ce4a484989a5bb5e9a048ae0e695f6d93f095c25d60", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.13.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.7", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.19 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", "2b38cf0749ca4d1c5a8bcbff79bbe15446861ca12a61f9fba604486cb6b62a14"}, "eflame": {:hex, :eflame, "1.0.1", "0664d287e39eef3c413749254b3af5f4f8b00be71c1af67d325331c4890be0fc", [:mix], [], "hexpm", "e0b08854a66f9013129de0b008488f3411ae9b69b902187837f994d7a99cf04e"}, "erlex": {:hex, :erlex, "0.2.8", "cd8116f20f3c0afe376d1e8d1f0ae2452337729f68be016ea544a72f767d9c12", [:mix], [], "hexpm", "9d66ff9fedf69e49dc3fd12831e12a8a37b76f8651dd21cd45fcf5561a8a7590"}, "ets": {:hex, :ets, "0.9.0", "79c6a6c205436780486f72d84230c6cba2f8a9920456750ddd1e47389107d5fd", [:mix], [], "hexpm", "2861fdfb04bcaeff370f1a5904eec864f0a56dcfebe5921ea9aadf2a481c822b"}, diff --git a/test/filter_test.exs b/test/filter_test.exs index 5492864b..e8b076b0 100644 --- a/test/filter_test.exs +++ b/test/filter_test.exs @@ -917,6 +917,53 @@ defmodule AshPostgres.FilterTest do end end + describe "is_distinct_from/2 and is_not_distinct_from/2" do + setup do + nil_post = Post |> Ash.Changeset.for_create(:create, %{category: nil}) |> Ash.create!() + tech_post = Post |> Ash.Changeset.for_create(:create, %{category: "tech"}) |> Ash.create!() + %{nil_post: nil_post, tech_post: tech_post} + end + + test "column compared to nil", %{nil_post: nil_post, tech_post: tech_post} do + assert [result] = Post |> Ash.Query.filter(is_distinct_from(category, nil)) |> Ash.read!() + assert result.id == tech_post.id + + assert [result] = + Post |> Ash.Query.filter(is_not_distinct_from(category, nil)) |> Ash.read!() + + assert result.id == nil_post.id + end + + test "column compared to value", %{nil_post: nil_post, tech_post: tech_post} do + assert [result] = + Post |> Ash.Query.filter(is_distinct_from(category, "tech")) |> Ash.read!() + + assert result.id == nil_post.id + + assert [result] = + Post |> Ash.Query.filter(is_not_distinct_from(category, "tech")) |> Ash.read!() + + assert result.id == tech_post.id + end + + test "literal comparisons" do + assert [] = Post |> Ash.Query.filter(is_distinct_from("tech", "tech")) |> Ash.read!() + assert [] = Post |> Ash.Query.filter(is_distinct_from(nil, nil)) |> Ash.read!() + assert [] = Post |> Ash.Query.filter(is_not_distinct_from("tech", "news")) |> Ash.read!() + + all_posts = Post |> Ash.read!() + + assert length(Post |> Ash.Query.filter(is_distinct_from("tech", "news")) |> Ash.read!()) == + length(all_posts) + + assert length(Post |> Ash.Query.filter(is_not_distinct_from("tech", "tech")) |> Ash.read!()) == + length(all_posts) + + assert length(Post |> Ash.Query.filter(is_not_distinct_from(nil, nil)) |> Ash.read!()) == + length(all_posts) + end + end + describe "like and ilike" do test "like builds and matches" do Post