From 59ba5c80b97b3cef2286716573d9697e82dd2a94 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Wed, 15 Jan 2020 17:10:33 +0300 Subject: [PATCH] little cleanup --- lib/pleroma/config/transfer_task.ex | 2 +- .../web/admin_api/admin_api_controller.ex | 2 +- test/config/transfer_task_test.exs | 4 ++-- test/support/helpers.ex | 15 ++++++------ test/tasks/config_test.exs | 4 ++-- .../admin_api/admin_api_controller_test.exs | 24 +++++++++---------- 6 files changed, 26 insertions(+), 25 deletions(-) diff --git a/lib/pleroma/config/transfer_task.ex b/lib/pleroma/config/transfer_task.ex index 75c4aa739..56abfe2a5 100644 --- a/lib/pleroma/config/transfer_task.ex +++ b/lib/pleroma/config/transfer_task.ex @@ -17,7 +17,7 @@ def start_link(_) do end def load_and_update_env do - with true <- Pleroma.Config.get([:configurable_from_database]), + with true <- Pleroma.Config.get(:configurable_from_database), true <- Ecto.Adapters.SQL.table_exists?(Repo, "config"), started_applications <- Application.started_applications() do # We need to restart applications for loaded settings take effect diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex index ce5411e8a..99fcc080c 100644 --- a/lib/pleroma/web/admin_api/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/admin_api_controller.ex @@ -847,7 +847,7 @@ def config_update(conn, %{"configs" => configs}) do end defp configurable_from_database(conn) do - if Pleroma.Config.get([:configurable_from_database]) do + if Pleroma.Config.get(:configurable_from_database) do :ok else errors( diff --git a/test/config/transfer_task_test.exs b/test/config/transfer_task_test.exs index b05191eab..b684956b6 100644 --- a/test/config/transfer_task_test.exs +++ b/test/config/transfer_task_test.exs @@ -7,8 +7,8 @@ defmodule Pleroma.Config.TransferTaskTest do alias Pleroma.Web.AdminAPI.Config - clear_config([:configurable_from_database]) do - Pleroma.Config.put([:configurable_from_database], true) + clear_config(:configurable_from_database) do + Pleroma.Config.put(:configurable_from_database, true) end test "transfer config values from db to env" do diff --git a/test/support/helpers.ex b/test/support/helpers.ex index af2b2eddf..9f817622d 100644 --- a/test/support/helpers.ex +++ b/test/support/helpers.ex @@ -6,6 +6,7 @@ defmodule Pleroma.Tests.Helpers do @moduledoc """ Helpers for use in tests. """ + alias Pleroma.Config defmacro clear_config(config_path) do quote do @@ -17,9 +18,9 @@ defmacro clear_config(config_path) do defmacro clear_config(config_path, do: yield) do quote do setup do - initial_setting = Pleroma.Config.get(unquote(config_path)) + initial_setting = Config.get(unquote(config_path)) unquote(yield) - on_exit(fn -> Pleroma.Config.put(unquote(config_path), initial_setting) end) + on_exit(fn -> Config.put(unquote(config_path), initial_setting) end) :ok end end @@ -35,9 +36,9 @@ defmacro clear_config_all(config_path) do defmacro clear_config_all(config_path, do: yield) do quote do setup_all do - initial_setting = Pleroma.Config.get(unquote(config_path)) + initial_setting = Config.get(unquote(config_path)) unquote(yield) - on_exit(fn -> Pleroma.Config.put(unquote(config_path), initial_setting) end) + on_exit(fn -> Config.put(unquote(config_path), initial_setting) end) :ok end end @@ -94,10 +95,10 @@ def stringify_keys(key), do: key defmacro guards_config(config_path) do quote do - initial_setting = Pleroma.Config.get(config_path) + initial_setting = Config.get(config_path) - Pleroma.Config.put(config_path, true) - on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end) + Config.put(config_path, true) + on_exit(fn -> Config.put(config_path, initial_setting) end) end end end diff --git a/test/tasks/config_test.exs b/test/tasks/config_test.exs index b967dfdde..099b3d8e3 100644 --- a/test/tasks/config_test.exs +++ b/test/tasks/config_test.exs @@ -19,8 +19,8 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do :ok end - clear_config_all([:configurable_from_database]) do - Pleroma.Config.put([:configurable_from_database], true) + clear_config_all(:configurable_from_database) do + Pleroma.Config.put(:configurable_from_database, true) end test "settings are migrated to db" do diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index 610fa5271..faefe729e 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -1860,14 +1860,14 @@ test "returns error when status is not exist", %{conn: conn} do end describe "GET /api/pleroma/admin/config" do - clear_config([:configurable_from_database]) do - Pleroma.Config.put([:configurable_from_database], true) + clear_config(:configurable_from_database) do + Pleroma.Config.put(:configurable_from_database, true) end test "when configuration from database is off", %{conn: conn} do - initial = Pleroma.Config.get([:configurable_from_database]) - Pleroma.Config.put([:configurable_from_database], false) - on_exit(fn -> Pleroma.Config.put([:configurable_from_database], initial) end) + initial = Pleroma.Config.get(:configurable_from_database) + Pleroma.Config.put(:configurable_from_database, false) + on_exit(fn -> Pleroma.Config.put(:configurable_from_database, initial) end) conn = get(conn, "/api/pleroma/admin/config") assert json_response(conn, 400) == @@ -1932,8 +1932,8 @@ test "POST /api/pleroma/admin/config error", %{conn: conn} do end) end - clear_config([:configurable_from_database]) do - Pleroma.Config.put([:configurable_from_database], true) + clear_config(:configurable_from_database) do + Pleroma.Config.put(:configurable_from_database, true) end @tag capture_log: true @@ -2822,8 +2822,8 @@ test "proxy tuple ip", %{conn: conn} do :ok end - clear_config([:configurable_from_database]) do - Pleroma.Config.put([:configurable_from_database], true) + clear_config(:configurable_from_database) do + Pleroma.Config.put(:configurable_from_database, true) end clear_config([:feed, :post_title]) do @@ -2843,9 +2843,9 @@ test "transfer settings to DB and to file", %{conn: conn} do end test "returns error if configuration from database is off", %{conn: conn} do - initial = Pleroma.Config.get([:configurable_from_database]) - on_exit(fn -> Pleroma.Config.put([:configurable_from_database], initial) end) - Pleroma.Config.put([:configurable_from_database], false) + initial = Pleroma.Config.get(:configurable_from_database) + on_exit(fn -> Pleroma.Config.put(:configurable_from_database, initial) end) + Pleroma.Config.put(:configurable_from_database, false) conn = get(conn, "/api/pleroma/admin/config/migrate_from_db")