Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phx.gen.auth: Put live files in their own directory #5908

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
50 changes: 36 additions & 14 deletions lib/mix/tasks/phx.gen.auth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -274,69 +274,91 @@ defmodule Mix.Tasks.Phx.Gen.Auth do
case Keyword.fetch(context.opts, :live) do
{:ok, true} ->
live_files = [
"registration_live.ex": [web_pre, "live", web_path, "#{singular}_registration_live.ex"],
"registration_live.ex": [
web_pre,
"live",
web_path,
"#{singular}_live",
"registration.ex"
],
"registration_live_test.exs": [
web_test_pre,
"live",
web_path,
"#{singular}_registration_live_test.exs"
"#{singular}_live",
"registration_test.exs"
],
"login_live.ex": [web_pre, "live", web_path, "#{singular}_login_live.ex"],
"login_live.ex": [web_pre, "live", web_path, "#{singular}_live", "login.ex"],
"login_live_test.exs": [
web_test_pre,
"live",
web_path,
"#{singular}_login_live_test.exs"
"#{singular}_live",
"login_test.exs"
],
"reset_password_live.ex": [
web_pre,
"live",
web_path,
"#{singular}_reset_password_live.ex"
"#{singular}_live",
"reset_password.ex"
],
"reset_password_live_test.exs": [
web_test_pre,
"live",
web_path,
"#{singular}_reset_password_live_test.exs"
"#{singular}_live",
"reset_password_test.exs"
],
"forgot_password_live.ex": [
web_pre,
"live",
web_path,
"#{singular}_forgot_password_live.ex"
"#{singular}_live",
"forgot_password.ex"
],
"forgot_password_live_test.exs": [
web_test_pre,
"live",
web_path,
"#{singular}_forgot_password_live_test.exs"
"#{singular}_live",
"forgot_password_test.exs"
],
"settings_live.ex": [web_pre, "live", web_path, "#{singular}_settings_live.ex"],
"settings_live.ex": [web_pre, "live", web_path, "#{singular}_live", "settings.ex"],
"settings_live_test.exs": [
web_test_pre,
"live",
web_path,
"#{singular}_settings_live_test.exs"
"#{singular}_live",
"settings_test.exs"
],
"confirmation_live.ex": [
web_pre,
"live",
web_path,
"#{singular}_live",
"confirmation.ex"
],
"confirmation_live.ex": [web_pre, "live", web_path, "#{singular}_confirmation_live.ex"],
"confirmation_live_test.exs": [
web_test_pre,
"live",
web_path,
"#{singular}_confirmation_live_test.exs"
"#{singular}_live",
"confirmation_test.exs"
],
"confirmation_instructions_live.ex": [
web_pre,
"live",
web_path,
"#{singular}_confirmation_instructions_live.ex"
"#{singular}_live",
"confirmation_instructions.ex"
],
"confirmation_instructions_live_test.exs": [
web_test_pre,
"live",
web_path,
"#{singular}_confirmation_instructions_live_test.exs"
"#{singular}_live",
"confirmation_instructions_test.exs"
]
]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>ConfirmationInstructionsLive do
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.ConfirmationInstructions do
use <%= inspect context.web_module %>, :live_view

alias <%= inspect context.module %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>ConfirmationInstructionsLiveTest do
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.ConfirmationInstructionsTest do
use <%= inspect context.web_module %>.ConnCase<%= test_case_options %>

import Phoenix.LiveViewTest
Expand Down
2 changes: 1 addition & 1 deletion priv/templates/phx.gen.auth/confirmation_live.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>ConfirmationLive do
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.Confirmation do
use <%= inspect context.web_module %>, :live_view

alias <%= inspect context.module %>
Expand Down
2 changes: 1 addition & 1 deletion priv/templates/phx.gen.auth/confirmation_live_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>ConfirmationLiveTest do
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.ConfirmationTest do
use <%= inspect context.web_module %>.ConnCase<%= test_case_options %>

import Phoenix.LiveViewTest
Expand Down
2 changes: 1 addition & 1 deletion priv/templates/phx.gen.auth/forgot_password_live.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>ForgotPasswordLive do
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.ForgotPassword do
use <%= inspect context.web_module %>, :live_view

alias <%= inspect context.module %>
Expand Down
2 changes: 1 addition & 1 deletion priv/templates/phx.gen.auth/forgot_password_live_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>ForgotPasswordLiveTest do
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.ForgotPasswordTest do
use <%= inspect context.web_module %>.ConnCase<%= test_case_options %>

import Phoenix.LiveViewTest
Expand Down
2 changes: 1 addition & 1 deletion priv/templates/phx.gen.auth/login_live.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>LoginLive do
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.Login do
use <%= inspect context.web_module %>, :live_view

def render(assigns) do
Expand Down
2 changes: 1 addition & 1 deletion priv/templates/phx.gen.auth/login_live_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>LoginLiveTest do
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.LoginTest do
use <%= inspect context.web_module %>.ConnCase<%= test_case_options %>

import Phoenix.LiveViewTest
Expand Down
2 changes: 1 addition & 1 deletion priv/templates/phx.gen.auth/registration_live.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>RegistrationLive do
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.Registration do
use <%= inspect context.web_module %>, :live_view

