ecto_morph
ecto_morph copied to clipboard
Add a "Factories" section in the Readme
Using ecto_morph as a factory in tests allows us to leverage changesets to create valid data structures. We should demo how this can be nice for factory functions:
def build_user(attrs) do
defaults = %{email: "[email protected]"}
Map.merge(default, attrs)
|> EctoMorph.cast_to_struct!(User)
end
def insert_user(attrs) do
defaults = %{email: "[email protected]"}
Map.merge(default, attrs)
|> EctoMorph.cast_to_struct!(User)
|> Db.Repo.insert
end
Demo with nested data - you just pass a map in.