From 50f93a760f087e29bf57e38bfd29af0c8a1f8222 Mon Sep 17 00:00:00 2001 From: Biruk Haileye Tabor Date: Fri, 22 May 2026 22:23:11 +0300 Subject: [PATCH 1/4] Add template override backward compatibility test Add template override backward compatibility test Remove phx.gen.auth template override backward compatibility test --- test/mix/phoenix_test.exs | 45 ++++++++++++++++++++++++++++ test/mix/tasks/phx.gen.auth_test.exs | 21 ------------- 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/test/mix/phoenix_test.exs b/test/mix/phoenix_test.exs index cc2f976279..73934e499e 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") + + File.cd!(tmp_dir, fn -> + Mix.Phoenix.copy_from( + ["."], + "templates", + [greeting: "hi"], + [{:eex, "hello.ex.eex", "output.ex"}] + ) + + assert File.read!("output.ex") == "hi" + end) + 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 %>") + + File.cd!(tmp_dir, fn -> + Mix.Phoenix.copy_from( + ["."], + "templates", + [greeting: "hi"], + [{:eex, "hello.ex.eex", "output.ex"}] + ) + + assert File.read!("output.ex") == "hi" + end) + 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) @@ -103,6 +144,10 @@ defmodule Mix.PhoenixTest do -@one_day_in_seconds ) + defp tmp_path! do + Path.join([System.tmp_dir!(), "phx_copy_from_test_#{:erlang.unique_integer([:positive])}"]) + end + test "live_form_value/1" do assert Mix.Phoenix.Schema.live_form_value(~D[2020-10-09]) == "2020-10-09" assert Mix.Phoenix.Schema.live_form_value(~T[14:00:00]) == "14:00" 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}) From ba5badaf5b580773552dbcc4dc76d09fde8b32e8 Mon Sep 17 00:00:00 2001 From: Biruk Haileye Tabor Date: Fri, 22 May 2026 22:44:20 +0300 Subject: [PATCH 2/4] Use System.unique_integer Use System.unique_integer --- test/mix/phoenix_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mix/phoenix_test.exs b/test/mix/phoenix_test.exs index 73934e499e..5ef2a0e971 100644 --- a/test/mix/phoenix_test.exs +++ b/test/mix/phoenix_test.exs @@ -145,7 +145,7 @@ defmodule Mix.PhoenixTest do ) defp tmp_path! do - Path.join([System.tmp_dir!(), "phx_copy_from_test_#{:erlang.unique_integer([:positive])}"]) + Path.join([System.tmp_dir!(), "phx_copy_from_test_#{System.unique_integer([:positive])}"]) end test "live_form_value/1" do From dc89efa8aa0555e84dcd241bfa7b56b4a53fdb86 Mon Sep 17 00:00:00 2001 From: Biruk Haileye Tabor Date: Fri, 22 May 2026 23:01:13 +0300 Subject: [PATCH 3/4] Move tmp_path! defp Move tmp_path! defp --- test/mix/phoenix_test.exs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/mix/phoenix_test.exs b/test/mix/phoenix_test.exs index 5ef2a0e971..485e4870f1 100644 --- a/test/mix/phoenix_test.exs +++ b/test/mix/phoenix_test.exs @@ -44,6 +44,10 @@ defmodule Mix.PhoenixTest do end) 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) @@ -144,10 +148,6 @@ defmodule Mix.PhoenixTest do -@one_day_in_seconds ) - defp tmp_path! do - Path.join([System.tmp_dir!(), "phx_copy_from_test_#{System.unique_integer([:positive])}"]) - end - test "live_form_value/1" do assert Mix.Phoenix.Schema.live_form_value(~D[2020-10-09]) == "2020-10-09" assert Mix.Phoenix.Schema.live_form_value(~T[14:00:00]) == "14:00" From a91436f5a0aee1135c566a98ed41072d3d3bd89a Mon Sep 17 00:00:00 2001 From: Biruk Haileye Tabor Date: Fri, 22 May 2026 23:19:29 +0300 Subject: [PATCH 4/4] Use absolute path Use absolute path --- test/mix/phoenix_test.exs | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/test/mix/phoenix_test.exs b/test/mix/phoenix_test.exs index 485e4870f1..0d9121d8e5 100644 --- a/test/mix/phoenix_test.exs +++ b/test/mix/phoenix_test.exs @@ -12,16 +12,14 @@ defmodule Mix.PhoenixTest do File.write!(Path.join(templates_dir, "hello.ex.eex"), "<%= greeting %>") File.write!(Path.join(templates_dir, "hello.ex"), "old") - File.cd!(tmp_dir, fn -> - Mix.Phoenix.copy_from( - ["."], - "templates", - [greeting: "hi"], - [{:eex, "hello.ex.eex", "output.ex"}] - ) - - assert File.read!("output.ex") == "hi" - end) + 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 @@ -32,16 +30,14 @@ defmodule Mix.PhoenixTest do File.mkdir_p!(templates_dir) File.write!(Path.join(templates_dir, "hello.ex"), "<%= greeting %>") - File.cd!(tmp_dir, fn -> - Mix.Phoenix.copy_from( - ["."], - "templates", - [greeting: "hi"], - [{:eex, "hello.ex.eex", "output.ex"}] - ) + Mix.Phoenix.copy_from( + [tmp_dir], + "templates", + [greeting: "hi"], + [{:eex, "hello.ex.eex", Path.join(tmp_dir, "output.ex")}] + ) - assert File.read!("output.ex") == "hi" - end) + assert File.read!(Path.join(tmp_dir, "output.ex")) == "hi" end defp tmp_path! do