EctoFactory v0.1.3 EctoFactory View Source

Link to this section Summary

Functions

Create a map with randomly generated of the passed in Ecto schema

Generate a random value. gen/1 will return a value of the atom or tuple to pass it.

Create a struct of the passed in factory

Link to this section Functions

Link to this function

attrs(factory_name, attrs \\ [])

View Source

Create a map with randomly generated of the passed in Ecto schema

Link to this function

gen(arg1)

View Source
gen(atom() | tuple()) ::
  integer()
  | binary()
  | float()
  | boolean()
  | list()
  | Time
  | NaiveDateTime
  | Date
  | DateTime

Generate a random value. gen/1 will return a value of the atom or tuple to pass it.

Link to this function

schema(factory_name, attrs \\ [])

View Source
schema(atom() | Ecto.Schema, keyword()) :: Ecto.Schema
schema(atom() | Ecto.Schema, keyword()) :: map()

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.

EctoFactory.schema(:user_with_default_username)

%User{
  age: 124309132# random number
  username: "mrmicahcooper"
}

And you can pass in your own attributes of course:

EctoFactory.schema(:user, age: 99, username: "hashrocket")

%User{
  age: 99,
  username: "hashrocket"
}