alias <%= inspect context.module %>
Expand Down
2 changes: 1 addition & 1 deletion priv/templates/phx.gen.auth/registration_live_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>RegistrationLiveTest do
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.RegistrationTest do
use <%= inspect context.web_module %>.ConnCase<%= test_case_options %>

import Phoenix.LiveViewTest
Expand Down
2 changes: 1 addition & 1 deletion priv/templates/phx.gen.auth/reset_password_live.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>ResetPasswordLive do
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.ResetPassword do
use <%= inspect context.web_module %>, :live_view

alias <%= inspect context.module %>
Expand Down
2 changes: 1 addition & 1 deletion priv/templates/phx.gen.auth/reset_password_live_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>ResetPasswordLiveTest do
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.ResetPasswordTest do
use <%= inspect context.web_module %>.ConnCase<%= test_case_options %>

import Phoenix.LiveViewTest
Expand Down
16 changes: 8 additions & 8 deletions priv/templates/phx.gen.auth/routes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

live_session :redirect_if_<%= schema.singular %>_is_authenticated,
on_mount: [{<%= inspect auth_module %>, :redirect_if_<%= schema.singular %>_is_authenticated}] do
live "/<%= schema.plural %>/register", <%= inspect schema.alias %>RegistrationLive, :new
live "/<%= schema.plural %>/log_in", <%= inspect schema.alias %>LoginLive, :new
live "/<%= schema.plural %>/reset_password", <%= inspect schema.alias %>ForgotPasswordLive, :new
live "/<%= schema.plural %>/reset_password/:token", <%= inspect schema.alias %>ResetPasswordLive, :edit
live "/<%= schema.plural %>/register", <%= inspect schema.alias %>Live.Registration, :new
live "/<%= schema.plural %>/log_in", <%= inspect schema.alias %>Live.Login, :new
live "/<%= schema.plural %>/reset_password", <%= inspect schema.alias %>Live.ForgotPassword, :new
live "/<%= schema.plural %>/reset_password/:token", <%= inspect schema.alias %>Live.ResetPassword, :edit
end

post "/<%= schema.plural %>/log_in", <%= inspect schema.alias %>SessionController, :create<% else %>
Expand All @@ -29,8 +29,8 @@

live_session :require_authenticated_<%= schema.singular %>,
on_mount: [{<%= inspect auth_module %>, :ensure_authenticated}] do
live "/<%= schema.plural %>/settings", <%= inspect schema.alias %>SettingsLive, :edit
live "/<%= schema.plural %>/settings/confirm_email/:token", <%= inspect schema.alias %>SettingsLive, :confirm_email
live "/<%= schema.plural %>/settings", <%= inspect schema.alias %>Live.Settings, :edit
live "/<%= schema.plural %>/settings/confirm_email/:token", <%= inspect schema.alias %>Live.Settings, :confirm_email
end<% else %>

get "/<%= schema.plural %>/settings", <%= inspect schema.alias %>SettingsController, :edit
Expand All @@ -45,8 +45,8 @@

live_session :current_<%= schema.singular %>,
on_mount: [{<%= inspect auth_module %>, :mount_current_<%= schema.singular %>}] do
live "/<%= schema.plural %>/confirm/:token", <%= inspect schema.alias %>ConfirmationLive, :edit
live "/<%= schema.plural %>/confirm", <%= inspect schema.alias %>ConfirmationInstructionsLive, :new
live "/<%= schema.plural %>/confirm/:token", <%= inspect schema.alias %>Live.Confirmation, :edit
live "/<%= schema.plural %>/confirm", <%= inspect schema.alias %>Live.ConfirmationInstructions, :new
end<% else %>
get "/<%= schema.plural %>/confirm", <%= inspect schema.alias %>ConfirmationController, :new
post "/<%= schema.plural %>/confirm", <%= inspect schema.alias %>ConfirmationController, :create
Expand Down
2 changes: 1 addition & 1 deletion priv/templates/phx.gen.auth/settings_live.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>SettingsLive do
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.Settings do
use <%= inspect context.web_module %>, :live_view

alias <%= inspect context.module %>
Expand Down
2 changes: 1 addition & 1 deletion priv/templates/phx.gen.auth/settings_live_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>SettingsLiveTest do
defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.SettingsTest do
use <%= inspect context.web_module %>.ConnCase<%= test_case_options %>

alias <%= inspect context.module %>
Expand Down
60 changes: 30 additions & 30 deletions test/mix/tasks/phx.gen.auth_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -249,20 +249,20 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do
assert file =~ ~s|deliver(user.email, "Update email instructions",|
end)

assert_file("lib/my_app_web/live/user_registration_live.ex")
assert_file("test/my_app_web/live/user_registration_live_test.exs")
assert_file("lib/my_app_web/live/user_login_live.ex")
assert_file("test/my_app_web/live/user_login_live_test.exs")
assert_file("lib/my_app_web/live/user_reset_password_live.ex")
assert_file("test/my_app_web/live/user_reset_password_live_test.exs")
assert_file("lib/my_app_web/live/user_forgot_password_live.ex")
assert_file("test/my_app_web/live/user_forgot_password_live_test.exs")
assert_file("lib/my_app_web/live/user_settings_live.ex")
assert_file("test/my_app_web/live/user_settings_live_test.exs")
assert_file("lib/my_app_web/live/user_confirmation_live.ex")
assert_file("test/my_app_web/live/user_confirmation_live_test.exs")
assert_file("lib/my_app_web/live/user_confirmation_instructions_live.ex")
assert_file("test/my_app_web/live/user_confirmation_instructions_live_test.exs")
assert_file("lib/my_app_web/live/user_live/registration.ex")
assert_file("test/my_app_web/live/user_live/registration_test.exs")
assert_file("lib/my_app_web/live/user_live/login.ex")
assert_file("test/my_app_web/live/user_live/login_test.exs")
assert_file("lib/my_app_web/live/user_live/reset_password.ex")
assert_file("test/my_app_web/live/user_live/reset_password_test.exs")
assert_file("lib/my_app_web/live/user_live/forgot_password.ex")
assert_file("test/my_app_web/live/user_live/forgot_password_test.exs")
assert_file("lib/my_app_web/live/user_live/settings.ex")
assert_file("test/my_app_web/live/user_live/settings_test.exs")
assert_file("lib/my_app_web/live/user_live/confirmation.ex")
assert_file("test/my_app_web/live/user_live/confirmation_test.exs")
assert_file("lib/my_app_web/live/user_live/confirmation_instructions.ex")
assert_file("test/my_app_web/live/user_live/confirmation_instructions_test.exs")

assert_file("lib/my_app_web/user_auth.ex")
assert_file("test/my_app_web/user_auth_test.exs")
Expand Down Expand Up @@ -290,10 +290,10 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do

live_session :redirect_if_user_is_authenticated,
on_mount: [{MyAppWeb.UserAuth, :redirect_if_user_is_authenticated}] do
live "/users/register", UserRegistrationLive, :new
live "/users/log_in", UserLoginLive, :new
live "/users/reset_password", UserForgotPasswordLive, :new
live "/users/reset_password/:token", UserResetPasswordLive, :edit
live "/users/register", UserLive.Registration, :new
live "/users/log_in", UserLive.Login, :new
live "/users/reset_password", UserLive.ForgotPassword, :new
live "/users/reset_password/:token", UserLive.ResetPassword, :edit
end

post "/users/log_in", UserSessionController, :create
Expand All @@ -304,8 +304,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do

live_session :require_authenticated_user,
on_mount: [{MyAppWeb.UserAuth, :ensure_authenticated}] do
live "/users/settings", UserSettingsLive, :edit
live "/users/settings/confirm_email/:token", UserSettingsLive, :confirm_email
live "/users/settings", UserLive.Settings, :edit
live "/users/settings/confirm_email/:token", UserLive.Settings, :confirm_email
end
end

Expand All @@ -316,8 +316,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do

live_session :current_user,
on_mount: [{MyAppWeb.UserAuth, :mount_current_user}] do
live "/users/confirm/:token", UserConfirmationLive, :edit
live "/users/confirm", UserConfirmationInstructionsLive, :new
live "/users/confirm/:token", UserLive.Confirmation, :edit
live "/users/confirm", UserLive.ConfirmationInstructions, :new
end
end
"""
Expand Down Expand Up @@ -387,10 +387,10 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do

live_session :redirect_if_user_is_authenticated,
on_mount: [{MyAppWeb.UserAuth, :redirect_if_user_is_authenticated}] do
live "/users/register", UserRegistrationLive, :new
live "/users/log_in", UserLoginLive, :new
live "/users/reset_password", UserForgotPasswordLive, :new
live "/users/reset_password/:token", UserResetPasswordLive, :edit
live "/users/register", UserLive.Registration, :new
live "/users/log_in", UserLive.Login, :new
live "/users/reset_password", UserLive.ForgotPassword, :new
live "/users/reset_password/:token", UserLive.ResetPassword, :edit
end

post "/users/log_in", UserSessionController, :create
Expand All @@ -401,8 +401,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do

live_session :require_authenticated_user,
on_mount: [{MyAppWeb.UserAuth, :ensure_authenticated}] do
live "/users/settings", UserSettingsLive, :edit
live "/users/settings/confirm_email/:token", UserSettingsLive, :confirm_email
live "/users/settings", UserLive.Settings, :edit
live "/users/settings/confirm_email/:token", UserLive.Settings, :confirm_email
end
end

Expand All @@ -413,8 +413,8 @@ defmodule Mix.Tasks.Phx.Gen.AuthTest do

live_session :current_user,
on_mount: [{MyAppWeb.UserAuth, :mount_current_user}] do
live "/users/confirm/:token", UserConfirmationLive, :edit
live "/users/confirm", UserConfirmationInstructionsLive, :new
live "/users/confirm/:token", UserLive.Confirmation, :edit
live "/users/confirm", UserLive.ConfirmationInstructions, :new
end
end
"""
Expand Down
Loading