test: add failing test for changing_attributes check for create (#288)

This commit is contained in:
Dmitry Maganov 2024-05-16 16:39:47 +03:00 committed by GitHub
parent d5c55f6b10
commit 74cead8749
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View file

@ -12,7 +12,15 @@ defmodule AshPostgresTest do
}
end
test "filter policies are applied" do
test "filter policies are applied in create" do
assert_raise Ash.Error.Forbidden, fn ->
AshPostgres.Test.Post
|> Ash.Changeset.for_create(:create, %{title: "worst"})
|> Ash.create!()
end
end
test "filter policies are applied in update" do
post =
AshPostgres.Test.Post
|> Ash.Changeset.for_create(:create, %{title: "good"})

View file

@ -41,6 +41,10 @@ defmodule AshPostgres.Test.Post do
authorize_if(relates_to_actor_via([:author, :authors_with_same_first_name]))
authorize_unless(changing_attributes(title: [from: "good", to: "bad"]))
end
policy action(:create) do
authorize_unless(changing_attributes(title: [to: "worst"]))
end
end
field_policies do