ExMachina.Ecto
Summary
Gets a factory from the passed in attrs, or creates if none is present
Builds a factory with the passed in factory_name and returns its fields
Saves a record using Repo.insert!
when create
is called
Functions
Gets a factory from the passed in attrs, or creates if none is present
Examples
attrs = %{user: %{name: "Someone"}}
# Returns attrs.user
assoc(attrs, :user)
attrs = %{}
# Creates and returns new instance based on :user factory
assoc(attrs, :user)
attrs = %{}
# Creates and returns new instance based on :user factory
assoc(attrs, :author, factory: :user)
Builds a factory with the passed in factory_name and returns its fields
This is only for use with Ecto models.
Will return a map with the fields and virtual fields, but without the Ecto metadata and associations.
Example
def factory(:user) do
%MyApp.User{name: "John Doe", admin: false}
end
# Returns %{name: "John Doe", admin: true}
fields_for(:user, admin: true)