QuickFactory behaviour (quick_factory v0.1.0)

View Source

Summary

Callbacks

Callback that returns a map with valid defaults for the schema.

Callback that returns a struct with valid defaults for the schema.

Callback that returns which changeset function to use.

Callback that returns the schema's repo module.

Callback that returns the schema module.

Functions

Builds a schema given the factory module and an optional list/map of params.

Builds many parameters for a schema changeset/2 function given the factory module and an optional list/map of params.

Builds the parameters for a schema changeset/2 function given the factory module and an optional list/map of params.

Removes all the instances of a schema from the database given its factory module.

Inserts a schema given the factory module and an optional list/map of params. Fails on error.

Insert as many as count schemas given the factory module and an optional list/map of params.

Types

build_opts()

@type build_opts() :: [{:keys, :atom | :string | :camel_string}]

Callbacks

build(map)

@callback build(map()) :: map()

Callback that returns a map with valid defaults for the schema.

build_struct(map)

(optional)
@callback build_struct(map()) :: struct()

Callback that returns a struct with valid defaults for the schema.

changeset()

@callback changeset() :: atom()

Callback that returns which changeset function to use.

repo()

@callback repo() :: module()

Callback that returns the schema's repo module.

schema()

@callback schema() :: module()

Callback that returns the schema module.

Functions

build(module, params \\ %{}, options \\ [])

Builds a schema given the factory module and an optional list/map of params.

build_invalid_params(module)

@spec build_invalid_params(module()) :: map()

build_many_params(count, module, params \\ %{}, opts \\ [])

@spec build_many_params(pos_integer(), module(), keyword() | map(), build_opts()) :: [
  map()
]

Builds many parameters for a schema changeset/2 function given the factory module and an optional list/map of params.

build_params(module, params \\ %{}, opts \\ [])

@spec build_params(module(), keyword() | map(), build_opts()) :: map()

Builds the parameters for a schema changeset/2 function given the factory module and an optional list/map of params.

cleanup(module, options \\ [])

Removes all the instances of a schema from the database given its factory module.

insert!(module, params \\ %{}, options \\ [])

@spec insert!(module(), keyword() | map(), Keyword.t()) ::
  Ecto.Schema.t() | no_return()

Inserts a schema given the factory module and an optional list/map of params. Fails on error.

insert_many!(count, module, params \\ %{}, options \\ [])

Insert as many as count schemas given the factory module and an optional list/map of params.