[WIP] renamed current settings module and tables to have backup suffix
This commit is contained in:
parent
d9053fff0c
commit
4ff2cc445f
20 changed files with 108 additions and 101 deletions
2
.iex.exs
2
.iex.exs
|
|
@ -11,7 +11,7 @@ alias Pinchflat.Tasks
|
||||||
alias Pinchflat.Media
|
alias Pinchflat.Media
|
||||||
alias Pinchflat.Profiles
|
alias Pinchflat.Profiles
|
||||||
alias Pinchflat.Sources
|
alias Pinchflat.Sources
|
||||||
alias Pinchflat.Settings
|
alias Pinchflat.SettingsBackup
|
||||||
|
|
||||||
alias Pinchflat.Downloading.MediaDownloader
|
alias Pinchflat.Downloading.MediaDownloader
|
||||||
alias Pinchflat.YtDlp.Media, as: YtDlpMedia
|
alias Pinchflat.YtDlp.Media, as: YtDlpMedia
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ defmodule Pinchflat.Boot.PreJobStartupTasks do
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
alias Pinchflat.Repo
|
alias Pinchflat.Repo
|
||||||
alias Pinchflat.Settings
|
alias Pinchflat.SettingsBackup
|
||||||
alias Pinchflat.YtDlp.CommandRunner
|
alias Pinchflat.YtDlp.CommandRunner
|
||||||
alias Pinchflat.Filesystem.FilesystemHelpers
|
alias Pinchflat.Filesystem.FilesystemHelpers
|
||||||
|
|
||||||
|
|
@ -65,8 +65,8 @@ defmodule Pinchflat.Boot.PreJobStartupTasks do
|
||||||
defp apply_default_settings do
|
defp apply_default_settings do
|
||||||
{:ok, yt_dlp_version} = CommandRunner.version()
|
{:ok, yt_dlp_version} = CommandRunner.version()
|
||||||
|
|
||||||
Settings.fetch!(:onboarding, true)
|
SettingsBackup.fetch!(:onboarding, true)
|
||||||
Settings.fetch!(:pro_enabled, false)
|
SettingsBackup.fetch!(:pro_enabled, false)
|
||||||
Settings.set!(:yt_dlp_version, yt_dlp_version)
|
SettingsBackup.set!(:yt_dlp_version, yt_dlp_version)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule Pinchflat.Settings.Setting do
|
defmodule Pinchflat.SettingsBackup.SettingBackup do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
A Setting is a key-value pair with a datatype used to track user-level settings.
|
A Setting is a key-value pair with a datatype used to track user-level settings.
|
||||||
"""
|
"""
|
||||||
|
|
@ -6,7 +6,7 @@ defmodule Pinchflat.Settings.Setting do
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
schema "settings" do
|
schema "settings_backup" do
|
||||||
field :name, :string
|
field :name, :string
|
||||||
field :value, :string
|
field :value, :string
|
||||||
field :datatype, Ecto.Enum, values: ~w(boolean string integer float)a
|
field :datatype, Ecto.Enum, values: ~w(boolean string integer float)a
|
||||||
|
|
@ -1,20 +1,20 @@
|
||||||
defmodule Pinchflat.Settings do
|
defmodule Pinchflat.SettingsBackup do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
The Settings context.
|
The SettingsBackup context.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import Ecto.Query, warn: false
|
import Ecto.Query, warn: false
|
||||||
alias Pinchflat.Repo
|
alias Pinchflat.Repo
|
||||||
|
|
||||||
alias Pinchflat.Settings.Setting
|
alias Pinchflat.SettingsBackup.SettingBackup
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Returns the list of settings.
|
Returns the list of settings.
|
||||||
|
|
||||||
Returns [%Setting{}, ...]
|
Returns [%SettingBackup{}, ...]
|
||||||
"""
|
"""
|
||||||
def list_settings do
|
def list_settings do
|
||||||
Repo.all(Setting)
|
Repo.all(SettingBackup)
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
|
@ -30,7 +30,7 @@ defmodule Pinchflat.Settings do
|
||||||
|
|
||||||
def set!(name, value, datatype) do
|
def set!(name, value, datatype) do
|
||||||
# Only create if doesn't exist
|
# Only create if doesn't exist
|
||||||
case Repo.get_by(Setting, name: to_string(name)) do
|
case Repo.get_by(SettingBackup, name: to_string(name)) do
|
||||||
nil -> create_setting!(name, value, datatype)
|
nil -> create_setting!(name, value, datatype)
|
||||||
setting -> update_setting!(setting, value, datatype)
|
setting -> update_setting!(setting, value, datatype)
|
||||||
end
|
end
|
||||||
|
|
@ -42,7 +42,7 @@ defmodule Pinchflat.Settings do
|
||||||
Returns value in type of `Ecto.Enum.mappings(Setting, :datatype)`
|
Returns value in type of `Ecto.Enum.mappings(Setting, :datatype)`
|
||||||
"""
|
"""
|
||||||
def get!(name) do
|
def get!(name) do
|
||||||
Setting
|
SettingBackup
|
||||||
|> Repo.get_by!(name: to_string(name))
|
|> Repo.get_by!(name: to_string(name))
|
||||||
|> read_setting()
|
|> read_setting()
|
||||||
end
|
end
|
||||||
|
|
@ -59,18 +59,18 @@ defmodule Pinchflat.Settings do
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch!(name, value, datatype) do
|
def fetch!(name, value, datatype) do
|
||||||
case Repo.get_by(Setting, name: to_string(name)) do
|
case Repo.get_by(SettingBackup, name: to_string(name)) do
|
||||||
nil -> create_setting!(name, value, datatype)
|
nil -> create_setting!(name, value, datatype)
|
||||||
setting -> read_setting(setting)
|
setting -> read_setting(setting)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp change_setting(setting, attrs) do
|
defp change_setting(setting, attrs) do
|
||||||
Setting.changeset(setting, attrs)
|
SettingBackup.changeset(setting, attrs)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp create_setting!(name, value, datatype) do
|
defp create_setting!(name, value, datatype) do
|
||||||
%Setting{}
|
%SettingBackup{}
|
||||||
|> change_setting(%{name: to_string(name), value: to_string(value), datatype: datatype})
|
|> change_setting(%{name: to_string(name), value: to_string(value), datatype: datatype})
|
||||||
|> Repo.insert!()
|
|> Repo.insert!()
|
||||||
|> read_setting()
|
|> read_setting()
|
||||||
|
|
@ -45,7 +45,7 @@ defmodule PinchflatWeb do
|
||||||
import Plug.Conn
|
import Plug.Conn
|
||||||
import PinchflatWeb.Gettext
|
import PinchflatWeb.Gettext
|
||||||
|
|
||||||
alias Pinchflat.Settings
|
alias Pinchflat.SettingsBackup
|
||||||
alias PinchflatWeb.Layouts
|
alias PinchflatWeb.Layouts
|
||||||
|
|
||||||
unquote(verified_routes())
|
unquote(verified_routes())
|
||||||
|
|
@ -58,7 +58,7 @@ defmodule PinchflatWeb do
|
||||||
|
|
||||||
use Phoenix.LiveView
|
use Phoenix.LiveView
|
||||||
|
|
||||||
alias Pinchflat.Settings
|
alias Pinchflat.SettingsBackup
|
||||||
|
|
||||||
unquote(html_helpers())
|
unquote(html_helpers())
|
||||||
end
|
end
|
||||||
|
|
@ -68,7 +68,7 @@ defmodule PinchflatWeb do
|
||||||
quote do
|
quote do
|
||||||
use Phoenix.LiveComponent
|
use Phoenix.LiveComponent
|
||||||
|
|
||||||
alias Pinchflat.Settings
|
alias Pinchflat.SettingsBackup
|
||||||
|
|
||||||
unquote(html_helpers())
|
unquote(html_helpers())
|
||||||
end
|
end
|
||||||
|
|
@ -82,7 +82,7 @@ defmodule PinchflatWeb do
|
||||||
import Phoenix.Controller,
|
import Phoenix.Controller,
|
||||||
only: [get_csrf_token: 0, view_module: 1, view_template: 1]
|
only: [get_csrf_token: 0, view_module: 1, view_template: 1]
|
||||||
|
|
||||||
alias Pinchflat.Settings
|
alias Pinchflat.SettingsBackup
|
||||||
|
|
||||||
# Include general helpers for rendering HTML
|
# Include general helpers for rendering HTML
|
||||||
unquote(html_helpers())
|
unquote(html_helpers())
|
||||||
|
|
@ -101,7 +101,7 @@ defmodule PinchflatWeb do
|
||||||
import PinchflatWeb.CustomComponents.TableComponents
|
import PinchflatWeb.CustomComponents.TableComponents
|
||||||
import PinchflatWeb.CustomComponents.ButtonComponents
|
import PinchflatWeb.CustomComponents.ButtonComponents
|
||||||
|
|
||||||
alias Pinchflat.Settings
|
alias Pinchflat.SettingsBackup
|
||||||
alias Pinchflat.Utils.StringUtils
|
alias Pinchflat.Utils.StringUtils
|
||||||
|
|
||||||
# Shortcut for generating JS commands
|
# Shortcut for generating JS commands
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@
|
||||||
Pinchflat v<%= Application.spec(:pinchflat)[:vsn] %>
|
Pinchflat v<%= Application.spec(:pinchflat)[:vsn] %>
|
||||||
</span>
|
</span>
|
||||||
<span class="group relative flex items-center gap-2.5 px-4 text-sm">
|
<span class="group relative flex items-center gap-2.5 px-4 text-sm">
|
||||||
yt-dlp <%= Settings.get!(:yt_dlp_version) %>
|
yt-dlp <%= SettingsBackup.get!(:yt_dlp_version) %>
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ defmodule Pinchflat.UpgradeButtonLive do
|
||||||
|> String.downcase()
|
|> String.downcase()
|
||||||
|
|
||||||
if normalized_text == "got it!" do
|
if normalized_text == "got it!" do
|
||||||
Settings.set!(:pro_enabled, true)
|
SettingsBackup.set!(:pro_enabled, true)
|
||||||
|
|
||||||
{:noreply, update(socket, :button_disabled, fn _ -> false end)}
|
{:noreply, update(socket, :button_disabled, fn _ -> false end)}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@
|
||||||
<body
|
<body
|
||||||
x-data={"{
|
x-data={"{
|
||||||
sidebarVisible: false,
|
sidebarVisible: false,
|
||||||
proEnabled: #{Settings.get!(:pro_enabled)},
|
proEnabled: #{SettingsBackup.get!(:pro_enabled)},
|
||||||
onboarding: #{Settings.get!(:onboarding)}
|
onboarding: #{SettingsBackup.get!(:onboarding)}
|
||||||
}"}
|
}"}
|
||||||
class="dark text-bodydark bg-boxdark-2"
|
class="dark text-bodydark bg-boxdark-2"
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ defmodule PinchflatWeb.MediaProfiles.MediaProfileController do
|
||||||
case Profiles.create_media_profile(media_profile_params) do
|
case Profiles.create_media_profile(media_profile_params) do
|
||||||
{:ok, media_profile} ->
|
{:ok, media_profile} ->
|
||||||
redirect_location =
|
redirect_location =
|
||||||
if Settings.get!(:onboarding), do: ~p"/?onboarding=1", else: ~p"/media_profiles/#{media_profile}"
|
if SettingsBackup.get!(:onboarding), do: ~p"/?onboarding=1", else: ~p"/media_profiles/#{media_profile}"
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_flash(:info, "Media profile created successfully.")
|
|> put_flash(:info, "Media profile created successfully.")
|
||||||
|
|
@ -89,7 +89,7 @@ defmodule PinchflatWeb.MediaProfiles.MediaProfileController do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_onboarding_layout do
|
defp get_onboarding_layout do
|
||||||
if Settings.get!(:onboarding) do
|
if SettingsBackup.get!(:onboarding) do
|
||||||
{Layouts, :onboarding}
|
{Layouts, :onboarding}
|
||||||
else
|
else
|
||||||
{Layouts, :app}
|
{Layouts, :app}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<div class="mb-6 flex gap-3 flex-row items-center">
|
<div class="mb-6 flex gap-3 flex-row items-center">
|
||||||
<.link :if={!Settings.get!(:onboarding)} href={~p"/media_profiles"}>
|
<.link :if={!SettingsBackup.get!(:onboarding)} href={~p"/media_profiles"}>
|
||||||
<.icon name="hero-arrow-left" class="w-10 h-10 hover:dark:text-white" />
|
<.icon name="hero-arrow-left" class="w-10 h-10 hover:dark:text-white" />
|
||||||
</.link>
|
</.link>
|
||||||
<h2 class="text-title-md2 font-bold text-black dark:text-white ml-4">New Media Profile</h2>
|
<h2 class="text-title-md2 font-bold text-black dark:text-white ml-4">New Media Profile</h2>
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,9 @@ defmodule PinchflatWeb.Pages.PageController do
|
||||||
done_onboarding = params["onboarding"] == "0"
|
done_onboarding = params["onboarding"] == "0"
|
||||||
force_onboarding = params["onboarding"] == "1"
|
force_onboarding = params["onboarding"] == "1"
|
||||||
|
|
||||||
if done_onboarding, do: Settings.set!(:onboarding, false)
|
if done_onboarding, do: SettingsBackup.set!(:onboarding, false)
|
||||||
|
|
||||||
if force_onboarding || Settings.get!(:onboarding) do
|
if force_onboarding || SettingsBackup.get!(:onboarding) do
|
||||||
render_onboarding_page(conn)
|
render_onboarding_page(conn)
|
||||||
else
|
else
|
||||||
render_home_page(conn)
|
render_home_page(conn)
|
||||||
|
|
@ -30,7 +30,7 @@ defmodule PinchflatWeb.Pages.PageController do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp render_onboarding_page(conn) do
|
defp render_onboarding_page(conn) do
|
||||||
Settings.set!(:onboarding, true)
|
SettingsBackup.set!(:onboarding, true)
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> render(:onboarding_checklist,
|
|> render(:onboarding_checklist,
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ defmodule PinchflatWeb.Sources.SourceController do
|
||||||
case Sources.create_source(source_params) do
|
case Sources.create_source(source_params) do
|
||||||
{:ok, source} ->
|
{:ok, source} ->
|
||||||
redirect_location =
|
redirect_location =
|
||||||
if Settings.get!(:onboarding), do: ~p"/?onboarding=1", else: ~p"/sources/#{source}"
|
if SettingsBackup.get!(:onboarding), do: ~p"/?onboarding=1", else: ~p"/sources/#{source}"
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_flash(:info, "Source created successfully.")
|
|> put_flash(:info, "Source created successfully.")
|
||||||
|
|
@ -159,7 +159,7 @@ defmodule PinchflatWeb.Sources.SourceController do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_onboarding_layout do
|
defp get_onboarding_layout do
|
||||||
if Settings.get!(:onboarding) do
|
if SettingsBackup.get!(:onboarding) do
|
||||||
{Layouts, :onboarding}
|
{Layouts, :onboarding}
|
||||||
else
|
else
|
||||||
{Layouts, :app}
|
{Layouts, :app}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<div class="mb-6 flex gap-3 flex-row items-center">
|
<div class="mb-6 flex gap-3 flex-row items-center">
|
||||||
<.link :if={!Settings.get!(:onboarding)} href={~p"/sources"}>
|
<.link :if={!SettingsBackup.get!(:onboarding)} href={~p"/sources"}>
|
||||||
<.icon name="hero-arrow-left" class="w-10 h-10 hover:dark:text-white" />
|
<.icon name="hero-arrow-left" class="w-10 h-10 hover:dark:text-white" />
|
||||||
</.link>
|
</.link>
|
||||||
<h2 class="text-title-md2 font-bold text-black dark:text-white ml-4">New Source</h2>
|
<h2 class="text-title-md2 font-bold text-black dark:text-white ml-4">New Source</h2>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule Pinchflat.Repo.Migrations.CreateSettings do
|
defmodule Pinchflat.Repo.Migrations.CreateSettingsBackup do
|
||||||
use Ecto.Migration
|
use Ecto.Migration
|
||||||
|
|
||||||
def change do
|
def change do
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
defmodule Pinchflat.Repo.Migrations.RenameSettingsBackupTable do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
rename table(:settings), to: table(:settings_backup)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -1,25 +1,25 @@
|
||||||
defmodule Pinchflat.Boot.PreJobStartupTasksTest do
|
defmodule Pinchflat.Boot.PreJobStartupTasksTest do
|
||||||
use Pinchflat.DataCase
|
use Pinchflat.DataCase
|
||||||
|
|
||||||
alias Pinchflat.Settings
|
alias Pinchflat.SettingsBackup
|
||||||
alias Pinchflat.Settings.Setting
|
alias Pinchflat.SettingsBackup.SettingBackup
|
||||||
alias Pinchflat.Boot.PreJobStartupTasks
|
alias Pinchflat.Boot.PreJobStartupTasks
|
||||||
|
|
||||||
describe "apply_default_settings" do
|
describe "apply_default_settings" do
|
||||||
setup do
|
setup do
|
||||||
Repo.delete_all(Setting)
|
Repo.delete_all(SettingBackup)
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
test "sets default settings" do
|
test "sets default settings" do
|
||||||
assert_raise Ecto.NoResultsError, fn -> Settings.get!(:onboarding) end
|
assert_raise Ecto.NoResultsError, fn -> SettingsBackup.get!(:onboarding) end
|
||||||
assert_raise Ecto.NoResultsError, fn -> Settings.get!(:pro_enabled) end
|
assert_raise Ecto.NoResultsError, fn -> SettingsBackup.get!(:pro_enabled) end
|
||||||
|
|
||||||
PreJobStartupTasks.start_link()
|
PreJobStartupTasks.start_link()
|
||||||
|
|
||||||
assert Settings.get!(:onboarding)
|
assert SettingsBackup.get!(:onboarding)
|
||||||
refute Settings.get!(:pro_enabled)
|
refute SettingsBackup.get!(:pro_enabled)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
defmodule Pinchflat.SettingsTest do
|
defmodule Pinchflat.SettingsBackupTest do
|
||||||
use Pinchflat.DataCase
|
use Pinchflat.DataCase
|
||||||
|
|
||||||
alias Pinchflat.Settings
|
alias Pinchflat.SettingsBackup
|
||||||
alias Pinchflat.Settings.Setting
|
alias Pinchflat.SettingsBackup.SettingBackup
|
||||||
|
|
||||||
# NOTE: We're treating some of these tests differently
|
# NOTE: We're treating some of these tests differently
|
||||||
# than in other modules because certain settings
|
# than in other modules because certain settings
|
||||||
|
|
@ -11,98 +11,98 @@ defmodule Pinchflat.SettingsTest do
|
||||||
|
|
||||||
describe "list_settings/0" do
|
describe "list_settings/0" do
|
||||||
test "returns all settings" do
|
test "returns all settings" do
|
||||||
Settings.set!("foo", "bar")
|
SettingsBackup.set!("foo", "bar")
|
||||||
results = Settings.list_settings()
|
results = SettingsBackup.list_settings()
|
||||||
|
|
||||||
assert Enum.all?(results, fn setting -> match?(%Setting{}, setting) end)
|
assert Enum.all?(results, fn setting -> match?(%SettingBackup{}, setting) end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "set/2" do
|
describe "set/2" do
|
||||||
test "creates a new setting if one does not exist" do
|
test "creates a new setting if one does not exist" do
|
||||||
original = Repo.aggregate(Setting, :count, :id)
|
original = Repo.aggregate(SettingBackup, :count, :id)
|
||||||
Settings.set!("foo", "bar")
|
SettingsBackup.set!("foo", "bar")
|
||||||
assert Repo.aggregate(Setting, :count, :id) == original + 1
|
assert Repo.aggregate(SettingBackup, :count, :id) == original + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
test "updates an existing setting if one exists" do
|
test "updates an existing setting if one exists" do
|
||||||
Settings.set!("foo", "bar")
|
SettingsBackup.set!("foo", "bar")
|
||||||
original = Repo.aggregate(Setting, :count, :id)
|
original = Repo.aggregate(SettingBackup, :count, :id)
|
||||||
Settings.set!("foo", "baz")
|
SettingsBackup.set!("foo", "baz")
|
||||||
assert Repo.aggregate(Setting, :count, :id) == original
|
assert Repo.aggregate(SettingBackup, :count, :id) == original
|
||||||
assert Settings.get!("foo") == "baz"
|
assert SettingsBackup.get!("foo") == "baz"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns the parsed value" do
|
test "returns the parsed value" do
|
||||||
assert Settings.set!("foo", true) == true
|
assert SettingsBackup.set!("foo", true) == true
|
||||||
assert Settings.set!("foo", false) == false
|
assert SettingsBackup.set!("foo", false) == false
|
||||||
assert Settings.set!("foo", 123) == 123
|
assert SettingsBackup.set!("foo", 123) == 123
|
||||||
assert Settings.set!("foo", 12.34) == 12.34
|
assert SettingsBackup.set!("foo", 12.34) == 12.34
|
||||||
assert Settings.set!("foo", "bar") == "bar"
|
assert SettingsBackup.set!("foo", "bar") == "bar"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "allows for atom keys" do
|
test "allows for atom keys" do
|
||||||
assert Settings.set!(:foo, "bar") == "bar"
|
assert SettingsBackup.set!(:foo, "bar") == "bar"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "blows up when an unsupported datatype is used" do
|
test "blows up when an unsupported datatype is used" do
|
||||||
assert_raise FunctionClauseError, fn ->
|
assert_raise FunctionClauseError, fn ->
|
||||||
Settings.set!("foo", nil)
|
SettingsBackup.set!("foo", nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "set/3" do
|
describe "set/3" do
|
||||||
test "allows manual specification of datatype" do
|
test "allows manual specification of datatype" do
|
||||||
assert Settings.set!("foo", "true", :boolean) == true
|
assert SettingsBackup.set!("foo", "true", :boolean) == true
|
||||||
assert Settings.set!("foo", "false", :boolean) == false
|
assert SettingsBackup.set!("foo", "false", :boolean) == false
|
||||||
assert Settings.set!("foo", "123", :integer) == 123
|
assert SettingsBackup.set!("foo", "123", :integer) == 123
|
||||||
assert Settings.set!("foo", "12.34", :float) == 12.34
|
assert SettingsBackup.set!("foo", "12.34", :float) == 12.34
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "get/1" do
|
describe "get/1" do
|
||||||
test "returns the value of the setting" do
|
test "returns the value of the setting" do
|
||||||
Settings.set!("str", "bar")
|
SettingsBackup.set!("str", "bar")
|
||||||
Settings.set!("bool", true)
|
SettingsBackup.set!("bool", true)
|
||||||
Settings.set!("int", 123)
|
SettingsBackup.set!("int", 123)
|
||||||
Settings.set!("float", 12.34)
|
SettingsBackup.set!("float", 12.34)
|
||||||
|
|
||||||
assert Settings.get!("str") == "bar"
|
assert SettingsBackup.get!("str") == "bar"
|
||||||
assert Settings.get!("bool") == true
|
assert SettingsBackup.get!("bool") == true
|
||||||
assert Settings.get!("int") == 123
|
assert SettingsBackup.get!("int") == 123
|
||||||
assert Settings.get!("float") == 12.34
|
assert SettingsBackup.get!("float") == 12.34
|
||||||
end
|
end
|
||||||
|
|
||||||
test "allows for atom keys" do
|
test "allows for atom keys" do
|
||||||
Settings.set!("str", "bar")
|
SettingsBackup.set!("str", "bar")
|
||||||
assert Settings.get!(:str) == "bar"
|
assert SettingsBackup.get!(:str) == "bar"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "blows up when the setting does not exist" do
|
test "blows up when the setting does not exist" do
|
||||||
assert_raise Ecto.NoResultsError, fn ->
|
assert_raise Ecto.NoResultsError, fn ->
|
||||||
Settings.get!("foo")
|
SettingsBackup.get!("foo")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "fetch/2" do
|
describe "fetch/2" do
|
||||||
test "creates a setting if one doesn't exist" do
|
test "creates a setting if one doesn't exist" do
|
||||||
original = Repo.aggregate(Setting, :count, :id)
|
original = Repo.aggregate(SettingBackup, :count, :id)
|
||||||
assert Settings.fetch!("foo", "bar") == "bar"
|
assert SettingsBackup.fetch!("foo", "bar") == "bar"
|
||||||
assert Repo.aggregate(Setting, :count, :id) == original + 1
|
assert Repo.aggregate(SettingBackup, :count, :id) == original + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns an existing setting if one does exist" do
|
test "returns an existing setting if one does exist" do
|
||||||
Settings.set!("foo", "bar")
|
SettingsBackup.set!("foo", "bar")
|
||||||
|
|
||||||
assert Settings.fetch!("foo", "baz") == "bar"
|
assert SettingsBackup.fetch!("foo", "baz") == "bar"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "fetch/3" do
|
describe "fetch/3" do
|
||||||
test "allows manual specification of datatype" do
|
test "allows manual specification of datatype" do
|
||||||
assert Settings.fetch!("foo", "true", :boolean) == true
|
assert SettingsBackup.fetch!("foo", "true", :boolean) == true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ defmodule PinchflatWeb.MediaProfileControllerTest do
|
||||||
import Pinchflat.ProfilesFixtures
|
import Pinchflat.ProfilesFixtures
|
||||||
|
|
||||||
alias Pinchflat.Repo
|
alias Pinchflat.Repo
|
||||||
alias Pinchflat.Settings
|
alias Pinchflat.SettingsBackup
|
||||||
|
|
||||||
@create_attrs %{name: "some name", output_path_template: "output_template.{{ ext }}"}
|
@create_attrs %{name: "some name", output_path_template: "output_template.{{ ext }}"}
|
||||||
@update_attrs %{
|
@update_attrs %{
|
||||||
|
|
@ -16,7 +16,7 @@ defmodule PinchflatWeb.MediaProfileControllerTest do
|
||||||
@invalid_attrs %{name: nil, output_path_template: nil}
|
@invalid_attrs %{name: nil, output_path_template: nil}
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
Settings.set!(:onboarding, false)
|
SettingsBackup.set!(:onboarding, false)
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
@ -35,7 +35,7 @@ defmodule PinchflatWeb.MediaProfileControllerTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "renders correct layout when onboarding", %{conn: conn} do
|
test "renders correct layout when onboarding", %{conn: conn} do
|
||||||
Settings.set!(:onboarding, true)
|
SettingsBackup.set!(:onboarding, true)
|
||||||
conn = get(conn, ~p"/media_profiles/new")
|
conn = get(conn, ~p"/media_profiles/new")
|
||||||
|
|
||||||
refute html_response(conn, 200) =~ "MENU"
|
refute html_response(conn, 200) =~ "MENU"
|
||||||
|
|
@ -59,14 +59,14 @@ defmodule PinchflatWeb.MediaProfileControllerTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "redirects to onboarding when onboarding", %{conn: conn} do
|
test "redirects to onboarding when onboarding", %{conn: conn} do
|
||||||
Settings.set!(:onboarding, true)
|
SettingsBackup.set!(:onboarding, true)
|
||||||
conn = post(conn, ~p"/media_profiles", media_profile: @create_attrs)
|
conn = post(conn, ~p"/media_profiles", media_profile: @create_attrs)
|
||||||
|
|
||||||
assert redirected_to(conn) == ~p"/?onboarding=1"
|
assert redirected_to(conn) == ~p"/?onboarding=1"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "renders correct layout on error when onboarding", %{conn: conn} do
|
test "renders correct layout on error when onboarding", %{conn: conn} do
|
||||||
Settings.set!(:onboarding, true)
|
SettingsBackup.set!(:onboarding, true)
|
||||||
conn = post(conn, ~p"/media_profiles", media_profile: @invalid_attrs)
|
conn = post(conn, ~p"/media_profiles", media_profile: @invalid_attrs)
|
||||||
|
|
||||||
refute html_response(conn, 200) =~ "MENU"
|
refute html_response(conn, 200) =~ "MENU"
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
defmodule PinchflatWeb.PageControllerTest do
|
defmodule PinchflatWeb.PageControllerTest do
|
||||||
use PinchflatWeb.ConnCase
|
use PinchflatWeb.ConnCase
|
||||||
|
|
||||||
alias Pinchflat.Settings
|
alias Pinchflat.SettingsBackup
|
||||||
|
|
||||||
describe "GET / when testing onboarding" do
|
describe "GET / when testing onboarding" do
|
||||||
test "sets the onboarding setting to true when onboarding", %{conn: conn} do
|
test "sets the onboarding setting to true when onboarding", %{conn: conn} do
|
||||||
_conn = get(conn, ~p"/")
|
_conn = get(conn, ~p"/")
|
||||||
assert Settings.get!(:onboarding)
|
assert SettingsBackup.get!(:onboarding)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "displays the onboarding page when onboarding is forced", %{conn: conn} do
|
test "displays the onboarding page when onboarding is forced", %{conn: conn} do
|
||||||
Settings.set!(:onboarding, false)
|
SettingsBackup.set!(:onboarding, false)
|
||||||
|
|
||||||
conn = get(conn, ~p"/?onboarding=1")
|
conn = get(conn, ~p"/?onboarding=1")
|
||||||
assert html_response(conn, 200) =~ "Welcome to Pinchflat"
|
assert html_response(conn, 200) =~ "Welcome to Pinchflat"
|
||||||
|
|
@ -18,14 +18,14 @@ defmodule PinchflatWeb.PageControllerTest do
|
||||||
|
|
||||||
test "sets the onboarding setting to false if you pass the corrent query param", %{conn: conn} do
|
test "sets the onboarding setting to false if you pass the corrent query param", %{conn: conn} do
|
||||||
conn = get(conn, ~p"/")
|
conn = get(conn, ~p"/")
|
||||||
assert Settings.get!(:onboarding)
|
assert SettingsBackup.get!(:onboarding)
|
||||||
|
|
||||||
_conn = get(conn, ~p"/?onboarding=0")
|
_conn = get(conn, ~p"/?onboarding=0")
|
||||||
refute Settings.get!(:onboarding)
|
refute SettingsBackup.get!(:onboarding)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "displays the home page when not onboarding", %{conn: conn} do
|
test "displays the home page when not onboarding", %{conn: conn} do
|
||||||
Settings.set!(:onboarding, false)
|
SettingsBackup.set!(:onboarding, false)
|
||||||
|
|
||||||
conn = get(conn, ~p"/")
|
conn = get(conn, ~p"/")
|
||||||
assert html_response(conn, 200) =~ "MENU"
|
assert html_response(conn, 200) =~ "MENU"
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,13 @@ defmodule PinchflatWeb.SourceControllerTest do
|
||||||
import Pinchflat.ProfilesFixtures
|
import Pinchflat.ProfilesFixtures
|
||||||
|
|
||||||
alias Pinchflat.Repo
|
alias Pinchflat.Repo
|
||||||
alias Pinchflat.Settings
|
alias Pinchflat.SettingsBackup
|
||||||
alias Pinchflat.Downloading.MediaDownloadWorker
|
alias Pinchflat.Downloading.MediaDownloadWorker
|
||||||
alias Pinchflat.SlowIndexing.MediaCollectionIndexingWorker
|
alias Pinchflat.SlowIndexing.MediaCollectionIndexingWorker
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
media_profile = media_profile_fixture()
|
media_profile = media_profile_fixture()
|
||||||
Settings.set!(:onboarding, false)
|
SettingsBackup.set!(:onboarding, false)
|
||||||
|
|
||||||
{
|
{
|
||||||
:ok,
|
:ok,
|
||||||
|
|
@ -47,7 +47,7 @@ defmodule PinchflatWeb.SourceControllerTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "renders correct layout when onboarding", %{conn: conn} do
|
test "renders correct layout when onboarding", %{conn: conn} do
|
||||||
Settings.set!(:onboarding, true)
|
SettingsBackup.set!(:onboarding, true)
|
||||||
conn = get(conn, ~p"/sources/new")
|
conn = get(conn, ~p"/sources/new")
|
||||||
|
|
||||||
refute html_response(conn, 200) =~ "MENU"
|
refute html_response(conn, 200) =~ "MENU"
|
||||||
|
|
@ -74,14 +74,14 @@ defmodule PinchflatWeb.SourceControllerTest do
|
||||||
test "redirects to onboarding when onboarding", %{conn: conn, create_attrs: create_attrs} do
|
test "redirects to onboarding when onboarding", %{conn: conn, create_attrs: create_attrs} do
|
||||||
expect(YtDlpRunnerMock, :run, 1, &runner_function_mock/3)
|
expect(YtDlpRunnerMock, :run, 1, &runner_function_mock/3)
|
||||||
|
|
||||||
Settings.set!(:onboarding, true)
|
SettingsBackup.set!(:onboarding, true)
|
||||||
conn = post(conn, ~p"/sources", source: create_attrs)
|
conn = post(conn, ~p"/sources", source: create_attrs)
|
||||||
|
|
||||||
assert redirected_to(conn) == ~p"/?onboarding=1"
|
assert redirected_to(conn) == ~p"/?onboarding=1"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "renders correct layout on error when onboarding", %{conn: conn, invalid_attrs: invalid_attrs} do
|
test "renders correct layout on error when onboarding", %{conn: conn, invalid_attrs: invalid_attrs} do
|
||||||
Settings.set!(:onboarding, true)
|
SettingsBackup.set!(:onboarding, true)
|
||||||
conn = post(conn, ~p"/sources", source: invalid_attrs)
|
conn = post(conn, ~p"/sources", source: invalid_attrs)
|
||||||
|
|
||||||
refute html_response(conn, 200) =~ "MENU"
|
refute html_response(conn, 200) =~ "MENU"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue