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 |
- |
Get Programming Phoenix 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.