EctoFactory v0.0.2 EctoFactory

Summary

Functions

Create a struct of the passed in factory

Insert a factory into the database

Functions

build(factory_name, attrs \\ [])

Create a struct of the passed in factory

After configuring a factory

config :ecto_factory, factories: [
  user: User,

  user_with_default_username: { User,
    username: "mrmicahcooper"
  }
]

You can build a struct with the attributes from your factory as defaults.

iex> EctoFactory.build(:user_with_default_username)
%User{
  age: 1,
  username: "mrmicahcooper",
  date_of_birth: Ecto.DateTime.utc
}

And you can pass in your own attributes of course:

iex> EctoFactory.build(:user, age: 99, username: "hashrocket")
%User{
  age: 99,
  username: "hashrocket",
  date_of_birth: Ecto.DateTime.utc
}
insert(factory_name, attrs \\ [])

Insert a factory into the database.

NOTE: Be sure to set ecto_factory’s :repo configuration before you use insert/2.

config :ecto_factory, repo: MyApp.Repo

Example

iex> EctoFactory.insert(:user, age: 99, username: "hashrocket")
%User{
  id: 1,
  age: 99,
  username: "hashrocket",
  date_of_birth: Ecto.DateTime.utc
}