Isdriai

Isdriai

Errors during tests when I add a Ecto.Enum to a schema

Hi !

I’m new in Elixir/Phoenix world,

I started a project and now, I would like add a new attribute to a schema, but this attribute must be an Enum. I saw Ecto.Enum for that, So I added an Ecto.Enum, I did a migration and when I run my server, It’s ok, I have my datas with the new attribute. But when I run tests, there are errors :cry:

I put my github’s project link because I don’t see to put my code here:

https://github.com/PicotRodolphe/cym

I think error or errors are into these files:
users_test.exs
users_controller_test.exs
user.ex
users.ex

Thanks for your help :slight_smile:

Ps: my errors during tests:

mix test
Compiling 1 file (.ex)
warning: function embed_as/1 required by behaviour Ecto.Type is not implemented (in module Cym.Users.User.Type)
lib/chooseYourMis/users/user.ex:7: Cym.Users.User.Type (module)

warning: function equal?/2 required by behaviour Ecto.Type is not implemented (in module Cym.Users.User.Type)
lib/chooseYourMis/users/user.ex:7: Cym.Users.User.Type (module)

..

  1. test users get_user!/1 returns the user with given id (Cym.UsersTest)
    test/chooseYourMis/users_test.exs:27
    ** (MatchError) no match of right hand side value: {:error, #Ecto.Changeset<action: :insert, changes: %{firstName: “some firstName”, lastName: “some lastName”, mail: “some mail”}, errors:
    [type: {“is invalid”, [type: Cym.Users.User.Type, validation: :cast]}], data: #Cym.Users.User<>, valid?: false>}
    code: user = user_fixture()
    stacktrace:
    test/chooseYourMis/users_test.exs:14: Cym.UsersTest.user_fixture/1
    test/chooseYourMis/users_test.exs:28: (test)

  2. test users create_user/1 with valid data creates a user (Cym.UsersTest)
    test/chooseYourMis/users_test.exs:32
    match (=) failed
    code: assert {:ok, %User{} = user} = Users.create_user(@valid_attrs)
    right: {:error,
    #Ecto.Changeset<
    action: :insert,
    changes: %{firstName: “some firstName”, lastName: “some lastName”, mail: “some mail”},
    errors: [type: {“is invalid”, [type: Cym.Users.User.Type, validation: :cast]}],
    data: #Cym.Users.User<>,
    valid?: false
    >}
    stacktrace:
    test/chooseYourMis/users_test.exs:33: (test)

  3. test users update_user/2 with valid data updates the user (Cym.UsersTest)
    test/chooseYourMis/users_test.exs:44
    ** (MatchError) no match of right hand side value: {:error, #Ecto.Changeset<action: :insert, changes: %{firstName: “some firstName”, lastName: “some lastName”, mail: “some mail”}, errors: [type: {“is invalid”, [type: Cym.Users.User.Type, validation: :cast]}], data: #Cym.Users.User<>, valid?: false>}
    code: user = user_fixture()
    stacktrace:
    test/chooseYourMis/users_test.exs:14: Cym.UsersTest.user_fixture/1
    test/chooseYourMis/users_test.exs:45: (test)

  4. test users list_users/0 returns all users (Cym.UsersTest)
    test/chooseYourMis/users_test.exs:22
    ** (MatchError) no match of right hand side value: {:error, #Ecto.Changeset<action: :insert, changes: %{firstName: “some firstName”, lastName: “some lastName”, mail: “some mail”}, errors: [type: {“is invalid”, [type: Cym.Users.User.Type, validation: :cast]}], data: #Cym.Users.User<>, valid?: false>}
    code: user = user_fixture()
    stacktrace:
    test/chooseYourMis/users_test.exs:14: Cym.UsersTest.user_fixture/1
    test/chooseYourMis/users_test.exs:23: (test)

.

  1. test users delete_user/1 deletes the user (Cym.UsersTest)
    test/chooseYourMis/users_test.exs:59
    ** (MatchError) no match of right hand side value: {:error, #Ecto.Changeset<action: :insert, changes: %{firstName: “some firstName”, lastName: “some lastName”, mail: “some mail”}, errors: [type: {“is invalid”, [type: Cym.Users.User.Type, validation: :cast]}], data: #Cym.Users.User<>, valid?: false>}
    code: user = user_fixture()
    stacktrace:
    test/chooseYourMis/users_test.exs:14: Cym.UsersTest.user_fixture/1
    test/chooseYourMis/users_test.exs:60: (test)

  2. test users change_user/1 returns a user changeset (Cym.UsersTest)
    test/chooseYourMis/users_test.exs:65
    ** (MatchError) no match of right hand side value: {:error, #Ecto.Changeset<action: :insert, changes: %{firstName: “some firstName”, lastName: “some lastName”, mail: “some mail”}, errors: [type: {“is invalid”, [type: Cym.Users.User.Type, validation: :cast]}], data: #Cym.Users.User<>, valid?: false>}
    code: user = user_fixture()
    stacktrace:
    test/chooseYourMis/users_test.exs:14: Cym.UsersTest.user_fixture/1
    test/chooseYourMis/users_test.exs:66: (test)

  3. test users update_user/2 with invalid data returns error changeset (Cym.UsersTest)
    test/chooseYourMis/users_test.exs:53
    ** (MatchError) no match of right hand side value: {:error, #Ecto.Changeset<action: :insert, changes: %{firstName: “some firstName”, lastName: “some lastName”, mail: “some mail”}, errors: [type: {“is invalid”, [type: Cym.Users.User.Type, validation: :cast]}], data: #Cym.Users.User<>, valid?: false>}
    code: user = user_fixture()
    stacktrace:
    test/chooseYourMis/users_test.exs:14: Cym.UsersTest.user_fixture/1
    test/chooseYourMis/users_test.exs:54: (test)

..

  1. test create user renders user when data is valid (CymWeb.UserControllerTest)
    test/chooseYourMis_web/controllers/user_controller_test.exs:38
    ** (RuntimeError) expected response with status 201, got: 422, with body:
    {“errors”:{“type”:[“is invalid”]}}
    code: assert %{“id” => id} = json_response(conn, 201)[“data”]
    stacktrace:
    (phoenix) lib/phoenix/test/conn_test.ex:373: Phoenix.ConnTest.response/2
    (phoenix) lib/phoenix/test/conn_test.ex:419: Phoenix.ConnTest.json_response/2
    test/chooseYourMis_web/controllers/user_controller_test.exs:40: (test)

  2. test update user renders errors when data is invalid (CymWeb.UserControllerTest)
    test/chooseYourMis_web/controllers/user_controller_test.exs:77
    ** (MatchError) no match of right hand side value: {:error, #Ecto.Changeset<action: :insert, changes: %{firstName: “some firstName”, lastName: “some lastName”, mail: “some mail”}, errors: [type: {“is invalid”, [type: Cym.Users.User.Type, validation: :cast]}], data: #Cym.Users.User<>, valid?: false>}
    stacktrace:
    test/chooseYourMis_web/controllers/user_controller_test.exs:22: CymWeb.UserControllerTest.fixture/1
    test/chooseYourMis_web/controllers/user_controller_test.exs:97: CymWeb.UserControllerTest.create_user/1
    test/chooseYourMis_web/controllers/user_controller_test.exs:1: CymWeb.UserControllerTest.ex_unit/2

  3. test delete user deletes chosen user (CymWeb.UserControllerTest)
    test/chooseYourMis_web/controllers/user_controller_test.exs:86
    ** (MatchError) no match of right hand side value: {:error, #Ecto.Changeset<action: :insert, changes: %{firstName: “some firstName”, lastName: “some lastName”, mail: “some mail”}, errors: [type: {“is invalid”, [type: Cym.Users.User.Type, validation: :cast]}], data: #Cym.Users.User<>, valid?: false>}
    stacktrace:
    test/chooseYourMis_web/controllers/user_controller_test.exs:22: CymWeb.UserControllerTest.fixture/1
    test/chooseYourMis_web/controllers/user_controller_test.exs:97: CymWeb.UserControllerTest.create_user/1
    test/chooseYourMis_web/controllers/user_controller_test.exs:1: CymWeb.UserControllerTest.ex_unit/2

  4. test update user renders user when data is valid (CymWeb.UserControllerTest)
    test/chooseYourMis_web/controllers/user_controller_test.exs:62
    ** (MatchError) no match of right hand side value: {:error, #Ecto.Changeset<action: :insert, changes: %{firstName: “some firstName”, lastName: “some lastName”, mail: “some mail”}, errors: [type: {“is invalid”, [type: Cym.Users.User.Type, validation: :cast]}], data: #Cym.Users.User<>, valid?: false>}
    stacktrace:
    test/chooseYourMis_web/controllers/user_controller_test.exs:22: CymWeb.UserControllerTest.fixture/1
    test/chooseYourMis_web/controllers/user_controller_test.exs:97: CymWeb.UserControllerTest.create_user/1
    test/chooseYourMis_web/controllers/user_controller_test.exs:1: CymWeb.UserControllerTest.ex_unit/2

Finished in 0.2 seconds
30 tests, 11 failures

Randomized with seed 429207

Most Liked

Eiji

Eiji

Please take a look at changes in my PR:

https://github.com/PicotRodolphe/cym/pull/1

Where Next?

Popular in Questions Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New

Other popular topics Top

TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43622 214
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement