Skip to content
Merged
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
7 changes: 6 additions & 1 deletion installer/lib/phx_new/generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ defmodule Phx.New.Generator do
elixir_install_bin_path: from_elixir_install && elixir_install_bin_path(),
inside_docker_env?: inside_docker_env?,
agents_md: agents_md,
config_regex_E: Version.match?(System.version(), "~> 1.19.3 or ~> 1.20") && "E" || ""
config_regex_E: Version.match?(System.version(), "~> 1.19.3 or ~> 1.20") && "E" || "",
test_case_options: test_case_options(adapter_module)
]

%{project | binding: binding}
Expand Down Expand Up @@ -410,6 +411,10 @@ defmodule Phx.New.Generator do
Mix.raise("Unknown database #{inspect(db)}")
end

defp test_case_options(Ecto.Adapters.Postgres), do: ", async: true"
defp test_case_options(nil), do: ", async: true"
defp test_case_options(adapter) when is_atom(adapter), do: ""

defp get_web_adapter("cowboy"),
do:
{:plug_cowboy, "~> 2.7", Phoenix.Endpoint.Cowboy2Adapter,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule <%= @web_namespace %>.ErrorHTMLTest do
use <%= @web_namespace %>.ConnCase, async: true
use <%= @web_namespace %>.ConnCase<%= @test_case_options %>

# Bring render_to_string/4 for testing custom views
import Phoenix.Template, only: [render_to_string: 4]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule <%= @web_namespace %>.ErrorJSONTest do
use <%= @web_namespace %>.ConnCase, async: true
use <%= @web_namespace %>.ConnCase<%= @test_case_options %>

test "renders 404" do
assert <%= @web_namespace %>.ErrorJSON.render("404.json", %{}) == %{errors: %{detail: "Not Found"}}
Expand Down
37 changes: 33 additions & 4 deletions installer/test/phx_new_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ defmodule Mix.Tasks.Phx.NewTest do
end)

assert_file("phx_blog/test/phx_blog_web/controllers/page_controller_test.exs")
assert_file("phx_blog/test/phx_blog_web/controllers/error_html_test.exs")
assert_file("phx_blog/test/phx_blog_web/controllers/error_json_test.exs")
assert_file("phx_blog/test/phx_blog_web/controllers/error_html_test.exs", "async: true")
assert_file("phx_blog/test/phx_blog_web/controllers/error_json_test.exs", "async: true")
assert_file("phx_blog/test/support/conn_case.ex")
assert_file("phx_blog/test/test_helper.exs")

Expand Down Expand Up @@ -557,6 +557,9 @@ defmodule Mix.Tasks.Phx.NewTest do
assert file =~ "inputs: [\"*.{heex,ex,exs}\", \"{config,lib,test}/**/*.{heex,ex,exs}\"]"
refute file =~ "subdirectories:"
end)

assert_file("phx_blog/test/phx_blog_web/controllers/error_html_test.exs", "async: true")
assert_file("phx_blog/test/phx_blog_web/controllers/error_json_test.exs", "async: true")
end)
end

Expand Down Expand Up @@ -686,6 +689,14 @@ defmodule Mix.Tasks.Phx.NewTest do
"custom_path/test/support/data_case.ex",
"Ecto.Adapters.SQL.Sandbox.start_owner"
)

assert_file("custom_path/test/custom_path_web/controllers/error_html_test.exs", fn file ->
refute file =~ "async: true"
end)

assert_file("custom_path/test/custom_path_web/controllers/error_json_test.exs", fn file ->
refute file =~ "async: true"
end)
end)
end

Expand Down Expand Up @@ -716,8 +727,18 @@ defmodule Mix.Tasks.Phx.NewTest do
"Ecto.Adapters.SQL.Sandbox.start_owner"
)

assert_file("custom_path/.gitignore", "*.db")
assert_file("custom_path/.gitignore", "*.db-*")
assert_file("custom_path/test/custom_path_web/controllers/error_html_test.exs", fn file ->
refute file =~ "async: true"
end)

assert_file("custom_path/test/custom_path_web/controllers/error_json_test.exs", fn file ->
refute file =~ "async: true"
end)

