Nested Forms Part 2 Phoenix Nested Forms Part 1

Recently released: ExMachina, a library for generating test data

Hey everyone! We’ve been working on a factory library called ExMachina: https://github.com/thoughtbot/ex_machina

We’ve been using it on a few internal projects. Here’s what we think you’ll like.

  • Makes it easy to work with belongs_to associations
  • Easy to pipe records through functions
  • Simple API with as few macros as possible

You can do cool things like

factory :user do
  %User{
    name: "Johnny",
    email: sequence(:email, &"email-#{&1}@example.com")
  }
end

def make_admin(user) do
  %{user | admin: true}
end

def with_article(user) do
  create(:article, user: user)
  user
end

build(:user) |> make_admin |> create |> with_article