diff --git a/lib/arc_ecto/type.ex b/lib/arc_ecto/type.ex index 98f7115..78a0a03 100644 --- a/lib/arc_ecto/type.ex +++ b/lib/arc_ecto/type.ex @@ -7,6 +7,9 @@ defmodule Arc.Ecto.Type do def cast(_definition, %{"file_name" => file, "updated_at" => updated_at}) do {:ok, %{file_name: file, updated_at: updated_at}} end + def cast(definition, value) when is_bitstring(value) do + load(definition, value) + end def cast(definition, args) do case definition.store(args) do {:ok, file} -> {:ok, %{file_name: file, updated_at: Ecto.DateTime.utc}} diff --git a/test/type_test.exs b/test/type_test.exs index 4f5a7ef..4b73993 100644 --- a/test/type_test.exs +++ b/test/type_test.exs @@ -42,4 +42,10 @@ defmodule ArcTest.Ecto.Type do {:ok, dumped_type} = DummyDefinition.Type.dump(value) assert dumped_type == "file.png" end + + test "casts embed value" do + {:ok, value} = DummyDefinition.Type.cast("file.png?62167219200") + assert value.file_name == "file.png" + assert value.updated_at == Ecto.DateTime.cast!({{1970, 1, 1}, {0, 0, 0}}) + end end