Skip to content

Commit

Permalink
use --no-scope in tests for now
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenDE committed Feb 20, 2025
1 parent ba53e60 commit 33fbb4c
Show file tree
Hide file tree
Showing 20 changed files with 185 additions and 173 deletions.
12 changes: 6 additions & 6 deletions integration_test/test/code_generation/app_with_defaults_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defmodule Phoenix.Integration.CodeGeneration.AppWithDefaultsTest do
with_installer_tmp("app_with_defaults", fn tmp_dir ->
{app_root_path, _} = generate_phoenix_app(tmp_dir, "phx_blog")

mix_run!(~w(phx.gen.html Blog Post posts title:unique body:string status:enum:unpublished:published:deleted), app_root_path)
mix_run!(~w(phx.gen.html Blog Post posts title:unique body:string status:enum:unpublished:published:deleted --no-scope), app_root_path)

modify_file(Path.join(app_root_path, "lib/phx_blog_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand All @@ -50,7 +50,7 @@ defmodule Phoenix.Integration.CodeGeneration.AppWithDefaultsTest do
with_installer_tmp("app_with_defaults", fn tmp_dir ->
{app_root_path, _} = generate_phoenix_app(tmp_dir, "phx_blog")

mix_run!(~w(phx.gen.html Blog Post posts title:unique body:string status:enum:unpublished:published:deleted order:integer:unique), app_root_path)
mix_run!(~w(phx.gen.html Blog Post posts title:unique body:string status:enum:unpublished:published:deleted order:integer:unique --no-scope), app_root_path)

modify_file(Path.join(app_root_path, "lib/phx_blog_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand All @@ -74,7 +74,7 @@ defmodule Phoenix.Integration.CodeGeneration.AppWithDefaultsTest do
with_installer_tmp("app_with_defaults", fn tmp_dir ->
{app_root_path, _} = generate_phoenix_app(tmp_dir, "phx_blog")

mix_run!(~w(phx.gen.json Blog Post posts title:unique body:string status:enum:unpublished:published:deleted), app_root_path)
mix_run!(~w(phx.gen.json Blog Post posts title:unique body:string status:enum:unpublished:published:deleted --no-scope), app_root_path)

modify_file(Path.join(app_root_path, "lib/phx_blog_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand All @@ -97,7 +97,7 @@ defmodule Phoenix.Integration.CodeGeneration.AppWithDefaultsTest do
with_installer_tmp("app_with_defaults", fn tmp_dir ->
{app_root_path, _} = generate_phoenix_app(tmp_dir, "phx_blog")

mix_run!(~w(phx.gen.json Blog Post posts title:unique body:string status:enum:unpublished:published:deleted), app_root_path)
mix_run!(~w(phx.gen.json Blog Post posts title:unique body:string status:enum:unpublished:published:deleted --no-scope), app_root_path)

modify_file(Path.join(app_root_path, "lib/phx_blog_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand All @@ -121,7 +121,7 @@ defmodule Phoenix.Integration.CodeGeneration.AppWithDefaultsTest do
with_installer_tmp("app_with_defaults", fn tmp_dir ->
{app_root_path, _} = generate_phoenix_app(tmp_dir, "phx_blog", ["--live"])

mix_run!(~w(phx.gen.live Blog Post posts title:unique body:string p:boolean s:enum:a:b:c), app_root_path)
mix_run!(~w(phx.gen.live Blog Post posts title:unique body:string p:boolean s:enum:a:b:c --no-scope), app_root_path)

modify_file(Path.join(app_root_path, "lib/phx_blog_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand All @@ -147,7 +147,7 @@ defmodule Phoenix.Integration.CodeGeneration.AppWithDefaultsTest do
with_installer_tmp("app_with_defaults", fn tmp_dir ->
{app_root_path, _} = generate_phoenix_app(tmp_dir, "phx_blog", ["--live"])

mix_run!(~w(phx.gen.live Blog Post posts title body:string public:boolean status:enum:unpublished:published:deleted), app_root_path)
mix_run!(~w(phx.gen.live Blog Post posts title body:string public:boolean status:enum:unpublished:published:deleted --no-scope), app_root_path)

modify_file(Path.join(app_root_path, "lib/phx_blog_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Phoenix.Integration.CodeGeneration.AppWithMSSQLAdapterTest do
{app_root_path, _} =
generate_phoenix_app(tmp_dir, "default_mssql_app", ["--database", "mssql"])

mix_run!(~w(phx.gen.html Blog Post posts title body:string status:enum:unpublished:published:deleted), app_root_path)
mix_run!(~w(phx.gen.html Blog Post posts title body:string status:enum:unpublished:published:deleted --no-scope), app_root_path)

modify_file(Path.join(app_root_path, "lib/default_mssql_app_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand All @@ -34,7 +34,7 @@ defmodule Phoenix.Integration.CodeGeneration.AppWithMSSQLAdapterTest do
{app_root_path, _} =
generate_phoenix_app(tmp_dir, "default_mssql_app", ["--database", "mssql"])

mix_run!(~w(phx.gen.json Blog Post posts title body:string status:enum:unpublished:published:deleted), app_root_path)
mix_run!(~w(phx.gen.json Blog Post posts title body:string status:enum:unpublished:published:deleted --no-scope), app_root_path)

modify_file(Path.join(app_root_path, "lib/default_mssql_app_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand All @@ -60,7 +60,7 @@ defmodule Phoenix.Integration.CodeGeneration.AppWithMSSQLAdapterTest do
{app_root_path, _} =
generate_phoenix_app(tmp_dir, "default_mssql_app", ["--database", "mssql", "--live"])

mix_run!(~w(phx.gen.live Blog Post posts title body:string status:enum:unpublished:published:deleted), app_root_path)
mix_run!(~w(phx.gen.live Blog Post posts title body:string status:enum:unpublished:published:deleted --no-scope), app_root_path)

modify_file(Path.join(app_root_path, "lib/default_mssql_app_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand All @@ -87,7 +87,7 @@ defmodule Phoenix.Integration.CodeGeneration.AppWithMSSQLAdapterTest do
with_installer_tmp("new with defaults", fn tmp_dir ->
{app_root_path, _} = generate_phoenix_app(tmp_dir, "phx_blog", ["--database", "mssql", "--live"])

mix_run!(~w(phx.gen.html Accounts Group groups name), app_root_path)
mix_run!(~w(phx.gen.html Accounts Group groups name --no-scope), app_root_path)

modify_file(Path.join(app_root_path, "lib/phx_blog_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand All @@ -111,7 +111,7 @@ defmodule Phoenix.Integration.CodeGeneration.AppWithMSSQLAdapterTest do
with_installer_tmp("new with defaults", fn tmp_dir ->
{app_root_path, _} = generate_phoenix_app(tmp_dir, "phx_blog", ["--database", "mssql", "--live"])

mix_run!(~w(phx.gen.html Accounts Group groups name), app_root_path)
mix_run!(~w(phx.gen.html Accounts Group groups name --no-scope), app_root_path)

modify_file(Path.join(app_root_path, "lib/phx_blog_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand All @@ -136,7 +136,7 @@ defmodule Phoenix.Integration.CodeGeneration.AppWithMSSQLAdapterTest do
with_installer_tmp("app_with_defaults (--live)", fn tmp_dir ->
{app_root_path, _} = generate_phoenix_app(tmp_dir, "phx_blog", ["--database", "mssql", "--live"])

mix_run!(~w(phx.gen.html Accounts Group groups name), app_root_path)
mix_run!(~w(phx.gen.html Accounts Group groups name --no-scope), app_root_path)

modify_file(Path.join(app_root_path, "lib/phx_blog_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand All @@ -161,7 +161,7 @@ defmodule Phoenix.Integration.CodeGeneration.AppWithMSSQLAdapterTest do
with_installer_tmp("app_with_defaults", fn tmp_dir ->
{app_root_path, _} = generate_phoenix_app(tmp_dir, "phx_blog", ["--database", "mssql", "--live"])

mix_run!(~w(phx.gen.html Accounts Group groups name), app_root_path)
mix_run!(~w(phx.gen.html Accounts Group groups name --no-scope), app_root_path)

modify_file(Path.join(app_root_path, "lib/phx_blog_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Phoenix.Integration.CodeGeneration.AppWithMySqlAdapterTest do
{app_root_path, _} =
generate_phoenix_app(tmp_dir, "default_mysql_app", ["--database", "mysql"])

mix_run!(~w(phx.gen.html Blog Post posts title body:string status:enum:unpublished:published:deleted), app_root_path)
mix_run!(~w(phx.gen.html Blog Post posts title body:string status:enum:unpublished:published:deleted --no-scope), app_root_path)

modify_file(Path.join(app_root_path, "lib/default_mysql_app_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand All @@ -34,7 +34,7 @@ defmodule Phoenix.Integration.CodeGeneration.AppWithMySqlAdapterTest do
{app_root_path, _} =
generate_phoenix_app(tmp_dir, "default_mysql_app", ["--database", "mysql"])

mix_run!(~w(phx.gen.json Blog Post posts title body:string status:enum:unpublished:published:deleted), app_root_path)
mix_run!(~w(phx.gen.json Blog Post posts title body:string status:enum:unpublished:published:deleted --no-scope), app_root_path)

modify_file(Path.join(app_root_path, "lib/default_mysql_app_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand All @@ -60,7 +60,7 @@ defmodule Phoenix.Integration.CodeGeneration.AppWithMySqlAdapterTest do
{app_root_path, _} =
generate_phoenix_app(tmp_dir, "default_mysql_app", ["--database", "mysql", "--live"])

mix_run!(~w(phx.gen.live Blog Post posts title body:string status:enum:unpublished:published:deleted), app_root_path)
mix_run!(~w(phx.gen.live Blog Post posts title body:string status:enum:unpublished:published:deleted --no-scope), app_root_path)

modify_file(Path.join(app_root_path, "lib/default_mysql_app_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ defmodule Phoenix.Integration.CodeGeneration.AppWithNoOptionsTest do
[
"--no-halt",
"-e",
"spawn fn -> IO.gets('') && System.halt(0) end",
"spawn fn -> IO.gets(~c[]) && System.halt(0) end",
"-S",
"mix",
"phx.server"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Phoenix.Integration.CodeGeneration.AppWithSQLite3AdapterTest do
{app_root_path, _} =
generate_phoenix_app(tmp_dir, "default_sqlite3_app", ["--database", "sqlite3"])

mix_run!(~w(phx.gen.html Blog Post posts title body:string status:enum:unpublished:published:deleted), app_root_path)
mix_run!(~w(phx.gen.html Blog Post posts title body:string status:enum:unpublished:published:deleted --no-scope), app_root_path)

modify_file(Path.join(app_root_path, "lib/default_sqlite3_app_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand All @@ -34,7 +34,7 @@ defmodule Phoenix.Integration.CodeGeneration.AppWithSQLite3AdapterTest do
{app_root_path, _} =
generate_phoenix_app(tmp_dir, "default_sqlite3_app", ["--database", "sqlite3"])

mix_run!(~w(phx.gen.json Blog Post posts title body:string status:enum:unpublished:published:deleted), app_root_path)
mix_run!(~w(phx.gen.json Blog Post posts title body:string status:enum:unpublished:published:deleted --no-scope), app_root_path)

modify_file(Path.join(app_root_path, "lib/default_sqlite3_app_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand All @@ -60,7 +60,7 @@ defmodule Phoenix.Integration.CodeGeneration.AppWithSQLite3AdapterTest do
{app_root_path, _} =
generate_phoenix_app(tmp_dir, "default_sqlite3_app", ["--database", "sqlite3", "--live"])

mix_run!(~w(phx.gen.live Blog Post posts title body:string status:enum:unpublished:published:deleted), app_root_path)
mix_run!(~w(phx.gen.live Blog Post posts title body:string status:enum:unpublished:published:deleted --no-scope), app_root_path)

modify_file(Path.join(app_root_path, "lib/default_sqlite3_app_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ defmodule Phoenix.Integration.CodeGeneration.UmbrellaAppWithDefaultsTest do
{app_root_path, _} = generate_phoenix_app(tmp_dir, "rainy_day", ["--umbrella"])
web_root_path = Path.join(app_root_path, "apps/rainy_day_web")

mix_run!(~w(phx.gen.html Blog Post posts title:unique body:string status:enum:unpublished:published:deleted), web_root_path)
mix_run!(~w(phx.gen.html Blog Post posts title:unique body:string status:enum:unpublished:published:deleted --no-scope), web_root_path)

modify_file(Path.join(web_root_path, "lib/rainy_day_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand All @@ -53,7 +53,7 @@ defmodule Phoenix.Integration.CodeGeneration.UmbrellaAppWithDefaultsTest do
{app_root_path, _} = generate_phoenix_app(tmp_dir, "rainy_day", ["--umbrella"])
web_root_path = Path.join(app_root_path, "apps/rainy_day_web")

mix_run!(~w(phx.gen.html Blog Post posts title body:string status:enum:unpublished:published:deleted), web_root_path)
mix_run!(~w(phx.gen.html Blog Post posts title body:string status:enum:unpublished:published:deleted --no-scope), web_root_path)

modify_file(Path.join(web_root_path, "lib/rainy_day_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand All @@ -78,7 +78,7 @@ defmodule Phoenix.Integration.CodeGeneration.UmbrellaAppWithDefaultsTest do
{app_root_path, _} = generate_phoenix_app(tmp_dir, "rainy_day", ["--umbrella"])
web_root_path = Path.join(app_root_path, "apps/rainy_day_web")

mix_run!(~w(phx.gen.json Blog Post posts title:unique body:string status:enum:unpublished:published:deleted), web_root_path)
mix_run!(~w(phx.gen.json Blog Post posts title:unique body:string status:enum:unpublished:published:deleted --no-scope), web_root_path)

modify_file(Path.join(web_root_path, "lib/rainy_day_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand All @@ -102,7 +102,7 @@ defmodule Phoenix.Integration.CodeGeneration.UmbrellaAppWithDefaultsTest do
{app_root_path, _} = generate_phoenix_app(tmp_dir, "rainy_day", ["--umbrella"])
web_root_path = Path.join(app_root_path, "apps/rainy_day_web")

mix_run!(~w(phx.gen.json Blog Post posts title body:string status:enum:unpublished:published:deleted), web_root_path)
mix_run!(~w(phx.gen.json Blog Post posts title body:string status:enum:unpublished:published:deleted --no-scope), web_root_path)

modify_file(Path.join(web_root_path, "lib/rainy_day_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand All @@ -127,7 +127,7 @@ defmodule Phoenix.Integration.CodeGeneration.UmbrellaAppWithDefaultsTest do
{app_root_path, _} = generate_phoenix_app(tmp_dir, "rainy_day", ["--umbrella", "--live"])
web_root_path = Path.join(app_root_path, "apps/rainy_day_web")

mix_run!(~w(phx.gen.live Blog Post posts title:unique body:string status:enum:unpublished:published:deleted), web_root_path)
mix_run!(~w(phx.gen.live Blog Post posts title:unique body:string status:enum:unpublished:published:deleted --no-scope), web_root_path)

modify_file(Path.join(web_root_path, "lib/rainy_day_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand All @@ -154,7 +154,7 @@ defmodule Phoenix.Integration.CodeGeneration.UmbrellaAppWithDefaultsTest do
{app_root_path, _} = generate_phoenix_app(tmp_dir, "rainy_day", ["--umbrella", "--live"])
web_root_path = Path.join(app_root_path, "apps/rainy_day_web")

mix_run!(~w(phx.gen.live Blog Post posts title body:string status:enum:unpublished:published:deleted), web_root_path)
mix_run!(~w(phx.gen.live Blog Post posts title body:string status:enum:unpublished:published:deleted --no-scope), web_root_path)

modify_file(Path.join(web_root_path, "lib/rainy_day_web/router.ex"), fn file ->
inject_before_final_end(file, """
Expand Down
1 change: 1 addition & 0 deletions lib/mix/phoenix/scope.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule Mix.Phoenix.Scope do
alias: nil,
assign_key: nil,
access_path: nil,
schema_table: nil,
schema_key: nil,
schema_type: nil

Expand Down
2 changes: 1 addition & 1 deletion lib/mix/tasks/phx.gen.auth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ defmodule Mix.Tasks.Phx.Gen.Auth do
hashing_library = build_hashing_library!(opts)

context_args = OptionParser.to_argv(opts, switches: @switches) ++ parsed
{context, schema} = Gen.Context.build(context_args, __MODULE__)
{context, schema} = Gen.Context.build(context_args ++ ["--no-scope"], __MODULE__)

context = put_live_option(context)
Gen.Context.prompt_for_code_injection(context)
Expand Down
9 changes: 5 additions & 4 deletions lib/mix/tasks/phx.gen.html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ defmodule Mix.Tasks.Phx.Gen.Html do
{context, schema} = Gen.Context.build(args)
Gen.Context.prompt_for_code_injection(context)

conn_scope = if schema.scope do
"conn.assigns.#{schema.scope.assign_key}"
{conn_scope, context_scope_prefix} = if schema.scope do
base = "conn.assigns.#{schema.scope.assign_key}"
{base, "#{base}, "}
else
""
{"", ""}
end

binding = [
Expand All @@ -120,7 +121,7 @@ defmodule Mix.Tasks.Phx.Gen.Html do
scope: schema.scope,
inputs: inputs(schema),
conn_scope: conn_scope,
context_scope_prefix: "#{conn_scope}, "
context_scope_prefix: context_scope_prefix
]
paths = Mix.Phoenix.generator_paths()

Expand Down
9 changes: 5 additions & 4 deletions lib/mix/tasks/phx.gen.json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ defmodule Mix.Tasks.Phx.Gen.Json do
{context, schema} = Gen.Context.build(args)
Gen.Context.prompt_for_code_injection(context)

conn_scope = if schema.scope do
"conn.assigns.#{schema.scope.assign_key}"
{conn_scope, context_scope_prefix} = if schema.scope do
base = "conn.assigns.#{schema.scope.assign_key}"
{base, "#{base}, "}
else
""
{"", ""}
end

binding = [
Expand All @@ -117,7 +118,7 @@ defmodule Mix.Tasks.Phx.Gen.Json do
gettext?: Code.ensure_loaded?(Module.concat(context.web_module, "Gettext")),
primary_key: schema.opts[:primary_key] || :id,
conn_scope: conn_scope,
context_scope_prefix: "#{conn_scope}, "
context_scope_prefix: context_scope_prefix
]

paths = Mix.Phoenix.generator_paths()
Expand Down
9 changes: 5 additions & 4 deletions lib/mix/tasks/phx.gen.live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,11 @@ defmodule Mix.Tasks.Phx.Gen.Live do

Gen.Context.prompt_for_code_injection(context)

socket_scope = if schema.scope do
"socket.assigns.#{schema.scope.assign_key}"
{socket_scope, context_scope_prefix} = if schema.scope do
base = "socket.assigns.#{schema.scope.assign_key}"
{base, "#{base}, "}
else
""
{"", ""}
end

binding = [
Expand All @@ -133,7 +134,7 @@ defmodule Mix.Tasks.Phx.Gen.Live do
scope: schema.scope,
inputs: inputs(schema),
socket_scope: socket_scope,
context_scope_prefix: "#{socket_scope}, "
context_scope_prefix: context_scope_prefix
]
paths = Mix.Phoenix.generator_paths()

Expand Down
5 changes: 3 additions & 2 deletions priv/templates/phx.gen.context/fixtures.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
<%= schema.fixture_params |> Enum.map(fn {key, code} -> " #{key}: #{code}" end) |> Enum.join(",\n") %>
})

{:ok, <%= schema.singular %>} = <%= inspect context.module %>.create_<%= schema.singular %>(scope, attrs)<% else %>{:ok, <%= schema.singular %>} =
{:ok, <%= schema.singular %>} = <%= inspect context.module %>.create_<%= schema.singular %>(scope, attrs)<% else %>
{:ok, <%= schema.singular %>} =
attrs
|> Enum.into(%{
<%= schema.fixture_params |> Enum.map(fn {key, code} -> " #{key}: #{code}" end) |> Enum.join(",\n") %>
})
|> <%= inspect context.module %>.create_<%= schema.singular %>()
<% end %>
<% end %>
<%= schema.singular %>
end
Loading

0 comments on commit 33fbb4c

Please sign in to comment.