O'Reilly logo

Programming Phoenix by Jose Valim, Bruce Tate, Chris McCord

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Splitting Side Effects in Model Tests

It’s time to test the M of the MVC: the model. We’ll split model tests by their reliance on side effects. Phoenix, like Rumbl.ConnCase, generates a module in test/support/model_case.ex to serve as a foundation for your model tests. Crack it open so you can import our TestHelpers, like this:

1: defmodule​ Rumbl.ModelCase ​do
use​ ExUnit.CaseTemplate
using ​do
5: quote​ ​do
alias Rumbl.Repo
import​ Ecto
import​ Ecto.Changeset
10: import​ Ecto.Query, ​only:​ [​from:​ 1, ​from:​ 2]
import​ Rumbl.TestHelpers
import​ Rumbl.ModelCase
end
end
15: 
setup tags ​do
unless​ tags[​:async​] ​do

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required