Skip to content

Commit

Permalink
Correctly load an empty map as a map
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmj committed Oct 22, 2015
1 parent f5c3251 commit 80cce81
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/mongo_ecto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ defmodule Mongo.Ecto do
do: Ecto.Type.load(ObjectID, data, &load/2)
def load(Ecto.Date, {date, _time}),
do: Ecto.Type.load(Ecto.Date, date, &dump/2)
def load(:map, []),
do: {:ok, %{}}
def load(type, data),
do: Ecto.Type.load(type, data, &load/2)

Expand Down
8 changes: 8 additions & 0 deletions test/mongo_ecto_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,12 @@ defmodule Mongo.EctoTest do
[item] = TestRepo.get!(Tag, tag.id).items
assert item.price == 10
end

test "decode empty map to map" do
post = TestRepo.insert!(%Post{meta: %{}})
assert post.meta == %{}

post = TestRepo.get(Post, post.id)
assert post.meta == %{}
end
end

0 comments on commit 80cce81

Please sign in to comment.