Testing Read Operation
Learn how to test Read operation in Elixir
We'll cover the following...
We'll cover the following...
The Read function
First, let’s look at the code in our Users
module at testing_ecto/lib/users/users.ex
.
Note: We used “Read” in the section header to keep it in line with CRUD, but you’ll notice that we prefer to call our function
get/1
. This is entirely user preference.
Press + to interact
#file path -> testing_ecto/lib/users/users.ex#add this code at the indicated place mentioned in comments of testing_ecto/lib/users/users.ex#in the playground widgetdef get(user_id) doif user = Repo.get(User, user_id) do{:ok, user}else{:error, :not_found}endend
Our ...