mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 21:43:12 +12:00
37cc01957d
* WIP * chore: fix mix.lock merge issues * improvement: upgrade to 3.0 * chore: remove `repo.to_tenant` * chore: continue removal of unnecessary helper * chore: use `Ash.ToTenant`
52 lines
1.6 KiB
Elixir
52 lines
1.6 KiB
Elixir
defmodule AshPostgres.Test.PrimaryKeyTest do
|
|
@moduledoc false
|
|
use AshPostgres.RepoCase, async: false
|
|
alias AshPostgres.Test.{IntegerPost, Post, PostView}
|
|
|
|
require Ash.Query
|
|
|
|
test "creates record with integer primary key" do
|
|
assert %IntegerPost{} =
|
|
IntegerPost |> Ash.Changeset.for_create(:create, %{title: "title"}) |> Ash.create!()
|
|
end
|
|
|
|
test "creates record with uuid primary key" do
|
|
assert %Post{} = Post |> Ash.Changeset.for_create(:create, %{title: "title"}) |> Ash.create!()
|
|
end
|
|
|
|
describe "resources without a primary key" do
|
|
test "records can be created" do
|
|
post =
|
|
Post
|
|
|> Ash.Changeset.for_action(:create, %{title: "not very interesting"})
|
|
|> Ash.create!()
|
|
|
|
assert {:ok, view} =
|
|
PostView
|
|
|> Ash.Changeset.for_action(:create, %{browser: :firefox, post_id: post.id})
|
|
|> Ash.create()
|
|
|
|
assert view.browser == :firefox
|
|
assert view.post_id == post.id
|
|
assert DateTime.diff(DateTime.utc_now(), view.time, :microsecond) < 1_000_000
|
|
end
|
|
|
|
test "records can be queried" do
|
|
post =
|
|
Post
|
|
|> Ash.Changeset.for_action(:create, %{title: "not very interesting"})
|
|
|> Ash.create!()
|
|
|
|
expected =
|
|
PostView
|
|
|> Ash.Changeset.for_action(:create, %{browser: :firefox, post_id: post.id})
|
|
|> Ash.create!()
|
|
|
|
assert {:ok, [actual]} = Ash.read(PostView)
|
|
|
|
assert actual.time == expected.time
|
|
assert actual.browser == expected.browser
|
|
assert actual.post_id == expected.post_id
|
|
end
|
|
end
|
|
end
|