Skip to content

Commit

Permalink
Merge pull request #49 from populimited/main
Browse files Browse the repository at this point in the history
Add support for %Plug.Upload{}
  • Loading branch information
nelsonic authored Aug 10, 2023
2 parents 3590fe9 + a3a973f commit 9e6fb9f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/useful.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ defmodule Useful do
def atomize_map_keys(%Time{} = value), do: value
def atomize_map_keys(%DateTime{} = value), do: value
def atomize_map_keys(%NaiveDateTime{} = value), do: value
def atomize_map_keys(%Plug.Upload{} = value), do: value

# handle lists in maps: github.com/dwyl/useful/issues/46
def atomize_map_keys(items) when is_list(items) do
Expand Down
12 changes: 12 additions & 0 deletions test/useful_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ defmodule UsefulTest do
assert Useful.atomize_map_keys(map) == map
end

test "atomize_map_keys/1 handles Plug.Upload" do
map = %{
image: %Plug.Upload{
path: "path/to/file",
filename: "file_name.ext",
content_type: "application/pdf"
}
}

assert Useful.atomize_map_keys(map) == map
end

test "atomize_map_keys/1 converts map containing list of maps" do
map = %{
"items" => [
Expand Down

0 comments on commit 9e6fb9f

Please sign in to comment.