Testing Create

We’re going to start by looking at part of the logic file with our queries. The file, called Users, contains the basic CRUD actions, in this case called create/1, get/1, update/2, and delete/1. We’ve provided a file in the copy of testing_ecto included with the book. You’re welcome to copy that over or type it in yourself. The file and the create/1 function look like this:

 defmodule​ TestingEcto.Users ​do
  @moduledoc false
  alias TestingEcto.Repo
  alias TestingEcto.Schemas.User
 
 def​ create(params) ​do
  params
  |> User.create_changeset()
  |> Repo.insert()
 end
 end

It’s pretty basic, as most CRUD queries are. As a result, testing it won’t be very complicated, either. First we’ll ...

Get Testing Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.