Skip to content

Instantly share code, notes, and snippets.

@v0idpwn
Created November 2, 2020 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save v0idpwn/bf96155e243f70ee2320d50e34bda109 to your computer and use it in GitHub Desktop.
Save v0idpwn/bf96155e243f70ee2320d50e34bda109 to your computer and use it in GitHub Desktop.
From f034e4a69845f47f5789f2b136b24626e17600a2 Mon Sep 17 00:00:00 2001
From: v0idpwn <v0idpwn@gmail.com>
Date: Mon, 2 Nov 2020 16:57:41 -0300
Subject: [PATCH] reproducing attempt
---
test/ecto/repo_test.exs | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/test/ecto/repo_test.exs b/test/ecto/repo_test.exs
index a218cbea..fed41c12 100644
--- a/test/ecto/repo_test.exs
+++ b/test/ecto/repo_test.exs
@@ -120,6 +120,22 @@ defmodule Ecto.RepoTest do
end
end
+ defmodule MySchemaWithEctoEnum do
+ use Ecto.Schema
+
+ schema "my_schema" do
+ field :my_enum, Ecto.Enum, values: [:foo, :bar]
+ end
+ end
+
+ defmodule MyEmbeddedSchemaWithEctoEnum do
+ use Ecto.Schema
+
+ embedded_schema do
+ field :my_enum, Ecto.Enum, values: [:foo, :bar]
+ end
+ end
+
test "defines child_spec/1" do
assert TestRepo.child_spec([]) == %{
id: TestRepo,
@@ -177,6 +193,14 @@ defmodule Ecto.RepoTest do
assert %MySchema{} =
TestRepo.load(MySchema, %{bad: "bad"})
+ # schema with ecto enum
+ assert %MySchemaWithEctoEnum{} =
+ TestRepo.load(MySchemaWithEctoEnum, %{my_enum: nil}) |> IO.inspect()
+
+ # embedded schema with ecto enum
+ assert %MyEmbeddedSchemaWithEctoEnum{} =
+ TestRepo.load(MyEmbeddedSchemaWithEctoEnum, %{my_enum: nil}) |> IO.inspect()
+
# invalid value
assert_raise ArgumentError, "cannot load `0` as type :string for field `x` in schema Ecto.RepoTest.MySchema", fn ->
TestRepo.load(MySchema, %{x: 0})
--
2.20.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment