diff options
author | kaniini <nenolod@gmail.com> | 2019-05-14 14:58:45 +0000 |
---|---|---|
committer | kaniini <nenolod@gmail.com> | 2019-05-14 14:58:45 +0000 |
commit | dfd031c26adb78fbbbf44943a81ef506fbbd1324 (patch) | |
tree | 573398026f0b1a67b130826fe133496b62743279 | |
parent | 37dc1cc431e8ba4c3f5af418a2690e2a1ae3570e (diff) | |
parent | a18b2c0b12b413c9a8d0aa0d4fd3b15e0e843cdf (diff) | |
download | pleroma-dfd031c26adb78fbbbf44943a81ef506fbbd1324.tar.gz |
Merge branch 'fix/pleroma-config-get-when-value-is-false' into 'develop'
Fix Pleroma.Config.get!/1 raising an error when value is false
See merge request pleroma/pleroma!1148
-rw-r--r-- | lib/pleroma/config.ex | 8 | ||||
-rw-r--r-- | test/config_test.exs | 18 |
2 files changed, 24 insertions, 2 deletions
diff --git a/lib/pleroma/config.ex b/lib/pleroma/config.ex index 189faa15f..71a47b9fb 100644 --- a/lib/pleroma/config.ex +++ b/lib/pleroma/config.ex @@ -12,8 +12,12 @@ defmodule Pleroma.Config do def get([key], default), do: get(key, default) def get([parent_key | keys], default) do - Application.get_env(:pleroma, parent_key) - |> get_in(keys) || default + case :pleroma + |> Application.get_env(parent_key) + |> get_in(keys) do + nil -> default + any -> any + end end def get(key, default) do diff --git a/test/config_test.exs b/test/config_test.exs index 0a6f0395a..73f3fcb0a 100644 --- a/test/config_test.exs +++ b/test/config_test.exs @@ -28,6 +28,15 @@ defmodule Pleroma.ConfigTest do assert Pleroma.Config.get([:azerty, :uiop], true) == true end + test "get/1 when value is false" do + Pleroma.Config.put([:instance, :false_test], false) + Pleroma.Config.put([:instance, :nested], []) + Pleroma.Config.put([:instance, :nested, :false_test], false) + + assert Pleroma.Config.get([:instance, :false_test]) == false + assert Pleroma.Config.get([:instance, :nested, :false_test]) == false + end + test "get!/1" do assert Pleroma.Config.get!(:instance) == Application.get_env(:pleroma, :instance) @@ -43,6 +52,15 @@ defmodule Pleroma.ConfigTest do end) end + test "get!/1 when value is false" do + Pleroma.Config.put([:instance, :false_test], false) + Pleroma.Config.put([:instance, :nested], []) + Pleroma.Config.put([:instance, :nested, :false_test], false) + + assert Pleroma.Config.get!([:instance, :false_test]) == false + assert Pleroma.Config.get!([:instance, :nested, :false_test]) == false + end + test "put/2 with a key" do Pleroma.Config.put(:config_test, true) |