little cleanup
This commit is contained in:
parent
66de2b159b
commit
59ba5c80b9
@ -17,7 +17,7 @@ defmodule Pleroma.Config.TransferTask do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def load_and_update_env do
|
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"),
|
true <- Ecto.Adapters.SQL.table_exists?(Repo, "config"),
|
||||||
started_applications <- Application.started_applications() do
|
started_applications <- Application.started_applications() do
|
||||||
# We need to restart applications for loaded settings take effect
|
# We need to restart applications for loaded settings take effect
|
||||||
|
@ -847,7 +847,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defp configurable_from_database(conn) do
|
defp configurable_from_database(conn) do
|
||||||
if Pleroma.Config.get([:configurable_from_database]) do
|
if Pleroma.Config.get(:configurable_from_database) do
|
||||||
:ok
|
:ok
|
||||||
else
|
else
|
||||||
errors(
|
errors(
|
||||||
|
@ -7,8 +7,8 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||||||
|
|
||||||
alias Pleroma.Web.AdminAPI.Config
|
alias Pleroma.Web.AdminAPI.Config
|
||||||
|
|
||||||
clear_config([:configurable_from_database]) do
|
clear_config(:configurable_from_database) do
|
||||||
Pleroma.Config.put([:configurable_from_database], true)
|
Pleroma.Config.put(:configurable_from_database, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "transfer config values from db to env" do
|
test "transfer config values from db to env" do
|
||||||
|
@ -6,6 +6,7 @@ defmodule Pleroma.Tests.Helpers do
|
|||||||
@moduledoc """
|
@moduledoc """
|
||||||
Helpers for use in tests.
|
Helpers for use in tests.
|
||||||
"""
|
"""
|
||||||
|
alias Pleroma.Config
|
||||||
|
|
||||||
defmacro clear_config(config_path) do
|
defmacro clear_config(config_path) do
|
||||||
quote do
|
quote do
|
||||||
@ -17,9 +18,9 @@ defmodule Pleroma.Tests.Helpers do
|
|||||||
defmacro clear_config(config_path, do: yield) do
|
defmacro clear_config(config_path, do: yield) do
|
||||||
quote do
|
quote do
|
||||||
setup do
|
setup do
|
||||||
initial_setting = Pleroma.Config.get(unquote(config_path))
|
initial_setting = Config.get(unquote(config_path))
|
||||||
unquote(yield)
|
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
|
:ok
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -35,9 +36,9 @@ defmodule Pleroma.Tests.Helpers do
|
|||||||
defmacro clear_config_all(config_path, do: yield) do
|
defmacro clear_config_all(config_path, do: yield) do
|
||||||
quote do
|
quote do
|
||||||
setup_all do
|
setup_all do
|
||||||
initial_setting = Pleroma.Config.get(unquote(config_path))
|
initial_setting = Config.get(unquote(config_path))
|
||||||
unquote(yield)
|
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
|
:ok
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -94,10 +95,10 @@ defmodule Pleroma.Tests.Helpers do
|
|||||||
|
|
||||||
defmacro guards_config(config_path) do
|
defmacro guards_config(config_path) do
|
||||||
quote do
|
quote do
|
||||||
initial_setting = Pleroma.Config.get(config_path)
|
initial_setting = Config.get(config_path)
|
||||||
|
|
||||||
Pleroma.Config.put(config_path, true)
|
Config.put(config_path, true)
|
||||||
on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
|
on_exit(fn -> Config.put(config_path, initial_setting) end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -19,8 +19,8 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
clear_config_all([:configurable_from_database]) do
|
clear_config_all(:configurable_from_database) do
|
||||||
Pleroma.Config.put([:configurable_from_database], true)
|
Pleroma.Config.put(:configurable_from_database, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "settings are migrated to db" do
|
test "settings are migrated to db" do
|
||||||
|
@ -1860,14 +1860,14 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "GET /api/pleroma/admin/config" do
|
describe "GET /api/pleroma/admin/config" do
|
||||||
clear_config([:configurable_from_database]) do
|
clear_config(:configurable_from_database) do
|
||||||
Pleroma.Config.put([:configurable_from_database], true)
|
Pleroma.Config.put(:configurable_from_database, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "when configuration from database is off", %{conn: conn} do
|
test "when configuration from database is off", %{conn: conn} do
|
||||||
initial = Pleroma.Config.get([:configurable_from_database])
|
initial = Pleroma.Config.get(:configurable_from_database)
|
||||||
Pleroma.Config.put([:configurable_from_database], false)
|
Pleroma.Config.put(:configurable_from_database, false)
|
||||||
on_exit(fn -> Pleroma.Config.put([:configurable_from_database], initial) end)
|
on_exit(fn -> Pleroma.Config.put(:configurable_from_database, initial) end)
|
||||||
conn = get(conn, "/api/pleroma/admin/config")
|
conn = get(conn, "/api/pleroma/admin/config")
|
||||||
|
|
||||||
assert json_response(conn, 400) ==
|
assert json_response(conn, 400) ==
|
||||||
@ -1932,8 +1932,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
clear_config([:configurable_from_database]) do
|
clear_config(:configurable_from_database) do
|
||||||
Pleroma.Config.put([:configurable_from_database], true)
|
Pleroma.Config.put(:configurable_from_database, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
@tag capture_log: true
|
@tag capture_log: true
|
||||||
@ -2822,8 +2822,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
clear_config([:configurable_from_database]) do
|
clear_config(:configurable_from_database) do
|
||||||
Pleroma.Config.put([:configurable_from_database], true)
|
Pleroma.Config.put(:configurable_from_database, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
clear_config([:feed, :post_title]) do
|
clear_config([:feed, :post_title]) do
|
||||||
@ -2843,9 +2843,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "returns error if configuration from database is off", %{conn: conn} do
|
test "returns error if configuration from database is off", %{conn: conn} do
|
||||||
initial = Pleroma.Config.get([:configurable_from_database])
|
initial = Pleroma.Config.get(:configurable_from_database)
|
||||||
on_exit(fn -> Pleroma.Config.put([:configurable_from_database], initial) end)
|
on_exit(fn -> Pleroma.Config.put(:configurable_from_database, initial) end)
|
||||||
Pleroma.Config.put([:configurable_from_database], false)
|
Pleroma.Config.put(:configurable_from_database, false)
|
||||||
|
|
||||||
conn = get(conn, "/api/pleroma/admin/config/migrate_from_db")
|
conn = get(conn, "/api/pleroma/admin/config/migrate_from_db")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user