Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for %Plug.Upload{} #49

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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