From 8be0091c29b9ba8e6c8c95065a86b71aaf96b2e9 Mon Sep 17 00:00:00 2001 From: David Bernheisel Date: Thu, 8 Nov 2018 16:56:09 -0500 Subject: [PATCH 1/3] Fix Ecto 3.0 Warnings --- lib/arc_ecto/schema.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/arc_ecto/schema.ex b/lib/arc_ecto/schema.ex index 3b9a56c..03b801f 100644 --- a/lib/arc_ecto/schema.ex +++ b/lib/arc_ecto/schema.ex @@ -18,7 +18,7 @@ defmodule Arc.Ecto.Schema do end # Cast supports both atom and string keys, ensure we're matching on both. - allowed = Enum.map(allowed, fn key -> + allowed_param_keys = Enum.map(allowed, fn key -> case key do key when is_binary(key) -> key key when is_atom(key) -> Atom.to_string(key) @@ -31,7 +31,7 @@ defmodule Arc.Ecto.Schema do %{} -> params |> Arc.Ecto.Schema.convert_params_to_binary - |> Map.take(allowed) + |> Map.take(allowed_param_keys) |> Enum.reduce([], fn # Don't wrap nil casts in the scope object {field, nil}, fields -> [{field, nil} | fields] From dce4e16dc8a845c4bc20299a120c946193d077ff Mon Sep 17 00:00:00 2001 From: David Bernheisel Date: Thu, 8 Nov 2018 16:56:27 -0500 Subject: [PATCH 2/3] Silence log output in tests --- test/schema_test.exs | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/test/schema_test.exs b/test/schema_test.exs index e921b24..6e58e48 100644 --- a/test/schema_test.exs +++ b/test/schema_test.exs @@ -1,6 +1,7 @@ defmodule ArcTest.Ecto.Schema do use ExUnit.Case, async: false import Mock + import ExUnit.CaptureLog defmodule TestUser do use Ecto.Schema @@ -53,28 +54,36 @@ defmodule ArcTest.Ecto.Schema do test_with_mock "cascades storage error into an error", DummyDefinition, [store: fn({%{__struct__: Plug.Upload, path: "/path/to/my/file.png", filename: "file.png"}, %TestUser{}}) -> {:error, :invalid_file} end] do upload = build_upload("/path/to/my/file.png") - cs = TestUser.changeset(%TestUser{}, %{"avatar" => upload}) - assert called DummyDefinition.store({upload, %TestUser{}}) - assert cs.valid? == false - assert cs.errors == [avatar: {"is invalid", [type: DummyDefinition.Type, validation: :cast]}] + capture_log(fn -> + cs = TestUser.changeset(%TestUser{}, %{"avatar" => upload}) + assert called DummyDefinition.store({upload, %TestUser{}}) + assert cs.valid? == false + assert cs.errors == [avatar: {"is invalid", [type: DummyDefinition.Type, validation: :cast]}] + end) end test_with_mock "converts changeset into schema", DummyDefinition, [store: fn({%{__struct__: Plug.Upload, path: "/path/to/my/file.png", filename: "file.png"}, %TestUser{}}) -> {:error, :invalid_file} end] do upload = build_upload("/path/to/my/file.png") - TestUser.changeset(%TestUser{}, %{"avatar" => upload}) - assert called DummyDefinition.store({upload, %TestUser{}}) + capture_log(fn -> + TestUser.changeset(%TestUser{}, %{"avatar" => upload}) + assert called DummyDefinition.store({upload, %TestUser{}}) + end) end test_with_mock "applies changes to schema", DummyDefinition, [store: fn({%{__struct__: Plug.Upload, path: "/path/to/my/file.png", filename: "file.png"}, %TestUser{}}) -> {:error, :invalid_file} end] do upload = build_upload("/path/to/my/file.png") - TestUser.changeset(%TestUser{}, %{"avatar" => upload, "first_name" => "test"}) - assert called DummyDefinition.store({upload, %TestUser{first_name: "test"}}) + capture_log(fn -> + TestUser.changeset(%TestUser{}, %{"avatar" => upload, "first_name" => "test"}) + assert called DummyDefinition.store({upload, %TestUser{first_name: "test"}}) + end) end test_with_mock "converts atom keys", DummyDefinition, [store: fn({%{__struct__: Plug.Upload, path: "/path/to/my/file.png", filename: "file.png"}, %TestUser{}}) -> {:error, :invalid_file} end] do upload = build_upload("/path/to/my/file.png") - TestUser.changeset(%TestUser{}, %{avatar: upload}) - assert called DummyDefinition.store({upload, %TestUser{}}) + capture_log(fn -> + TestUser.changeset(%TestUser{}, %{avatar: upload}) + assert called DummyDefinition.store({upload, %TestUser{}}) + end) end test_with_mock "casting nil attachments", DummyDefinition, [store: fn({%{__struct__: Plug.Upload, path: "/path/to/my/file.png", filename: "file.png"}, %TestUser{}}) -> {:ok, "file.png"} end] do @@ -84,7 +93,7 @@ defmodule ArcTest.Ecto.Schema do end test_with_mock "allow_paths => true", DummyDefinition, [store: fn({"/path/to/my/file.png", %TestUser{}}) -> {:ok, "file.png"} end] do - changeset = TestUser.path_changeset(%TestUser{}, %{"avatar" => "/path/to/my/file.png"}) + _changeset = TestUser.path_changeset(%TestUser{}, %{"avatar" => "/path/to/my/file.png"}) assert called DummyDefinition.store({"/path/to/my/file.png", %TestUser{}}) end end From e67698cbf7fbe2ea9e2facd422fcc5d577fa9250 Mon Sep 17 00:00:00 2001 From: David Bernheisel Date: Fri, 9 Nov 2018 09:22:16 -0500 Subject: [PATCH 3/3] Update mix requirement to allow Ecto 3.0 --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index cfcb3c1..8619e2c 100644 --- a/mix.exs +++ b/mix.exs @@ -42,7 +42,7 @@ defmodule Arc.Ecto.Mixfile do defp deps do [ {:arc, "~> 0.11.0"}, - {:ecto, "~> 2.1"}, + {:ecto, "~> 2.1 or ~> 3.0"}, {:mock, "~> 0.1.1", only: :test}, {:ex_doc, ">= 0.0.0", only: :dev} ]