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 :’(

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

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:

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement