Skip to content

Commit 5412526

Browse files
committed
feat: add tests for is_distinct_from operators
Add comprehensive integration tests for is_distinct_from and is_not_distinct_from operators with PostgreSQL. - Test is_distinct_from with nil values - Test is_not_distinct_from with nil values - Test is_distinct_from with non-nil values - Test is_not_distinct_from with non-nil values Tests verify that NULL-safe comparisons work correctly in PostgreSQL queries. Related to ash-project/ash#2493
1 parent ce42897 commit 5412526

File tree

3 files changed

+114
-13
lines changed

3 files changed

+114
-13
lines changed

mix.exs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,6 @@ defmodule AshPostgres.MixProject do
2121
description: @description,
2222
elixirc_paths: elixirc_paths(Mix.env()),
2323
consolidate_protocols: Mix.env() == :prod,
24-
preferred_cli_env: [
25-
coveralls: :test,
26-
"coveralls.github": :test,
27-
"test.create": :test,
28-
"test.migrate": :test,
29-
"test.rollback": :test,
30-
"test.migrate_tenants": :test,
31-
"test.check_migrations": :test,
32-
"test.drop": :test,
33-
"test.generate_migrations": :test,
34-
"test.reset": :test
35-
],
3624
dialyzer: [
3725
plt_add_apps: [:ecto, :ash, :mix]
3826
],
@@ -264,4 +252,21 @@ defmodule AshPostgres.MixProject do
264252
"test.drop": "ash_postgres.drop"
265253
]
266254
end
255+
256+
def cli do
257+
[
258+
preferred_envs: [
259+
coveralls: :test,
260+
"coveralls.github": :test,
261+
"test.create": :test,
262+
"test.migrate": :test,
263+
"test.rollback": :test,
264+
"test.migrate_tenants": :test,
265+
"test.check_migrations": :test,
266+
"test.drop": :test,
267+
"test.generate_migrations": :test,
268+
"test.reset": :test
269+
]
270+
]
271+
end
267272
end

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"earmark_parser": {:hex, :earmark_parser, "1.4.44", "f20830dd6b5c77afe2b063777ddbbff09f9759396500cdbe7523efd58d7a339c", [:mix], [], "hexpm", "4778ac752b4701a5599215f7030989c989ffdc4f6df457c5f36938cc2d2a2750"},
1313
"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"},
1414
"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"},
15-
"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"},
15+
"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"},
1616
"eflame": {:hex, :eflame, "1.0.1", "0664d287e39eef3c413749254b3af5f4f8b00be71c1af67d325331c4890be0fc", [:mix], [], "hexpm", "e0b08854a66f9013129de0b008488f3411ae9b69b902187837f994d7a99cf04e"},
1717
"erlex": {:hex, :erlex, "0.2.8", "cd8116f20f3c0afe376d1e8d1f0ae2452337729f68be016ea544a72f767d9c12", [:mix], [], "hexpm", "9d66ff9fedf69e49dc3fd12831e12a8a37b76f8651dd21cd45fcf5561a8a7590"},
1818
"ets": {:hex, :ets, "0.9.0", "79c6a6c205436780486f72d84230c6cba2f8a9920456750ddd1e47389107d5fd", [:mix], [], "hexpm", "2861fdfb04bcaeff370f1a5904eec864f0a56dcfebe5921ea9aadf2a481c822b"},

test/filter_test.exs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,102 @@ defmodule AshPostgres.FilterTest do
917917
end
918918
end
919919

920+
describe "is_distinct_from/2 and is_not_distinct_from/2" do
921+
setup do
922+
post_with_nil =
923+
Post
924+
|> Ash.Changeset.for_create(:create, %{title: "post_nil", category: nil})
925+
|> Ash.create!()
926+
927+
post_with_tech =
928+
Post
929+
|> Ash.Changeset.for_create(:create, %{title: "post_tech", category: "tech"})
930+
|> Ash.create!()
931+
932+
%{post_with_nil: post_with_nil, post_with_tech: post_with_tech}
933+
end
934+
935+
test "is_distinct_from with nil", %{post_with_tech: post_with_tech} do
936+
results =
937+
Post
938+
|> Ash.Query.filter(is_distinct_from(category, nil))
939+
|> Ash.read!()
940+
941+
assert length(results) == 1
942+
assert hd(results).id == post_with_tech.id
943+
end
944+
945+
test "is_not_distinct_from with nil", %{post_with_nil: post_with_nil} do
946+
results =
947+
Post
948+
|> Ash.Query.filter(is_not_distinct_from(category, nil))
949+
|> Ash.read!()
950+
951+
assert length(results) == 1
952+
assert hd(results).id == post_with_nil.id
953+
end
954+
955+
test "is_distinct_from with value", %{post_with_nil: post_with_nil} do
956+
results =
957+
Post
958+
|> Ash.Query.filter(is_distinct_from(category, "tech"))
959+
|> Ash.read!()
960+
961+
assert length(results) == 1
962+
assert hd(results).id == post_with_nil.id
963+
end
964+
965+
test "is_not_distinct_from with value", %{post_with_tech: post_with_tech} do
966+
results =
967+
Post
968+
|> Ash.Query.filter(is_not_distinct_from(category, "tech"))
969+
|> Ash.read!()
970+
971+
assert length(results) == 1
972+
assert hd(results).id == post_with_tech.id
973+
end
974+
975+
test "is_distinct_from with literal values" do
976+
# Should return all posts since "tech" is distinct from "news"
977+
results =
978+
Post
979+
|> Ash.Query.filter(is_distinct_from("tech", "news"))
980+
|> Ash.read!()
981+
982+
assert length(results) == 2
983+
end
984+
985+
test "is_not_distinct_from with literal values" do
986+
# Should return no posts since "tech" is not equal to "news"
987+
results =
988+
Post
989+
|> Ash.Query.filter(is_not_distinct_from("tech", "news"))
990+
|> Ash.read!()
991+
992+
assert length(results) == 0
993+
end
994+
995+
test "is_not_distinct_from with same literal values" do
996+
# Should return all posts since "tech" equals "tech"
997+
results =
998+
Post
999+
|> Ash.Query.filter(is_not_distinct_from("tech", "tech"))
1000+
|> Ash.read!()
1001+
1002+
assert length(results) == 2
1003+
end
1004+
1005+
test "is_not_distinct_from with nil literals" do
1006+
# Should return all posts since nil is not distinct from nil
1007+
results =
1008+
Post
1009+
|> Ash.Query.filter(is_not_distinct_from(nil, nil))
1010+
|> Ash.read!()
1011+
1012+
assert length(results) == 2
1013+
end
1014+
end
1015+
9201016
describe "like and ilike" do
9211017
test "like builds and matches" do
9221018
Post

0 commit comments

Comments
 (0)