mirror of
https://github.com/ash-project/ash.git
synced 2024-09-19 13:03:02 +12:00
fix: incorrect error for casting binary UUID (#653)
This commit is contained in:
parent
8e12a14b25
commit
925f5c1f9a
2 changed files with 15 additions and 1 deletions
|
@ -23,7 +23,10 @@ defmodule Ash.Type.UUID do
|
|||
def cast_input(nil, _), do: {:ok, nil}
|
||||
|
||||
def cast_input(value, _) when is_binary(value) do
|
||||
Ecto.Type.cast(Ecto.UUID, String.trim(value))
|
||||
case String.valid?(value) do
|
||||
true -> Ecto.Type.cast(Ecto.UUID, String.trim(value))
|
||||
false -> Ecto.Type.cast(Ecto.UUID, value)
|
||||
end
|
||||
end
|
||||
|
||||
def cast_input(value, _) do
|
||||
|
|
11
test/type/uuid_test.exs
Normal file
11
test/type/uuid_test.exs
Normal file
|
@ -0,0 +1,11 @@
|
|||
defmodule Ash.Test.Type.UUIDTest do
|
||||
@moduledoc false
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
test "it casts binary UUIDs to string" do
|
||||
uuid = "a7cec9ba-15de-4c56-99e4-c2abc91a2209"
|
||||
|
||||
assert {:ok, binary_uuid} = Ash.Type.dump_to_native(Ash.Type.UUID, uuid)
|
||||
assert {:ok, ^uuid} = Ash.Type.cast_input(Ash.Type.UUID, binary_uuid)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue