Skip to Main Content
Programming Phoenix
book

Programming Phoenix

by Chris McCord, Bruce Tate, Jose Valim
April 2016
Beginner to intermediate content levelBeginner to intermediate
300 pages
6h 58m
English
Pragmatic Bookshelf
Content preview from Programming Phoenix

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
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Elm

Programming Elm

Jeremy Fairbank
Real-Time Phoenix

Real-Time Phoenix

Stephen Bussey

Publisher Resources

ISBN: 9781680501926Errata Page