View Source Ash.Generator (ash v2.14.18)

Tools for generating input to Ash resource actions, as well as for seeds.

These tools are young, and various factors are not taken into account. For example, validations and identities are not automatically considered.

If you want to use this with stream data testing, you will likely want to get familiar with StreamData.

Many functions in this module support overrides, which allow passing down either constant values or your own generators.

For example:

# All generated posts will have text as `"text"`. Equivalent to providing `StreamData.constant("text")`.
Ash.Generator.seed_input(Post, %{text: "text"})

Summary

Functions

Generate input meant to be passed into a resource action.

Creates the input for the provided action with action_input/3, and creates a changeset for that action with that input.

Creates a generator map where the keys are required except the list provided

Creates the input for the provided action with action_input/3, and creates a query for that action with that input.

Gets input using seed_input/2 and passes it to Ash.Seed.seed!/2, returning the result

Generate input meant to be passed into Ash.Seed.seed!/2.

Generates an input n times, and passes them all to seed, returning the list of seeded items.

Functions

Link to this function

action_input(resource_or_record, action, generators \\ %{})

View Source

Generate input meant to be passed into a resource action.

Currently input for arguments that are passed to a manage_relationship are excluded, and you will have to generate them yourself by passing your own generators/values down See the module documentation for more.

This is meant to be used in property testing. If you want to generate a finite list of

Link to this function

changeset(resource_or_record, action, generators \\ %{}, changeset_options \\ [])

View Source

Creates the input for the provided action with action_input/3, and creates a changeset for that action with that input.

See action_input/3 and the module documentation for more.

Link to this function

many_changesets(resource_or_record, action, n, generators \\ %{}, changeset_options \\ [])

View Source

Generate n changesets and return them as a list.

Link to this function

many_queries(resource, action, n, generators \\ %{}, changeset_options \\ [])

View Source

Generate n queries and return them as a list.

Creates a generator map where the keys are required except the list provided

Link to this function

query(resource, action, generators \\ %{}, changeset_options \\ [])

View Source

Creates the input for the provided action with action_input/3, and creates a query for that action with that input.

See action_input/3 and the module documentation for more.

Link to this function

seed!(resource, generators \\ %{})

View Source

Gets input using seed_input/2 and passes it to Ash.Seed.seed!/2, returning the result

Link to this function

seed_input(resource, generators \\ %{})

View Source

Generate input meant to be passed into Ash.Seed.seed!/2.

A map of custom StreamData generators can be provided to add to or overwrite the generated input, for example: Ash.Generator.for_seed(Post, %{text: StreamData.constant("Post")})

Link to this function

seed_many!(resource, n, generators \\ %{})

View Source

Generates an input n times, and passes them all to seed, returning the list of seeded items.