View Source EctoFactory (EctoFactory v0.3.1)
EctoFactory is a super easy way to generate fake data for an Ecto Schema. It requires zero setup and generates random data based on the fields you've defined.
Link to this section Summary
Functions
Create a map with randomly generated of the passed in Ecto schema. The keys of this map are String
s
Create a map with randomly generated of the passed in Ecto schema. The keys of this map are atoms
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
Create a map with randomly generated of the passed in Ecto schema. The keys of this map are String
s
Create a map with randomly generated of the passed in Ecto schema. The keys of this map are atoms
@spec 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.
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"
}