ExMachina
Defines functions for generating data
In depth examples are in the README
Summary
Builds a factory with the passed in factory_name and attrs
Builds and returns X records with the passed in factory_name and attrs
Builds and returns 2 records with the passed in factory_name and attrs
Builds and saves a factory with the passed in factory_name
Creates and returns X records with the passed in factory_name and attrs
Creates and returns 2 records with the passed in factory_name and attrs
Create sequences for generating unique values
Callback implementation for c::application.start/2
Functions
Builds a factory with the passed in factory_name and attrs
Example
def factory(:user, _attrs) do
%{name: "John Doe", admin: false}
end
# Returns %{name: "John Doe", admin: true}
build(:user, admin: true)
Builds and returns X records with the passed in factory_name and attrs
Example
# Returns a list of 3 users
build_list(3, :user)
Builds and returns 2 records with the passed in factory_name and attrs
Example
# Returns a list of 2 users
build_pair(:user)
Builds and saves a factory with the passed in factory_name
If using ExMachina.Ecto it will use the Ecto Repo passed in to save the record automatically.
If you are not using ExMachina.Ecto, you need to define a save_record/1
function in your module. See save_record
docs for more information.
Example
def factory(:user, _attrs) do
%{name: "John Doe", admin: false}
end
# Saves and returns %{name: "John Doe", admin: true}
create(:user, admin: true)
Creates and returns X records with the passed in factory_name and attrs
Example
# Returns a list of 3 saved users
create_list(3, :user)
Creates and returns 2 records with the passed in factory_name and attrs
Example
# Returns a list of 2 saved users
create_pair(:user)
Create sequences for generating unique values
Examples
def factory(:user, _attrs) do
%{
# Will generate "me-0@example.com" then "me-1@example.com", etc.
email: sequence(:email, &"me-#{&1}@foo.com")
}
end