assert_file("custom_path/.gitignore", fn file ->
assert file =~ "*.db"
assert file =~ "*.db-*"
end)
end)
end

Expand Down Expand Up @@ -747,6 +768,14 @@ defmodule Mix.Tasks.Phx.NewTest do
"custom_path/test/support/data_case.ex",
"Ecto.Adapters.SQL.Sandbox.start_owner"
)

assert_file("custom_path/test/custom_path_web/controllers/error_html_test.exs", fn file ->
refute file =~ "async: true"
end)

assert_file("custom_path/test/custom_path_web/controllers/error_json_test.exs", fn file ->
refute file =~ "async: true"
end)
end)
end

Expand Down
47 changes: 43 additions & 4 deletions installer/test/phx_new_umbrella_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,17 @@ defmodule Mix.Tasks.Phx.New.UmbrellaTest do
)

assert_file(web_path(@app, "test/#{@app}_web/controllers/page_controller_test.exs"))
assert_file(web_path(@app, "test/#{@app}_web/controllers/error_html_test.exs"))
assert_file(web_path(@app, "test/#{@app}_web/controllers/error_json_test.exs"))

assert_file(
web_path(@app, "test/#{@app}_web/controllers/error_html_test.exs"),
"async: true"
)

assert_file(
web_path(@app, "test/#{@app}_web/controllers/error_json_test.exs"),
"async: true"
)

assert_file(web_path(@app, "test/support/conn_case.ex"))
assert_file(web_path(@app, "test/test_helper.exs"))

Expand Down Expand Up @@ -625,6 +634,16 @@ defmodule Mix.Tasks.Phx.New.UmbrellaTest do
assert_file(root_path(app, "config/runtime.exs"), [~r/url: database_url/])

assert_file(web_path(app, "test/support/conn_case.ex"), "DataCase.setup_sandbox(tags)")

assert_file(
web_path(app, "test/custom_path_web/controllers/error_html_test.exs"),
fn file -> refute file =~ "async: true" end
)

assert_file(
web_path(app, "test/custom_path_web/controllers/error_json_test.exs"),
fn file -> refute file =~ "async: true" end
)
end)
end

Expand Down Expand Up @@ -652,6 +671,16 @@ defmodule Mix.Tasks.Phx.New.UmbrellaTest do

assert_file(web_path(app, "test/support/conn_case.ex"), "DataCase.setup_sandbox(tags)")

assert_file(
web_path(app, "test/custom_path_web/controllers/error_html_test.exs"),
fn file -> refute file =~ "async: true" end
)

assert_file(
web_path(app, "test/custom_path_web/controllers/error_json_test.exs"),
fn file -> refute file =~ "async: true" end
)

assert_file(root_path(app, ".gitignore"), "*.db")
assert_file(root_path(app, ".gitignore"), "*.db-*")
end)
Expand Down Expand Up @@ -679,6 +708,16 @@ defmodule Mix.Tasks.Phx.New.UmbrellaTest do
assert_file(root_path(app, "config/runtime.exs"), [~r/url: database_url/])

assert_file(web_path(app, "test/support/conn_case.ex"), "DataCase.setup_sandbox(tags)")

assert_file(
web_path(app, "test/custom_path_web/controllers/error_html_test.exs"),
fn file -> refute file =~ "async: true" end
)

assert_file(
web_path(app, "test/custom_path_web/controllers/error_json_test.exs"),
fn file -> refute file =~ "async: true" end
)
end)
end

Expand Down Expand Up @@ -822,8 +861,8 @@ defmodule Mix.Tasks.Phx.New.UmbrellaTest do
assert_file("another/lib/another/endpoint.ex", ~r/defmodule Another.Endpoint do/)

assert_file("another/test/another/controllers/page_controller_test.exs")
assert_file("another/test/another/controllers/error_html_test.exs")
assert_file("another/test/another/controllers/error_json_test.exs")
assert_file("another/test/another/controllers/error_html_test.exs", "async: true")
assert_file("another/test/another/controllers/error_json_test.exs", "async: true")
assert_file("another/test/support/conn_case.ex")
assert_file("another/test/test_helper.exs")

Expand Down
Loading