Skip to Content
Phoenix Web Development
book

Phoenix Web Development

by Brandon Richey
April 2018
Beginner to intermediate content levelBeginner to intermediate
406 pages
9h 33m
English
Packt Publishing
Content preview from Phoenix Web Development

Shoring up our tests

Next, we can move on to actually writing our tests. We'll want to test two things, specifically:

  1. When we have multiple polls, we want to return them in the order of most-recently created to least-recently created.
  2. When we are including pagination params (page and per_page), we should get the correct results (also respecting ordering).

We'll start with a test to cover the first scenario, since that should be pretty simple to write:

test "list_most_recent_polls/2 returns polls ordered by the most recent first", %{user: user} do  poll = poll_fixture(%{user_id: user.id})  poll2 = poll_fixture(%{user_id: user.id})  poll3 = poll_fixture(%{user_id: user.id})  assert Votes.list_most_recent_polls() == [poll3, poll2, poll]end

What ...

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

Phoenix in Action

Phoenix in Action

Geoffrey Lessel
Real-Time Phoenix

Real-Time Phoenix

Stephen Bussey

Publisher Resources

ISBN: 9781787284197Supplemental Content