Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions test/mix/phoenix_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 0 additions & 21 deletions test/mix/tasks/phx.gen.auth_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down