diff --git a/config/test.exs b/config/test.exs index 233ad47..b0a3aeb 100644 --- a/config/test.exs +++ b/config/test.exs @@ -1,6 +1,6 @@ import Config -config :logger, level: :critical +config :logger, level: :warning config :phoenix_sync, mode: :disabled diff --git a/lib/phoenix/sync/application.ex b/lib/phoenix/sync/application.ex index f22d832..a3d1e62 100644 --- a/lib/phoenix/sync/application.ex +++ b/lib/phoenix/sync/application.ex @@ -9,14 +9,17 @@ defmodule Phoenix.Sync.Application do @impl true def start(_type, _args) do - case children() do - {:ok, children} -> - Supervisor.start_link(children, strategy: :one_for_one, name: Phoenix.Sync.Supervisor) + children = + case children() do + {:ok, children} -> + children - {:error, reason} -> - Logger.warning(reason) - Supervisor.start_link([], strategy: :one_for_one, name: Phoenix.Sync.Supervisor) - end + {:error, reason} -> + Logger.warning(reason) + [] + end + + Supervisor.start_link(children, strategy: :one_for_one, name: Phoenix.Sync.Supervisor) end @doc false @@ -41,6 +44,8 @@ defmodule Phoenix.Sync.Application do @doc false def children(opts) when is_list(opts) do + warn_missing_env(opts) + {adapter, env} = adapter_env(opts) apply(adapter, :children, [env, opts]) @@ -73,4 +78,23 @@ defmodule Phoenix.Sync.Application do :error -> {:error, "Missing required key #{inspect(key)}"} end end + + defp warn_missing_env(config) do + if config[:mode] != :disabled && !config[:env] do + Logger.warning(""" + No `env` specified for :phoenix_sync: defaulting to `:prod`. + + Add the following to your config: + + config :phoenix_sync, + env: config_env(), + # the rest of your config + + In `:prod` mode, shapes are persisted between server restarts + which may cause problems in `:dev` or `:test` environments. + """) + end + + config + end end diff --git a/test/phoenix/sync/application_test.exs b/test/phoenix/sync/application_test.exs index de8294c..e99a1e1 100644 --- a/test/phoenix/sync/application_test.exs +++ b/test/phoenix/sync/application_test.exs @@ -3,6 +3,8 @@ defmodule Phoenix.Sync.ApplicationTest do alias Phoenix.Sync.Application, as: App + import ExUnit.CaptureLog + Code.ensure_loaded!(Support.ConfigTestRepo) defp validate_repo_connection_opts!(opts, overrides \\ []) do @@ -78,7 +80,20 @@ defmodule Phoenix.Sync.ApplicationTest do end test "disabled mode" do - assert {:ok, []} = App.children(mode: :disabled) + refute capture_log(fn -> + assert {:ok, []} = App.children(mode: :disabled) + end) =~ ~r/No `env` specified for :phoenix_sync: defaulting to `:prod`/ + end + + test "warns if env not set" do + config = [ + mode: :embedded, + repo: Support.ConfigTestRepo + ] + + assert capture_log(fn -> + assert {:ok, _} = App.children(config) + end) =~ ~r/No `env` specified for :phoenix_sync: defaulting to `:prod`/ end test "embedded mode dev env" do pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy