samedi 29 avril 2017

Ecto.Association.NotLoaded error on update action test in Phoenix 1.3.0-rc1

I'm running the automatically generated tests for an update action on a model (or whatever they're called now?) in Phoenix 1.3.0-rc1 and getting ** (Protocol.UndefinedError) protocol Enumerable not implemented for #Ecto.Association.NotLoaded<association :associated_models is not loaded> on the line with the put function call. Adding preloading to the fixture function like this...

def fixture(:model) do
  with {:ok, model} <- MyContext.create_model(@create_attrs),
  {:ok, preloaded_model} <- Repo.preload(model, : associated_models),
  do: preloaded_model
end

...does not change the error at all.

Test looks like this:

 test "updates chosen model and renders model when data is valid", %{conn: conn} do
    %Model{id: id} = model = fixture(:model)
    conn = put conn, model_path(conn, :update, model), model: @update_attrs
    assert %{"id" => ^id} = json_response(conn, 200)["data"]

    conn = get conn, model_path(conn, :show, id)
    assert json_response(conn, 200)["data"] == %{
      "id" => id,
      "name" => "some updated name"}
  end

I'm somewhat new to both Phoenix and Elixir.

Aucun commentaire:

Enregistrer un commentaire