Skip to content

Commit 74cead8

Browse files
authored
test: add failing test for changing_attributes check for create (#288)
1 parent d5c55f6 commit 74cead8

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

test/ash_postgres_test.exs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ defmodule AshPostgresTest do
1212
}
1313
end
1414

15-
test "filter policies are applied" do
15+
test "filter policies are applied in create" do
16+
assert_raise Ash.Error.Forbidden, fn ->
17+
AshPostgres.Test.Post
18+
|> Ash.Changeset.for_create(:create, %{title: "worst"})
19+
|> Ash.create!()
20+
end
21+
end
22+
23+
test "filter policies are applied in update" do
1624
post =
1725
AshPostgres.Test.Post
1826
|> Ash.Changeset.for_create(:create, %{title: "good"})

test/support/resources/post.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ defmodule AshPostgres.Test.Post do
4141
authorize_if(relates_to_actor_via([:author, :authors_with_same_first_name]))
4242
authorize_unless(changing_attributes(title: [from: "good", to: "bad"]))
4343
end
44+
45+
policy action(:create) do
46+
authorize_unless(changing_attributes(title: [to: "worst"]))
47+
end
4448
end
4549

4650
field_policies do

0 commit comments

Comments
 (0)