2024-01-31 03:26:39 +13:00
|
|
|
defmodule AshPostgres.ManualUpdateTest do
|
2024-01-31 06:49:52 +13:00
|
|
|
use AshPostgres.RepoCase, async: true
|
2024-01-31 03:26:39 +13:00
|
|
|
|
|
|
|
test "Manual update defined in a module to update an attribute" do
|
|
|
|
post =
|
|
|
|
AshPostgres.Test.Post
|
2024-03-28 09:52:28 +13:00
|
|
|
|> Ash.Changeset.for_create(:create, %{title: "match"})
|
|
|
|
|> Ash.create!()
|
2024-01-31 03:26:39 +13:00
|
|
|
|
2024-01-31 14:04:42 +13:00
|
|
|
AshPostgres.Test.Comment
|
2024-03-28 09:52:28 +13:00
|
|
|
|> Ash.Changeset.for_create(:create, %{title: "_"})
|
2024-01-31 14:04:42 +13:00
|
|
|
|> Ash.Changeset.manage_relationship(:post, post, type: :append_and_remove)
|
2024-03-28 09:52:28 +13:00
|
|
|
|> Ash.create!()
|
2024-01-31 14:04:42 +13:00
|
|
|
|
2024-01-31 03:26:39 +13:00
|
|
|
post =
|
|
|
|
post
|
|
|
|
|> Ash.Changeset.for_update(:manual_update)
|
2024-03-28 09:52:28 +13:00
|
|
|
|> Ash.update!()
|
2024-01-31 03:26:39 +13:00
|
|
|
|
|
|
|
assert post.title == "manual"
|
2024-01-31 14:04:42 +13:00
|
|
|
|
|
|
|
# The manual update has a call to Ash.Changeset.load that should
|
|
|
|
# cause the comments to be loaded
|
|
|
|
assert Ash.Resource.loaded?(post, :comments)
|
|
|
|
assert Enum.count(post.comments) == 1
|
2024-01-31 03:26:39 +13:00
|
|
|
end
|
|
|
|
end
|