Isdriai

Isdriai

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

Showing Posts 1 to 4

Eiji

Eiji

Please take a look at changes in my PR:

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

Isdriai

Isdriai OP

Hey ! I test your changes, it works now !!! thanks :slight_smile:

Just, I saw VisualCode doesn’t propose me :candidate when I start typing :can for example. If you use VisualCode, which plugins do use you for Elixir ? ( For the moment, I have ElixirLS only )

Eiji

Eiji

Since it’s not a type known by Elixir compiler probably no editors would ever allow to prompt for atom enum values.

It would be possible if this would be merged:
https://github.com/gjaldon/ecto_enum/pull/90

With this instead of atoms you could use macros. Every editor seeing functions and macros would be able to give a proper prompt.

Of course nothing stops you from implementing your own plugin, but I do not see it a good way unless you have a good idea how to solve it nicely, because there may be multiple enums with same one or more values.

Eiji

Eiji

ping @Isdriai
My PR is still not closed/merged. Also it would be nice if you could mark this topic solved as well.

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews