From a3a973f8b1879b37491eab0bfa44691601b472c7 Mon Sep 17 00:00:00 2001 From: icra Date: Thu, 10 Aug 2023 10:40:28 +0200 Subject: [PATCH] Add support for %Plug.Upload{} --- lib/useful.ex | 1 + test/useful_test.exs | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/useful.ex b/lib/useful.ex index 3a804a9..db4b721 100644 --- a/lib/useful.ex +++ b/lib/useful.ex @@ -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 diff --git a/test/useful_test.exs b/test/useful_test.exs index 016dca4..4e5b9ba 100644 --- a/test/useful_test.exs +++ b/test/useful_test.exs @@ -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" => [