Skip to content

Commit d31162e

Browse files
committed
added a new test for the encoder protocol
1 parent 068d451 commit d31162e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

test/mongo/encoder_test.exs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ defmodule Mongo.EncoderTest do
88
{:ok, [pid: pid]}
99
end
1010

11+
defimpl Mongo.Encoder, for: Date do
12+
def encode(date) do
13+
Date.to_iso8601(date)
14+
end
15+
end
16+
1117
defmodule CustomStructWithoutProtocol do
1218
@fields [:a, :b, :c, :id]
1319
@enforce_keys @fields
@@ -31,6 +37,16 @@ defmodule Mongo.EncoderTest do
3137
end
3238
end
3339

40+
test "insert encoded date with protocol", c do
41+
coll = unique_collection()
42+
43+
to_insert = %{date: ~D[2000-01-01]}
44+
45+
assert {:ok, _} = Mongo.insert_one(c.pid, coll, to_insert, [])
46+
47+
assert %{"date" => "2000-01-01"} = Mongo.find_one(c.pid, coll, %{})
48+
end
49+
3450
test "insert encoded struct with protocol", c do
3551
coll = unique_collection()
3652

0 commit comments

Comments
 (0)