ExMachina.Ecto

Summary

Gets a factory from the passed in attrs, or builds if none is present

Builds a factory with the passed in factory_name and returns its fields

Saves a record and all associated records using Repo.insert!

Functions

assoc(module, attrs, factory_name, opts \\ [])

Gets a factory from the passed in attrs, or builds if none is present

Examples

attrs = %{user: %{name: "Someone"}}
# Returns attrs.user
assoc(:user)

attrs = %{}
# Builds and returns new instance based on :user factory
assoc(:user)

attrs = %{}
# Builds and returns new instance based on :user factory
assoc(:author, factory: :user)
fields_for(module, factory_name, attrs \\ %{})

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

factory :user do
  %MyApp.User{name: "John Doe", admin: false}
end

# Returns %{name: "John Doe", admin: true}
fields_for(:user, admin: true)
save_record(module, repo, record)

Saves a record and all associated records using Repo.insert!

Macros

assoc(factory_name, opts \\ [])