mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-10 03:17:51 +00:00
Fix Pleroma.Config.get!/1 raising an error when value is false
This commit is contained in:
parent
cdcdbd88da
commit
a18b2c0b12
2 changed files with 24 additions and 2 deletions
|
@ -12,8 +12,12 @@ defmodule Pleroma.Config do
|
||||||
def get([key], default), do: get(key, default)
|
def get([key], default), do: get(key, default)
|
||||||
|
|
||||||
def get([parent_key | keys], default) do
|
def get([parent_key | keys], default) do
|
||||||
Application.get_env(:pleroma, parent_key)
|
case :pleroma
|
||||||
|> get_in(keys) || default
|
|> Application.get_env(parent_key)
|
||||||
|
|> get_in(keys) do
|
||||||
|
nil -> default
|
||||||
|
any -> any
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(key, default) do
|
def get(key, default) do
|
||||||
|
|
|
@ -28,6 +28,15 @@ defmodule Pleroma.ConfigTest do
|
||||||
assert Pleroma.Config.get([:azerty, :uiop], true) == true
|
assert Pleroma.Config.get([:azerty, :uiop], true) == true
|
||||||
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 "get!/1" do
|
test "get!/1" do
|
||||||
assert Pleroma.Config.get!(:instance) == Application.get_env(:pleroma, :instance)
|
assert Pleroma.Config.get!(:instance) == Application.get_env(:pleroma, :instance)
|
||||||
|
|
||||||
|
@ -43,6 +52,15 @@ defmodule Pleroma.ConfigTest do
|
||||||
end)
|
end)
|
||||||
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
|
test "put/2 with a key" do
|
||||||
Pleroma.Config.put(:config_test, true)
|
Pleroma.Config.put(:config_test, true)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue