QuickFactory behaviour (quick_factory v0.2.3)
View SourceSummary
Callbacks
Callback that returns a struct with valid defaults for the schema.
Callback that returns a map with valid defaults for the schema. <=== THE MAIN CALLBACK
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
.
Shortcut for creating unique string values.
Automatically imported into a model factory when you use QuickFactory
.
Create sequences for generating unique values.
Similar to sequence/2
but it allows for passing a start_at
option
to the sequence generation.
Reset sequence / sequences
Types
Callbacks
Callback that returns a struct with valid defaults for the schema.
Callback that returns a map with valid defaults for the schema. <=== THE MAIN CALLBACK
@callback changeset() :: atom()
Callback that returns which changeset function to use.
@callback repo() :: module()
Callback that returns the schema's repo module.
@callback schema() :: module()
Callback that returns the schema module.
Functions
Builds a schema given the factory module
and an optional
list/map of params
.
@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
.
@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
.
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
.
Shortcut for creating unique string values.
Automatically imported into a model factory when you use QuickFactory
.
This is equivalent to sequence(name, &"#{name}#{&1}")
. If you need to
customize the returned string, see sequence/2
.
Examples
# Will generate "username0" then "username1", etc.
username: sequence("username")
# Will generate "Article Title0" then "Article Title1", etc.
title: sequence("Article Title")
Create sequences for generating unique values.
The name
can be any term, although it is typically an atom describing the
sequence. Each time a sequence is called with the same name
, its number is
incremented by one.
Examples
# Will generate "me-0@foo.com" then "me-1@foo.com", etc.
sequence(:email, &"me-#{&1}@foo.com"),
# Will generate "admin" then "user", "other", "admin" etc.
sequence(:role, ["admin", "user", "other"])
@spec sequence(any(), (integer() -> any()) | [...], [{:start_at, non_neg_integer()}]) :: any()
Similar to sequence/2
but it allows for passing a start_at
option
to the sequence generation.
Examples
# Will generate "me-100@foo.com" then "me-101@foo.com", etc.
email: sequence(:email, &"me-#{&1}@foo.com", start_at: 100),
Reset sequence / sequences