Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/ecto/uuid.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ defmodule Ecto.UUID do
{:ok, binary}
end
end


@doc """
Returns value unchanged if it is already a 16 byte binary
"""
def dump(value) when byte_size(value) == 16 do
{:ok, value}
end

def dump(_), do: :error

@compile {:inline, d: 1}
Expand Down
3 changes: 2 additions & 1 deletion test/ecto/uuid_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ defmodule Ecto.UUIDTest do

test "dump" do
assert Ecto.UUID.dump(@test_uuid) == {:ok, @test_uuid_binary}
assert Ecto.UUID.dump(@test_uuid_binary) == :error
assert Ecto.UUID.dump(@test_uuid_binary) == {:ok, @test_uuid_binary}
assert Ecto.UUID.dump("") == :error
end

test "generate" do
Expand Down