diff --git a/test/mix/phoenix_test.exs b/test/mix/phoenix_test.exs index cc2f976279..0d9121d8e5 100644 --- a/test/mix/phoenix_test.exs +++ b/test/mix/phoenix_test.exs @@ -3,6 +3,47 @@ defmodule Mix.PhoenixTest do doctest Mix.Phoenix, import: true + test "copy_from/4 uses file with .eex extension when it exists" do + tmp_dir = tmp_path!() + on_exit(fn -> File.rm_rf!(tmp_dir) end) + + templates_dir = Path.join(tmp_dir, "templates") + File.mkdir_p!(templates_dir) + File.write!(Path.join(templates_dir, "hello.ex.eex"), "<%= greeting %>") + File.write!(Path.join(templates_dir, "hello.ex"), "old") + + Mix.Phoenix.copy_from( + [tmp_dir], + "templates", + [greeting: "hi"], + [{:eex, "hello.ex.eex", Path.join(tmp_dir, "output.ex")}] + ) + + assert File.read!(Path.join(tmp_dir, "output.ex")) == "hi" + end + + test "copy_from/4 falls back to file without .eex extension for backward compatibility" do + tmp_dir = tmp_path!() + on_exit(fn -> File.rm_rf!(tmp_dir) end) + + templates_dir = Path.join(tmp_dir, "templates") + File.mkdir_p!(templates_dir) + File.write!(Path.join(templates_dir, "hello.ex"), "<%= greeting %>") + + Mix.Phoenix.copy_from( + [tmp_dir], + "templates", + [greeting: "hi"], + [{:eex, "hello.ex.eex", Path.join(tmp_dir, "output.ex")}] + ) + + assert File.read!(Path.join(tmp_dir, "output.ex")) == "hi" + end + + defp tmp_path! do + Path.join([System.tmp_dir!(), "phx_copy_from_test_#{System.unique_integer([:positive])}"]) + end + test "base/0 returns the module base based on the Mix application" do assert Mix.Phoenix.base() == "Phoenix" Application.put_env(:phoenix, :namespace, Phoenix.Sample.App) diff --git a/test/mix/tasks/phx.gen.auth_test.exs b/test/mix/tasks/phx.gen.auth_test.exs index 9c58980fd3..a16e11a3f9 100644 --- a/test/mix/tasks/phx.gen.auth_test.exs +++ b/test/mix/tasks/phx.gen.auth_test.exs @@ -1459,27 +1459,6 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do end) end - test "allows templates to be overridden (backwards compatibility)", config do - in_tmp_phx_project(config.test, fn -> - File.mkdir_p!("priv/templates/phx.gen.auth") - # verify that projects using the old filenames without .eex extension still work - File.write!("priv/templates/phx.gen.auth/auth.ex", "#it works with compat!") - - send(self(), {:mix_shell_input, :yes?, false}) - - Gen.Auth.run( - ~w(Accounts Admin admins --no-compile), - ecto_adapter: Ecto.Adapters.Postgres - ) - - assert_received {:mix_shell, :yes?, [@liveview_option_message]} - - assert_file("lib/my_app_web/admin_auth.ex", fn file -> - assert file =~ ~S|it works with compat!| - end) - end) - end - test "with --no-agents-md does not inject content to AGENTS.md", config do in_tmp_phx_project(config.test, fn -> send(self(), {:mix_shell_input, :yes?, false})