simonprev
Factori - Test data without boilerplate based on your database schema
factori is a library to generate fake data for your tests based on your database schema.
Instead of having to implement a Faker mapper for each data structure in your application, factori enables you to just bootstrap a factory module based on a PostgreSQL database. ![]()
Classic ex_machina factory module in every project:
defmodule Factory do
use ExMachina.Ecto, repo: MyApp.Repo
def user_factory do
%MyApp.User{
first_name: Faker.first_name(),
admin: Enum.random([true, false])
}
end
end
# Then use it in your test cases:
Factory.insert(:user)
Couple of things that factori tries to fix:
- No more forgetting to add a Faker generator for a new field added
- Automatic association handling based on foreign key
- Random data based on database built-in constraint (column size, nullability)
- No more “magic” API that calls the right function based on the suffix
_factory - Easily add “named” variant of data (example: insert an admin user)
The result is pretty simple for the user:
defmodule MyAppTest.Factory do
use Factori, repo: MyApp.Repo, mappings: [Factori.Mapping.Faker]
end
user = MyAppTest.Factory.insert("users")
user.first_name # => "Lorem"
user.last_name # => "Ipsum"
Go check the docs to see all the possibilities with named variants, structs, overrides, mapping, transform, etc
This is an early release, I’m open to comments and API changes ![]()
Popular in Announcing
Hey everyone
i’ve developed a library for Jalaali calendar for elixir which supports converting Gregorian dates to Jalaali and vice vers...
New
I’ve decided to create this topic to discuss optimization possibilities for something like Phoenix LiveView. I’ve created this topic unde...
New
Earmark is a pure-Elixir Markdown converter.
It is intended to be used as a library (just call Earmark.as_html), but can also be used as...
New
Hello!
Came here to announce ChromicPDF, a pet project PDF generator I’ve been working on for the past few months. Why another PDF gener...
New
Hey all,
We have made an Ecto3 Adapter for SQLite3, ecto_sqlite3!
We have successfully on-boarded the full suite of integration tests (...
New
After working on it for a couple of months and using it in production for most of that time, today I’ve released LiveAdmin, a LiveView ba...
New
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub.
Docs are at OpenaiEx User Gu...
New
Other popular topics
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!)
This post collects co...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
New
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security









