Skip to content

Commit b2216c4

Browse files
committed
test: add tests for ash_sql fix for exists paths in calculations
chore: update ash
1 parent 39475a7 commit b2216c4

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
%{
2-
"ash": {:hex, :ash, "3.7.0", "711b9eb200f81e0a071e8fe52272fde27e3548a5f3d30589dfcf23eaf34b0d12", [:mix], [{:crux, "~> 0.1.0", [hex: :crux, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8", [hex: :ets, repo: "hexpm", optional: false]}, {:igniter, ">= 0.6.29 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: true]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:reactor, "~> 0.11", [hex: :reactor, repo: "hexpm", optional: false]}, {:simple_sat, ">= 0.1.1 and < 1.0.0-0", [hex: :simple_sat, repo: "hexpm", optional: true]}, {:spark, ">= 2.3.3 and < 3.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, ">= 0.2.6 and < 1.0.0-0", [hex: :splode, repo: "hexpm", optional: false]}, {:stream_data, "~> 1.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "2581e3e2ad21aff8157b25c0f58c884524bee8d06ae8dc94d38ef0b8ae67b2a3"},
2+
"ash": {:hex, :ash, "3.7.1", "abb55dee19e0959e529e52fe0622468825ae05400f535484919713e492d9a9e7", [:mix], [{:crux, "~> 0.1.0", [hex: :crux, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8", [hex: :ets, repo: "hexpm", optional: false]}, {:igniter, ">= 0.6.29 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: true]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:reactor, "~> 0.11", [hex: :reactor, repo: "hexpm", optional: false]}, {:simple_sat, ">= 0.1.1 and < 1.0.0-0", [hex: :simple_sat, repo: "hexpm", optional: true]}, {:spark, ">= 2.3.3 and < 3.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, ">= 0.2.6 and < 1.0.0-0", [hex: :splode, repo: "hexpm", optional: false]}, {:stream_data, "~> 1.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "4474ce9befe9862d1ed73cadf8a755e836c45a14a7b3b952d02e1a12f2b2e529"},
33
"ash_sql": {:hex, :ash_sql, "0.3.7", "80affa5446075d71deb157c67290685a84b392d723be766bfb684f58fe0143de", [:mix], [{:ash, "~> 3.7", [hex: :ash, repo: "hexpm", optional: false]}, {:ecto, "~> 3.9", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.9", [hex: :ecto_sql, repo: "hexpm", optional: false]}], "hexpm", "ce4d974b8e784171c5a2a62593b3672b42dfd4888fa2239f01a6b32bad769038"},
44
"benchee": {:hex, :benchee, "1.4.0", "9f1f96a30ac80bab94faad644b39a9031d5632e517416a8ab0a6b0ac4df124ce", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}, {:statistex, "~> 1.0", [hex: :statistex, repo: "hexpm", optional: false]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "299cd10dd8ce51c9ea3ddb74bb150f93d25e968f93e4c1fa31698a8e4fa5d715"},
55
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},

test/calculation_test.exs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,4 +1121,25 @@ defmodule AshPostgres.CalculationTest do
11211121
first_comment_by_author.created_at
11221122
)
11231123
end
1124+
1125+
test "nested calculation with parent() in exists works" do
1126+
author =
1127+
Author
1128+
|> Ash.Changeset.for_create(:create, %{first_name: "John", last_name: "Doe"})
1129+
|> Ash.create!()
1130+
1131+
_post =
1132+
Post
1133+
|> Ash.Changeset.for_create(:create, %{title: "test", author_id: author.id})
1134+
|> Ash.create!()
1135+
1136+
result =
1137+
Post
1138+
|> Ash.Query.load(:author_has_post_with_title_matching_their_first_name)
1139+
|> Ash.read!()
1140+
|> List.first()
1141+
1142+
# Should be false since post title doesn't match author first name
1143+
refute result.author_has_post_with_title_matching_their_first_name
1144+
end
11241145
end

test/support/resources/author.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ defmodule AshPostgres.Test.Author do
181181
calculate(:has_posts, :boolean, expr(exists(posts, true == true)))
182182
calculate(:has_no_posts, :boolean, expr(has_posts == false))
183183

184+
calculate(
185+
:has_post_with_title_matching_first_name,
186+
:boolean,
187+
expr(exists(posts, title == parent(first_name)))
188+
)
189+
184190
calculate(:profile_description_calc, :string, expr(profile.description), allow_nil?: true)
185191
end
186192

test/support/resources/post.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,12 @@ defmodule AshPostgres.Test.Post do
924924
)
925925
)
926926

927+
calculate(
928+
:author_has_post_with_title_matching_their_first_name,
929+
:boolean,
930+
expr(author.has_post_with_title_matching_first_name)
931+
)
932+
927933
calculate(:has_author, :boolean, expr(exists(author, true == true)))
928934

929935
calculate(:has_comments, :boolean, expr(exists(comments, true == true)))

0 commit comments

Comments
 (0)