summaryrefslogtreecommitdiff
path: root/test/support
diff options
context:
space:
mode:
Diffstat (limited to 'test/support')
-rw-r--r--test/support/helpers.ex30
1 files changed, 29 insertions, 1 deletions
diff --git a/test/support/helpers.ex b/test/support/helpers.ex
index 6bf4b019e..c6f7fa5e2 100644
--- a/test/support/helpers.ex
+++ b/test/support/helpers.ex
@@ -26,6 +26,25 @@ defmodule Pleroma.Tests.Helpers do
end
end
+ defmacro clear_config(config_path, temp_setting) do
+ quote do
+ clear_config(unquote(config_path)) do
+ Config.put(unquote(config_path), unquote(temp_setting))
+ end
+ end
+ end
+
+ @doc """
+ From _within a test case_, sets config to provided value and restores initial value on exit.
+ For multi-case setup use `clear_config/2` instead.
+ """
+ def set_config(config_path, temp_setting) do
+ initial_setting = Config.get(config_path)
+ Config.put(config_path, temp_setting)
+
+ ExUnit.Callbacks.on_exit(fn -> Config.put(config_path, initial_setting) end)
+ end
+
@doc "Stores initial config value and restores it after *all* test examples are executed."
defmacro clear_config_all(config_path) do
quote do
@@ -50,6 +69,14 @@ defmodule Pleroma.Tests.Helpers do
end
end
+ defmacro clear_config_all(config_path, temp_setting) do
+ quote do
+ clear_config_all(unquote(config_path)) do
+ Config.put(unquote(config_path), unquote(temp_setting))
+ end
+ end
+ end
+
defmacro __using__(_opts) do
quote do
import Pleroma.Tests.Helpers,
@@ -57,7 +84,8 @@ defmodule Pleroma.Tests.Helpers do
clear_config: 1,
clear_config: 2,
clear_config_all: 1,
- clear_config_all: 2
+ clear_config_all: 2,
+ set_config: 2
]
def to_datetime(naive_datetime) do