mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
test: update test to load forbidden field through union (#713)
This commit is contained in:
parent
dedba7f471
commit
4fb6da6eee
1 changed files with 66 additions and 10 deletions
|
@ -25,7 +25,9 @@ defmodule Ash.Test.Actions.LoadTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
defmodule Bio do
|
defmodule Bio do
|
||||||
use Ash.Resource, data_layer: :embedded
|
use Ash.Resource,
|
||||||
|
authorizers: [Ash.Policy.Authorizer],
|
||||||
|
data_layer: :embedded
|
||||||
|
|
||||||
attributes do
|
attributes do
|
||||||
attribute(:first_name, :string)
|
attribute(:first_name, :string)
|
||||||
|
@ -38,13 +40,32 @@ defmodule Ash.Test.Actions.LoadTest do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
field_policies do
|
||||||
|
field_policy :* do
|
||||||
|
authorize_if always()
|
||||||
|
end
|
||||||
|
|
||||||
|
field_policy :forbidden_name do
|
||||||
|
forbid_if always()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
policies do
|
||||||
|
policy always() do
|
||||||
|
authorize_if always()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
calculations do
|
calculations do
|
||||||
calculate(:full_name, :string, expr(first_name <> " " <> last_name))
|
calculate(:full_name, :string, expr(first_name <> " " <> last_name))
|
||||||
|
calculate(:forbidden_name, :string, expr(first_name <> " " <> last_name))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defmodule OtherKindOfBio do
|
defmodule OtherKindOfBio do
|
||||||
use Ash.Resource, data_layer: :embedded
|
use Ash.Resource,
|
||||||
|
authorizers: [Ash.Policy.Authorizer],
|
||||||
|
data_layer: :embedded
|
||||||
|
|
||||||
attributes do
|
attributes do
|
||||||
attribute(:first_name, :string)
|
attribute(:first_name, :string)
|
||||||
|
@ -57,8 +78,26 @@ defmodule Ash.Test.Actions.LoadTest do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
field_policies do
|
||||||
|
field_policy :* do
|
||||||
|
authorize_if always()
|
||||||
|
end
|
||||||
|
|
||||||
|
field_policy :forbidden_name do
|
||||||
|
forbid_if always()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
policies do
|
||||||
|
policy always() do
|
||||||
|
authorize_if always()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
calculations do
|
calculations do
|
||||||
calculate(:full_name, :string, expr(first_name <> " " <> last_name))
|
calculate(:full_name, :string, expr(first_name <> " " <> last_name))
|
||||||
|
|
||||||
|
calculate(:forbidden_name, :string, expr(first_name <> " " <> last_name))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -842,22 +881,39 @@ defmodule Ash.Test.Actions.LoadTest do
|
||||||
|> Api.create!()
|
|> Api.create!()
|
||||||
|
|
||||||
assert [
|
assert [
|
||||||
%{bio_union_calc: %Ash.Union{value: %{full_name: "donald duck"}}},
|
%{
|
||||||
%{bio_union_calc: %Ash.Union{value: %{full_name: "donald duck"}}}
|
bio_union_calc: %Ash.Union{
|
||||||
|
value: %{full_name: "donald duck", forbidden_name: %Ash.ForbiddenField{}}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
%{
|
||||||
|
bio_union_calc: %Ash.Union{
|
||||||
|
value: %{full_name: "donald duck", forbidden_name: %Ash.ForbiddenField{}}
|
||||||
|
}
|
||||||
|
}
|
||||||
] =
|
] =
|
||||||
Author
|
Author
|
||||||
|> Ash.Query.load(bio_union_calc: {%{}, [*: :full_name]})
|
|> Ash.Query.load(bio_union_calc: {%{}, [*: [:full_name, :forbidden_name]]})
|
||||||
|> Api.read!()
|
|> Api.read!(actor: %{name: "zerg"})
|
||||||
|
|
||||||
assert [
|
assert [
|
||||||
%{bio_union_calc: %Ash.Union{value: %{full_name: "donald duck"}}},
|
%{
|
||||||
%{bio_union_calc: %Ash.Union{value: %{full_name: "donald duck"}}}
|
bio_union_calc: %Ash.Union{
|
||||||
|
value: %{full_name: "donald duck", forbidden_name: %Ash.ForbiddenField{}}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
%{
|
||||||
|
bio_union_calc: %Ash.Union{
|
||||||
|
value: %{full_name: "donald duck", forbidden_name: %Ash.ForbiddenField{}}
|
||||||
|
}
|
||||||
|
}
|
||||||
] =
|
] =
|
||||||
Author
|
Author
|
||||||
|> Ash.Query.load(
|
|> Ash.Query.load(
|
||||||
bio_union_calc: {%{}, [bio: :full_name, other_kind_of_bio: :full_name]}
|
bio_union_calc:
|
||||||
|
{%{}, [bio: :full_name, other_kind_of_bio: [:full_name, :forbidden_name]]}
|
||||||
)
|
)
|
||||||
|> Api.read!()
|
|> Api.read!(actor: %{name: "zerg"})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue