So we've got something approximating an e-commerce system. We have products with photos, descriptions, and prices, and you can add them to a cart as a guest. Next we're going to add the ability to actually complete an order. Let's get started.

Obviously we need an Order model. An Order's just like a Cart, but it's been completed. Consequently we would expect to be able to call some function on a Cart, and end up with a new Order in our database and an empty Cart. Let's model this with unit tests.

We're going to introduce a new model into our system. It's the Register, and it's where a Cart gets ordered. We'll start out writing a basic test:

# We can read in the Acceptance.CartTest and tweak it some for this defmodule PhoenixCommerce.RegisterTest do use PhoenixCommerce.ModelCase alias PhoenixCommerce.{Product, LineItem, Cart, Register, Order} setup do Repo.delete_all(Cart) Repo.delete_all(LineItem) Repo.delete_all(Product) {:ok, product}...