@@ -4,6 +4,8 @@ defmodule Ecto.Integration.UUIDTest do
44 alias Ecto.Integration.TestRepo
55 alias EctoSQLite3.Schemas.Product
66
7+ import Ecto.Query , only: [ from: 2 ]
8+
79 setup do
810 Application . put_env ( :ecto_sqlite3 , :uuid_type , :string )
911 on_exit ( fn -> Application . put_env ( :ecto_sqlite3 , :uuid_type , :string ) end )
@@ -34,4 +36,40 @@ defmodule Ecto.Integration.UUIDTest do
3436 assert found
3537 assert found . external_id == external_id
3638 end
39+
40+ test "handles uuid casting with binary format" do
41+ Application . put_env ( :ecto_sqlite3 , :uuid_type , :binary )
42+ Application . put_env ( :ecto_sqlite3 , :binary_id_type , :binary )
43+
44+ external_id = Ecto.UUID . generate ( )
45+ TestRepo . insert! ( % Product { external_id: external_id , bid: external_id } )
46+
47+ product =
48+ TestRepo . one ( from ( p in Product , where: p . external_id == type ( p . bid , Ecto.UUID ) ) )
49+
50+ assert % { external_id: ^ external_id } = product
51+
52+ product =
53+ TestRepo . one (
54+ from ( p in Product , where: p . external_id == type ( ^ external_id , Ecto.UUID ) )
55+ )
56+
57+ assert % { external_id: ^ external_id } = product
58+ end
59+
60+ test "handles binary_id casting with binary format" do
61+ Application . put_env ( :ecto_sqlite3 , :uuid_type , :binary )
62+ Application . put_env ( :ecto_sqlite3 , :binary_id_type , :binary )
63+
64+ bid = Ecto.UUID . generate ( )
65+ TestRepo . insert! ( % Product { bid: bid , external_id: bid } )
66+
67+ product =
68+ TestRepo . one ( from ( p in Product , where: p . bid == type ( p . external_id , :binary_id ) ) )
69+
70+ assert % { bid: ^ bid } = product
71+
72+ product = TestRepo . one ( from ( p in Product , where: p . bid == type ( ^ bid , :binary_id ) ) )
73+ assert % { bid: ^ bid } = product
74+ end
3775end
0 commit comments