DSL macros for defining policy tests.
This module provides the following macros:
resource/1- Specify the resource being testedactor/2- Define a named actor with attributesdescribe/2- Group related teststest/2- Define a single test case
These macros are automatically imported when you use AshGrant.PolicyTest.
Summary
Functions
Defines a named actor with attributes.
Groups related tests under a description.
Specifies the resource being tested.
Defines a single test case.
Functions
Defines a named actor with attributes.
Actors are referenced by name in assert_can and assert_cannot macros.
Examples
actor :reader, %{role: :reader}
actor :author, %{role: :author, id: "author_001"}
actor :pm, %{
role: :project_manager,
id: "pm_001",
team_id: "team_alpha",
project_ids: ["proj_1", "proj_2"]
}
Groups related tests under a description.
The description is prepended to test names within the block.
Examples
describe "read access" do
test "reader can read" do
assert_can :reader, :read
end
end
Specifies the resource being tested.
Examples
resource MyApp.Document
resource MyApp.Blog.Post
Defines a single test case.
Within the test body, use assert_can and assert_cannot macros
to verify policy behavior.
Examples
test "reader can read" do
assert_can :reader, :read
end
test "reader can read published documents" do
assert_can :reader, :read, %{status: :published}
end