Skip to content

Commit

Permalink
Add support for %Plug.Upload{}
Browse files Browse the repository at this point in the history
  • Loading branch information
icr4 committed Aug 10, 2023
1 parent 3590fe9 commit a3a973f
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 a3a973f

Please sign in to comment.