#--- # Excerpted from "Programming Ecto", # published by The Pragmatic Bookshelf. # Copyrights apply to this code. It may not be used to create training material, # courses, books, articles, and the like. Contact us if you are in doubt. # We make no guarantees that this code is fit for any purpose. # Visit https://pragprog.com/titles/wmecto for more book information. #--- import ExUnit.Assertions import Ecto.Changeset alias MusicDB.{Repo, Artist} import Ecto.Changeset params = %{name: "Gene Harris"} changeset = %Artist{} |> cast(params, [:name]) |> validate_required([:name]) case Repo.insert(changeset) do {:ok, artist} -> IO.puts("Record for #{artist.name} was created.") {:error, changeset} -> IO.inspect(changeset.errors) end assert %Artist{name: "Gene Harris"} = Repo.get_by(Artist, name: "Gene Harris")