   use CalgyApi.ConnCase
 
   alias Plug.Conn
-  alias Calgy.Calendars.Calendar
-  alias Calgy.Repo
+  alias Calgy.Calendars
 
-  setup %{conn: conn} do
-    conn =
-      conn
-      |> put_req_header("accept", "application/json")
-
+  setup %{conn: orig_conn} do
+    conn = put_req_header(orig_conn, "accept", "application/json")
     {:ok, %{conn: conn}}
   end
 

  end

  test "GET returns 404 if uuid is invalid", %{conn: conn} do
    {:ok, _calendar} = Repo.insert(%Calendar{})
    conn = get conn, calendar_path(conn, :show, "teapot")
    body = json_response(conn, 404)
    assert body["error"]
  end

  test "GET retuns 404 if calendar is not found", %{conn: conn} do
    {:ok, _calendar} = Repo.insert(%Calendar{})
    conn = get conn, calendar_path(conn, :show, Ecto.UUID.generate)
    body = json_response(conn, 404)
    assert body["error"]
  end

  test "PUT ignores attempt to set the id", %{conn: conn} do
    {:ok, calendar} = Repo.insert(%Calendar{})

    id = Ecto.UUID.generate
    conn = put conn, calendar_path(conn, :update, calendar), %{id: id}

  end

  test "PUT allows setting :title and :description", %{conn: conn} do
    {:ok, calendar} = Calendars.create_calendar()

    attrs = %{title: "new title", description: "new description"}
    conn = put conn, calendar_path(conn, :update, calendar), attrs
