samedi 3 décembre 2016

Phoenix test suite can't find column when running test

I'm building my first phoenix test. I'm just trying to assert that there is content on the screen. I'm using ex_machina for a factory, that may be my problem but I'm not sure? Here is my code.

Table:

create table(:locations) do
  add :start,  :string
  add :finish, :string
end

Test:

defmodule AwesomeLunch.LocationsControllerTest do
  use AwesomeLunch.ConnCase

  import AwesomeLunch.Factory

  test "shows start and finish for locations" do
    conn = conn()
    locations = insert(:locations)

    conn = get conn, locations_path(conn, :show, locations.id)

    assert html_response(conn, 200) =~ locations.start
  end
end

Controller:

def show(conn, %{"id" => locations_id}) do
  locations = Repo.get!(Locations, locations_id)

  render conn, "show.html", locations: locations
end

Error:

** (Postgrex.Error) ERROR (undefined_column): column "finish" of relation "locations" does not exist
 stacktrace:
   (ecto) lib/ecto/adapters/sql.ex:463: Ecto.Adapters.SQL.struct/6
   (ecto) lib/ecto/repo/schema.ex:397: Ecto.Repo.Schema.apply/4
   (ecto) lib/ecto/repo/schema.ex:193: anonymous fn/11 in Ecto.Repo.Schema.do_insert/4
   (ecto) lib/ecto/repo/schema.ex:124: Ecto.Repo.Schema.insert!/4
   test/controllers/locations_controller_test.exs:8: (test)

Aucun commentaire:

Enregistrer un commentaire