AshGrant.PolicyTest.Dsl (AshGrant v0.17.0)

Copy Markdown View Source

DSL macros for defining policy tests.

This module provides the following macros:

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

actor(name, attrs)

(macro)

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"]
}

describe(description, list)

(macro)

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

resource(module)

(macro)

Specifies the resource being tested.

Examples

resource MyApp.Document
resource MyApp.Blog.Post

test(name, list)

(macro)

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