From 33fbb4c247ac0334dad5f6bf6128e7d2cd282514 Mon Sep 17 00:00:00 2001 From: Steffen Deusch Date: Thu, 20 Feb 2025 16:58:25 +0100 Subject: [PATCH] use --no-scope in tests for now --- .../app_with_defaults_test.exs | 12 ++-- .../app_with_mssql_adapter_test.exs | 14 ++-- .../app_with_mysql_adapter_test.exs | 6 +- .../app_with_no_options_test.exs | 2 +- .../app_with_sqlite3_adapter.exs | 6 +- .../umbrella_app_with_defaults_test.exs | 12 ++-- lib/mix/phoenix/scope.ex | 1 + lib/mix/tasks/phx.gen.auth.ex | 2 +- lib/mix/tasks/phx.gen.html.ex | 9 +-- lib/mix/tasks/phx.gen.json.ex | 9 +-- lib/mix/tasks/phx.gen.live.ex | 9 +-- priv/templates/phx.gen.context/fixtures.ex | 5 +- priv/templates/phx.gen.schema/migration.exs | 2 +- test/mix/tasks/phx.gen.auth/injector_test.exs | 24 +++---- test/mix/tasks/phx.gen.context_test.exs | 38 ++++++----- test/mix/tasks/phx.gen.embedded_test.exs | 14 ++-- test/mix/tasks/phx.gen.html_test.exs | 45 ++++++------- test/mix/tasks/phx.gen.json_test.exs | 39 +++++------ test/mix/tasks/phx.gen.live_test.exs | 43 ++++++------ test/mix/tasks/phx.gen.schema_test.exs | 66 ++++++++++--------- 20 files changed, 185 insertions(+), 173 deletions(-) diff --git a/integration_test/test/code_generation/app_with_defaults_test.exs b/integration_test/test/code_generation/app_with_defaults_test.exs index 57d069f794..135b86f7da 100644 --- a/integration_test/test/code_generation/app_with_defaults_test.exs +++ b/integration_test/test/code_generation/app_with_defaults_test.exs @@ -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, """ @@ -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, """ @@ -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, """ @@ -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, """ @@ -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, """ @@ -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, """ diff --git a/integration_test/test/code_generation/app_with_mssql_adapter_test.exs b/integration_test/test/code_generation/app_with_mssql_adapter_test.exs index 96ca203de2..d361709dea 100644 --- a/integration_test/test/code_generation/app_with_mssql_adapter_test.exs +++ b/integration_test/test/code_generation/app_with_mssql_adapter_test.exs @@ -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, """ @@ -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, """ @@ -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, """ @@ -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, """ @@ -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, """ @@ -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, """ @@ -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, """ diff --git a/integration_test/test/code_generation/app_with_mysql_adapter_test.exs b/integration_test/test/code_generation/app_with_mysql_adapter_test.exs index 0886d421f9..342c6654a8 100644 --- a/integration_test/test/code_generation/app_with_mysql_adapter_test.exs +++ b/integration_test/test/code_generation/app_with_mysql_adapter_test.exs @@ -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, """ @@ -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, """ @@ -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, """ diff --git a/integration_test/test/code_generation/app_with_no_options_test.exs b/integration_test/test/code_generation/app_with_no_options_test.exs index daf153814b..8b92626ba2 100644 --- a/integration_test/test/code_generation/app_with_no_options_test.exs +++ b/integration_test/test/code_generation/app_with_no_options_test.exs @@ -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" diff --git a/integration_test/test/code_generation/app_with_sqlite3_adapter.exs b/integration_test/test/code_generation/app_with_sqlite3_adapter.exs index 4576a6cfc0..1b5d586b97 100644 --- a/integration_test/test/code_generation/app_with_sqlite3_adapter.exs +++ b/integration_test/test/code_generation/app_with_sqlite3_adapter.exs @@ -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, """ @@ -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, """ @@ -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, """ diff --git a/integration_test/test/code_generation/umbrella_app_with_defaults_test.exs b/integration_test/test/code_generation/umbrella_app_with_defaults_test.exs index 9dc71ba64d..1532a142cd 100644 --- a/integration_test/test/code_generation/umbrella_app_with_defaults_test.exs +++ b/integration_test/test/code_generation/umbrella_app_with_defaults_test.exs @@ -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, """ @@ -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, """ @@ -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, """ @@ -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, """ @@ -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, """ @@ -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, """ diff --git a/lib/mix/phoenix/scope.ex b/lib/mix/phoenix/scope.ex index 78a48c3f51..de89eece79 100644 --- a/lib/mix/phoenix/scope.ex +++ b/lib/mix/phoenix/scope.ex @@ -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 diff --git a/lib/mix/tasks/phx.gen.auth.ex b/lib/mix/tasks/phx.gen.auth.ex index 737d82d15d..cb83d410bf 100644 --- a/lib/mix/tasks/phx.gen.auth.ex +++ b/lib/mix/tasks/phx.gen.auth.ex @@ -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) diff --git a/lib/mix/tasks/phx.gen.html.ex b/lib/mix/tasks/phx.gen.html.ex index c11f100fe3..b5f5789057 100644 --- a/lib/mix/tasks/phx.gen.html.ex +++ b/lib/mix/tasks/phx.gen.html.ex @@ -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 = [ @@ -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() diff --git a/lib/mix/tasks/phx.gen.json.ex b/lib/mix/tasks/phx.gen.json.ex index d94b975415..2783c34050 100644 --- a/lib/mix/tasks/phx.gen.json.ex +++ b/lib/mix/tasks/phx.gen.json.ex @@ -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 = [ @@ -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() diff --git a/lib/mix/tasks/phx.gen.live.ex b/lib/mix/tasks/phx.gen.live.ex index 0dbd9c1f76..d5a94f2ded 100644 --- a/lib/mix/tasks/phx.gen.live.ex +++ b/lib/mix/tasks/phx.gen.live.ex @@ -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 = [ @@ -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() diff --git a/priv/templates/phx.gen.context/fixtures.ex b/priv/templates/phx.gen.context/fixtures.ex index ac9167f1b2..c44257f341 100644 --- a/priv/templates/phx.gen.context/fixtures.ex +++ b/priv/templates/phx.gen.context/fixtures.ex @@ -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 diff --git a/priv/templates/phx.gen.schema/migration.exs b/priv/templates/phx.gen.schema/migration.exs index d17ca498f8..0fdab9f365 100644 --- a/priv/templates/phx.gen.schema/migration.exs +++ b/priv/templates/phx.gen.schema/migration.exs @@ -7,7 +7,7 @@ defmodule <%= inspect schema.repo %>.Migrations.Create<%= Macro.camelize(schema. <% else %><%= if schema.opts[:primary_key] do %> add :<%= schema.opts[:primary_key] %>, :id, primary_key: true <% end %><% end %><%= for {k, v} <- schema.attrs do %> add <%= inspect k %>, <%= inspect Mix.Phoenix.Schema.type_for_migration(v) %><%= schema.migration_defaults[k] %> <% end %><%= for {_, i, _, s} <- schema.assocs do %> add <%= inspect(i) %>, references(<%= inspect(s) %>, on_delete: :nothing<%= if schema.binary_id do %>, type: :binary_id<% end %>) -<% end %><%= if scope do %> add :<%= scope.schema_key %>, references(:<%= scope.access_path |> Enum.at(0) %>, on_delete: :delete_all) +<% end %><%= if scope do %> add :<%= scope.schema_key %>, references(:<%= scope.schema_table %>, on_delete: :delete_all) <% end %> timestamps(<%= if schema.timestamp_type != :naive_datetime, do: "type: #{inspect schema.timestamp_type}" %>) end diff --git a/test/mix/tasks/phx.gen.auth/injector_test.exs b/test/mix/tasks/phx.gen.auth/injector_test.exs index d526af98cb..869ccfb404 100644 --- a/test/mix/tasks/phx.gen.auth/injector_test.exs +++ b/test/mix/tasks/phx.gen.auth/injector_test.exs @@ -468,7 +468,7 @@ defmodule Mix.Tasks.Phx.Gen.Auth.InjectorTest do describe "router_plug_inject/2" do test "injects after :put_secure_browser_headers" do - schema = Schema.new("Accounts.User", "users", [], []) + schema = Schema.new("Accounts.User", "users", [], [no_scope: true]) context = Context.new("Accounts", schema, []) input = """ @@ -505,7 +505,7 @@ defmodule Mix.Tasks.Phx.Gen.Auth.InjectorTest do end test "injects after :put_secure_browser_headers even when it has additional options" do - schema = Schema.new("Accounts.User", "users", [], []) + schema = Schema.new("Accounts.User", "users", [], [no_scope: true]) context = Context.new("Accounts", schema, []) input = """ @@ -542,7 +542,7 @@ defmodule Mix.Tasks.Phx.Gen.Auth.InjectorTest do end test "respects windows line endings" do - schema = Schema.new("Accounts.User", "users", [], []) + schema = Schema.new("Accounts.User", "users", [], [no_scope: true]) context = Context.new("Accounts", schema, []) input = """ @@ -579,7 +579,7 @@ defmodule Mix.Tasks.Phx.Gen.Auth.InjectorTest do end test "errors when :put_secure_browser_headers_is_missing" do - schema = Schema.new("Accounts.User", "users", [], []) + schema = Schema.new("Accounts.User", "users", [], [no_scope: true]) context = Context.new("Accounts", schema, []) input = """ @@ -601,7 +601,7 @@ defmodule Mix.Tasks.Phx.Gen.Auth.InjectorTest do describe "router_plug_help_text/2" do test "returns a string with the expected help text" do - schema = Schema.new("Accounts.User", "users", [], []) + schema = Schema.new("Accounts.User", "users", [], [no_scope: true]) context = Context.new("Accounts", schema, []) file_path = Path.expand("foo.ex") @@ -621,7 +621,7 @@ defmodule Mix.Tasks.Phx.Gen.Auth.InjectorTest do describe "app_layout_menu_inject/2" do test "injects user menu at the bottom of nav section when it exists" do - schema = Schema.new("Accounts.User", "users", [], []) + schema = Schema.new("Accounts.User", "users", [], [no_scope: true]) template = """ @@ -715,7 +715,7 @@ defmodule Mix.Tasks.Phx.Gen.Auth.InjectorTest do end test "injects user menu at the bottom of nav section when it exists with windows line endings" do - schema = Schema.new("Accounts.User", "users", [], []) + schema = Schema.new("Accounts.User", "users", [], [no_scope: true]) template = """ \r @@ -809,7 +809,7 @@ defmodule Mix.Tasks.Phx.Gen.Auth.InjectorTest do end test "injects render user_menu after the opening body tag" do - schema = Schema.new("Accounts.User", "users", [], []) + schema = Schema.new("Accounts.User", "users", [], [no_scope: true]) template = """ @@ -889,7 +889,7 @@ defmodule Mix.Tasks.Phx.Gen.Auth.InjectorTest do end test "works with windows line endings" do - schema = Schema.new("Accounts.User", "users", [], []) + schema = Schema.new("Accounts.User", "users", [], [no_scope: true]) template = """ \r @@ -969,7 +969,7 @@ defmodule Mix.Tasks.Phx.Gen.Auth.InjectorTest do end test "returns :already_injected when render is already found in file" do - schema = Schema.new("Accounts.User", "users", [], []) + schema = Schema.new("Accounts.User", "users", [], [no_scope: true]) template = """ @@ -1003,14 +1003,14 @@ defmodule Mix.Tasks.Phx.Gen.Auth.InjectorTest do end test "returns {:error, :unable_to_inject} when the body tag isn't found" do - schema = Schema.new("Accounts.User", "users", [], []) + schema = Schema.new("Accounts.User", "users", [], [no_scope: true]) assert {:error, :unable_to_inject} = Injector.app_layout_menu_inject(schema, "") end end describe "app_layout_menu_help_text/2" do test "returns a string with the expected help text" do - schema = Schema.new("Accounts.User", "users", [], []) + schema = Schema.new("Accounts.User", "users", [], [no_scope: true]) file_path = Path.expand("foo.ex") assert Injector.app_layout_menu_help_text(file_path, schema) =~ diff --git a/test/mix/tasks/phx.gen.context_test.exs b/test/mix/tasks/phx.gen.context_test.exs index eb6c587162..fcc8c3836e 100644 --- a/test/mix/tasks/phx.gen.context_test.exs +++ b/test/mix/tasks/phx.gen.context_test.exs @@ -16,7 +16,7 @@ defmodule Mix.Tasks.Phx.Gen.ContextTest do test "new context", config do in_tmp_project(config.test, fn -> - schema = Schema.new("Blog.Post", "posts", [], []) + schema = Schema.new("Blog.Post", "posts", [], [no_scope: true]) context = Context.new("Blog", schema, []) assert %Context{ @@ -50,7 +50,7 @@ defmodule Mix.Tasks.Phx.Gen.ContextTest do test "new nested context", config do in_tmp_project(config.test, fn -> - schema = Schema.new("Site.Blog.Post", "posts", [], []) + schema = Schema.new("Site.Blog.Post", "posts", [], [no_scope: true]) context = Context.new("Site.Blog", schema, []) assert %Context{ @@ -91,7 +91,7 @@ defmodule Mix.Tasks.Phx.Gen.ContextTest do end """) - schema = Schema.new("Blog.Post", "posts", [], []) + schema = Schema.new("Blog.Post", "posts", [], [no_scope: true]) context = Context.new("Blog", schema, []) assert Context.pre_existing?(context) refute Context.pre_existing_tests?(context) @@ -120,42 +120,42 @@ defmodule Mix.Tasks.Phx.Gen.ContextTest do test "invalid mix arguments", config do in_tmp_project(config.test, fn -> assert_raise Mix.Error, ~r/Expected the context, "blog", to be a valid module name/, fn -> - Gen.Context.run(~w(blog Post posts title:string)) + Gen.Context.run(~w(blog Post posts title:string --no-scope)) end assert_raise Mix.Error, ~r/Expected the schema, "posts", to be a valid module name/, fn -> - Gen.Context.run(~w(Post posts title:string)) + Gen.Context.run(~w(Post posts title:string --no-scope)) end assert_raise Mix.Error, ~r/The context and schema should have different names/, fn -> - Gen.Context.run(~w(Blog Blog blogs)) + Gen.Context.run(~w(Blog Blog blogs --no-scope)) end assert_raise Mix.Error, ~r/Cannot generate context Phoenix because it has the same name as the application/, fn -> - Gen.Context.run(~w(Phoenix Post blogs)) + Gen.Context.run(~w(Phoenix Post blogs --no-scope)) end assert_raise Mix.Error, ~r/Cannot generate schema Phoenix because it has the same name as the application/, fn -> - Gen.Context.run(~w(Blog Phoenix blogs)) + Gen.Context.run(~w(Blog Phoenix blogs --no-scope)) end assert_raise Mix.Error, ~r/Invalid arguments/, fn -> - Gen.Context.run(~w(Blog.Post posts)) + Gen.Context.run(~w(Blog.Post posts --no-scope)) end assert_raise Mix.Error, ~r/Invalid arguments/, fn -> - Gen.Context.run(~w(Blog Post)) + Gen.Context.run(~w(Blog Post --no-scope)) end end) end test "generates context and handles existing contexts", config do in_tmp_project(config.test, fn -> - Gen.Context.run(~w(Blog Post posts slug:unique secret:redact title:string)) + Gen.Context.run(~w(Blog Post posts slug:unique secret:redact title:string --no-scope)) assert_file("lib/phoenix/blog/post.ex", fn file -> assert file =~ "field :title, :string" @@ -193,7 +193,7 @@ defmodule Mix.Tasks.Phx.Gen.ContextTest do end) send(self(), {:mix_shell_input, :yes?, true}) - Gen.Context.run(~w(Blog Comment comments title:string)) + Gen.Context.run(~w(Blog Comment comments title:string --no-scope)) assert_received {:mix_shell, :info, ["You are generating into an existing context" <> notice]} @@ -248,6 +248,7 @@ defmodule Mix.Tasks.Phx.Gen.ContextTest do published_at:utc_datetime:unique author:references:users:unique published?:boolean + --no-scope )) assert_received {:mix_shell, :info, @@ -319,6 +320,7 @@ defmodule Mix.Tasks.Phx.Gen.ContextTest do subject:unique body:text:unique order:integer:unique + --no-scope )) refute_received {:mix_shell, :info, @@ -329,7 +331,7 @@ defmodule Mix.Tasks.Phx.Gen.ContextTest do test "generates into existing context without prompt with --merge-with-existing-context", config do in_tmp_project(config.test, fn -> - Gen.Context.run(~w(Blog Post posts title)) + Gen.Context.run(~w(Blog Post posts title --no-scope)) assert_file("lib/phoenix/blog.ex", fn file -> assert file =~ "def get_post!" @@ -340,7 +342,7 @@ defmodule Mix.Tasks.Phx.Gen.ContextTest do assert file =~ "def change_post" end) - Gen.Context.run(~w(Blog Comment comments message:string --merge-with-existing-context)) + Gen.Context.run(~w(Blog Comment comments message:string --merge-with-existing-context --no-scope)) refute_received {:mix_shell, :info, ["You are generating into an existing context" <> _notice]} @@ -359,7 +361,7 @@ defmodule Mix.Tasks.Phx.Gen.ContextTest do test "when more than 50 attributes are given", config do in_tmp_project(config.test, fn -> long_attribute_list = Enum.map_join(0..55, " ", &"attribute#{&1}:string") - Gen.Context.run(~w(Blog Post posts title #{long_attribute_list})) + Gen.Context.run(~w(Blog Post posts title #{long_attribute_list} --no-scope)) assert_file("test/phoenix/blog_test.exs", fn file -> refute file =~ "...}" @@ -369,7 +371,7 @@ defmodule Mix.Tasks.Phx.Gen.ContextTest do test "generates schema with no migration option", config do in_tmp_project(config.test, fn -> - Gen.Context.run(~w(Blog Post posts title:string --no-migration)) + Gen.Context.run(~w(Blog Post posts title:string --no-migration --no-scope)) assert Path.wildcard("priv/repo/migrations/*") == [] end) @@ -377,7 +379,7 @@ defmodule Mix.Tasks.Phx.Gen.ContextTest do test "generates context with no schema and repo option", config do in_tmp_project(config.test, fn -> - Gen.Context.run(~w(Blog Post posts title:string --no-schema --repo=Foo.RepoX)) + Gen.Context.run(~w(Blog Post posts title:string --no-schema --repo=Foo.RepoX --no-scope)) refute_file("lib/phoenix/blog/post.ex") @@ -411,7 +413,7 @@ defmodule Mix.Tasks.Phx.Gen.ContextTest do test "generates context with enum", config do in_tmp_project(config.test, fn -> Gen.Context.run( - ~w(Accounts User users email:text:unique password:text:redact status:enum:verified:unverified:disabled) + ~w(Accounts User users email:text:unique password:text:redact status:enum:verified:unverified:disabled --no-scope) ) assert_file("lib/phoenix/accounts/user.ex", fn file -> diff --git a/test/mix/tasks/phx.gen.embedded_test.exs b/test/mix/tasks/phx.gen.embedded_test.exs index 1bc02c67b4..c3258d149d 100644 --- a/test/mix/tasks/phx.gen.embedded_test.exs +++ b/test/mix/tasks/phx.gen.embedded_test.exs @@ -13,7 +13,7 @@ defmodule Mix.Tasks.Phx.Gen.EmbeddedTest do test "build" do in_tmp_project("embedded build", fn -> - schema = Gen.Embedded.build(~w(Blog.Post title:string)) + schema = Gen.Embedded.build(~w(Blog.Post title:string --no-scope)) assert %Schema{ alias: Post, @@ -37,7 +37,7 @@ defmodule Mix.Tasks.Phx.Gen.EmbeddedTest do test "generates embedded schema", config do in_tmp_project(config.test, fn -> - Gen.Embedded.run(~w(Blog.Post title:string)) + Gen.Embedded.run(~w(Blog.Post title:string --no-scope)) assert_file("lib/phoenix/blog/post.ex", fn file -> assert file =~ "embedded_schema do" @@ -47,7 +47,7 @@ defmodule Mix.Tasks.Phx.Gen.EmbeddedTest do test "generates nested embedded schema", config do in_tmp_project(config.test, fn -> - Gen.Embedded.run(~w(Blog.Admin.User name:string)) + Gen.Embedded.run(~w(Blog.Admin.User name:string --no-scope)) assert_file("lib/phoenix/blog/admin/user.ex", fn file -> assert file =~ "defmodule Phoenix.Blog.Admin.User do" @@ -59,7 +59,7 @@ defmodule Mix.Tasks.Phx.Gen.EmbeddedTest do test "generates embedded schema with proper datetime types", config do in_tmp_project(config.test, fn -> Gen.Embedded.run( - ~w(Blog.Comment title:string drafted_at:datetime published_at:naive_datetime edited_at:utc_datetime) + ~w(Blog.Comment title:string drafted_at:datetime published_at:naive_datetime edited_at:utc_datetime --no-scope) ) assert_file("lib/phoenix/blog/comment.ex", fn file -> @@ -73,7 +73,7 @@ defmodule Mix.Tasks.Phx.Gen.EmbeddedTest do test "generates embedded schema with enum", config do in_tmp_project(config.test, fn -> Gen.Embedded.run( - ~w(Blog.Comment comments title:string status:enum:unpublished:published:deleted) + ~w(Blog.Comment comments title:string status:enum:unpublished:published:deleted --no-scope) ) assert_file("lib/phoenix/blog/comment.ex", fn file -> @@ -84,7 +84,7 @@ defmodule Mix.Tasks.Phx.Gen.EmbeddedTest do test "generates embedded schema with redact option", config do in_tmp_project(config.test, fn -> - Gen.Embedded.run(~w(Blog.Comment comments title:string secret:redact)) + Gen.Embedded.run(~w(Blog.Comment comments title:string secret:redact --no-scope)) assert_file("lib/phoenix/blog/comment.ex", fn file -> assert file =~ "field :secret, :string, redact: true" @@ -95,7 +95,7 @@ defmodule Mix.Tasks.Phx.Gen.EmbeddedTest do test "generates embedded schema with references", config do in_tmp_project(config.test, fn -> Gen.Embedded.run( - ~w(Blog.Comment comments body word_count:integer author_id:references:author) + ~w(Blog.Comment comments body word_count:integer author_id:references:author --no-scope) ) assert_file("lib/phoenix/blog/comment.ex", fn file -> diff --git a/test/mix/tasks/phx.gen.html_test.exs b/test/mix/tasks/phx.gen.html_test.exs index 53b51e58d8..7a26402dd6 100644 --- a/test/mix/tasks/phx.gen.html_test.exs +++ b/test/mix/tasks/phx.gen.html_test.exs @@ -13,27 +13,27 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do test "invalid mix arguments", config do in_tmp_project(config.test, fn -> assert_raise Mix.Error, ~r/Expected the context, "blog", to be a valid module name/, fn -> - Gen.Html.run(~w(blog Post posts title:string)) + Gen.Html.run(~w(blog Post posts title:string --no-scope)) end assert_raise Mix.Error, ~r/Expected the schema, "posts", to be a valid module name/, fn -> - Gen.Html.run(~w(Post posts title:string)) + Gen.Html.run(~w(Post posts title:string --no-scope)) end assert_raise Mix.Error, ~r/The context and schema should have different names/, fn -> - Gen.Html.run(~w(Blog Blog blogs)) + Gen.Html.run(~w(Blog Blog blogs --no-scope)) end assert_raise Mix.Error, ~r/Invalid arguments/, fn -> - Gen.Html.run(~w(Blog.Post posts)) + Gen.Html.run(~w(Blog.Post posts --no-scope)) end assert_raise Mix.Error, ~r/Invalid arguments/, fn -> - Gen.Html.run(~w(Blog Post)) + Gen.Html.run(~w(Blog Post --no-scope)) end assert_raise Mix.Error, ~r/Enum type requires at least one value/, fn -> - Gen.Html.run(~w(Blog Post posts status:enum)) + Gen.Html.run(~w(Blog Post posts status:enum --no-scope)) end end) end @@ -55,7 +55,8 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do alarm_usec:time_usec secret:uuid:redact announcement_date:date alarm:time metadata:map - weight:float user_id:references:users)) + weight:float user_id:references:users + --no-scope)) assert_file("lib/phoenix/blog/post.ex") assert_file("lib/phoenix/blog.ex") @@ -184,7 +185,7 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do end) send(self(), {:mix_shell_input, :yes?, true}) - Gen.Html.run(~w(Blog Comment comments title:string)) + Gen.Html.run(~w(Blog Comment comments title:string --no-scope)) assert_received {:mix_shell, :info, ["You are generating into an existing context" <> _]} assert_file("lib/phoenix/blog/comment.ex") @@ -227,7 +228,7 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do test "generates into existing context without prompt with --merge-with-existing-context", config do in_tmp_project(config.test, fn -> - Gen.Html.run(~w(Blog Post posts title)) + Gen.Html.run(~w(Blog Post posts title --no-scope)) assert_file("lib/phoenix/blog.ex", fn file -> assert file =~ "def get_post!" @@ -238,7 +239,7 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do assert file =~ "def change_post" end) - Gen.Html.run(~w(Blog Comment comments message:string --merge-with-existing-context)) + Gen.Html.run(~w(Blog Comment comments message:string --merge-with-existing-context --no-scope)) refute_received {:mix_shell, :info, ["You are generating into an existing context" <> _notice]} @@ -256,7 +257,7 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do test "with --web namespace generates namespaced web modules and directories", config do in_tmp_project(config.test, fn -> - Gen.Html.run(~w(Blog Post posts title:string --web Blog)) + Gen.Html.run(~w(Blog Post posts title:string --web Blog --no-scope)) assert_file("test/phoenix_web/controllers/blog/post_controller_test.exs", fn file -> assert file =~ "defmodule PhoenixWeb.Blog.PostControllerTest" @@ -307,7 +308,7 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do test "with --no-context skips context and schema file generation", config do in_tmp_project(config.test, fn -> - Gen.Html.run(~w(Blog Comment comments title:string --no-context)) + Gen.Html.run(~w(Blog Comment comments title:string --no-context --no-scope)) refute_file("lib/phoenix/blog.ex") refute_file("lib/phoenix/blog/comment.ex") @@ -330,7 +331,7 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do test "with a matching plural and singular term", config do in_tmp_project(config.test, fn -> - Gen.Html.run(~w(Tracker Series series value:integer)) + Gen.Html.run(~w(Tracker Series series value:integer --no-scope)) assert_file("lib/phoenix_web/controllers/series_controller.ex", fn file -> assert file =~ "render(conn, :index, series_collection: series)" end) @@ -339,12 +340,12 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do test "with --no-context no warning is emitted when context exists", config do in_tmp_project(config.test, fn -> - Gen.Html.run(~w(Blog Post posts title:string)) + Gen.Html.run(~w(Blog Post posts title:string --no-scope)) assert_file("lib/phoenix/blog.ex") assert_file("lib/phoenix/blog/post.ex") - Gen.Html.run(~w(Blog Comment comments title:string --no-context)) + Gen.Html.run(~w(Blog Comment comments title:string --no-context --no-scope)) refute_received {:mix_shell, :info, ["You are generating into an existing context" <> _]} assert_file("test/phoenix_web/controllers/comment_controller_test.exs", fn file -> @@ -364,7 +365,7 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do test "with --no-schema skips schema file generation", config do in_tmp_project(config.test, fn -> - Gen.Html.run(~w(Blog Comment comments title:string --no-schema)) + Gen.Html.run(~w(Blog Comment comments title:string --no-schema --no-scope)) assert_file("lib/phoenix/blog.ex") refute_file("lib/phoenix/blog/comment.ex") @@ -388,7 +389,7 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do test "when more than 50 arguments are given", config do in_tmp_project(config.test, fn -> long_attribute_list = Enum.map_join(0..55, " ", &"attribute#{&1}:string") - Gen.Html.run(~w(Blog Post posts #{long_attribute_list})) + Gen.Html.run(~w(Blog Post posts #{long_attribute_list} --no-scope)) assert_file("test/phoenix_web/controllers/post_controller_test.exs", fn file -> refute file =~ "...}" @@ -398,7 +399,7 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do test "with custom primary key", config do in_tmp_project(config.test, fn -> - Gen.Html.run(~w(Blog Post posts title:string --primary-key post_id)) + Gen.Html.run(~w(Blog Post posts title:string --primary-key post_id --no-scope)) assert_file("lib/phoenix_web/controllers/post_controller.ex", fn file -> assert file =~ ~s[%{"post_id" => post_id}] @@ -420,7 +421,7 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do test "without context_app generators config uses web dir", config do in_tmp_umbrella_project(config.test, fn -> Application.put_env(:phoenix, :generators, context_app: nil) - Gen.Html.run(~w(Accounts User users name:string)) + Gen.Html.run(~w(Accounts User users name:string --no-scope)) assert_file("lib/phoenix/accounts.ex") assert_file("lib/phoenix/accounts/user.ex") @@ -445,7 +446,7 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do Application.put_env(:phoenix, :generators, context_app: false) assert_raise Mix.Error, ~r/no context_app configured/, fn -> - Gen.Html.run(~w(Accounts User users name:string)) + Gen.Html.run(~w(Accounts User users name:string --no-scope)) end end) end @@ -455,7 +456,7 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do File.mkdir!("another_app") Application.put_env(:phoenix, :generators, context_app: {:another_app, "another_app"}) - Gen.Html.run(~w(Accounts User users name:string)) + Gen.Html.run(~w(Accounts User users name:string --no-scope)) assert_file("another_app/lib/another_app/accounts.ex") assert_file("another_app/lib/another_app/accounts/user.ex") @@ -477,7 +478,7 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do test "allows enum type with at least one value", config do in_tmp_project(config.test, fn -> - Gen.Html.run(~w(Blog Post posts status:enum:new)) + Gen.Html.run(~w(Blog Post posts status:enum:new --no-scope)) assert_file("lib/phoenix_web/controllers/post_html/post_form.html.heex", fn file -> assert file =~ ~s|Ecto.Enum.values(Phoenix.Blog.Post, :status)| diff --git a/test/mix/tasks/phx.gen.json_test.exs b/test/mix/tasks/phx.gen.json_test.exs index 696b000a02..b9b314d067 100644 --- a/test/mix/tasks/phx.gen.json_test.exs +++ b/test/mix/tasks/phx.gen.json_test.exs @@ -13,23 +13,23 @@ defmodule Mix.Tasks.Phx.Gen.JsonTest do test "invalid mix arguments", config do in_tmp_project(config.test, fn -> assert_raise Mix.Error, ~r/Expected the context, "blog", to be a valid module name/, fn -> - Gen.Json.run(~w(blog Post posts title:string)) + Gen.Json.run(~w(blog Post posts title:string --no-scope)) end assert_raise Mix.Error, ~r/Expected the schema, "posts", to be a valid module name/, fn -> - Gen.Json.run(~w(Post posts title:string)) + Gen.Json.run(~w(Post posts title:string --no-scope)) end assert_raise Mix.Error, ~r/The context and schema should have different names/, fn -> - Gen.Json.run(~w(Blog Blog blogs)) + Gen.Json.run(~w(Blog Blog blogs --no-scope)) end assert_raise Mix.Error, ~r/Invalid arguments/, fn -> - Gen.Json.run(~w(Blog.Post posts)) + Gen.Json.run(~w(Blog.Post posts --no-scope)) end assert_raise Mix.Error, ~r/Invalid arguments/, fn -> - Gen.Json.run(~w(Blog Post)) + Gen.Json.run(~w(Blog Post --no-scope)) end end) end @@ -56,7 +56,8 @@ defmodule Mix.Tasks.Phx.Gen.JsonTest do alarm:time alarm_usec:time_usec secret:uuid:redact announcement_date:date - weight:float user_id:references:users)) + weight:float user_id:references:users + --no-scope)) assert_file("lib/phoenix/blog/post.ex") assert_file("lib/phoenix/blog.ex") @@ -124,7 +125,7 @@ defmodule Mix.Tasks.Phx.Gen.JsonTest do test "generates into existing context without prompt with --merge-with-existing-context", config do in_tmp_project(config.test, fn -> - Gen.Json.run(~w(Blog Post posts title)) + Gen.Json.run(~w(Blog Post posts title --no-scope)) assert_file("lib/phoenix/blog.ex", fn file -> assert file =~ "def get_post!" @@ -135,7 +136,7 @@ defmodule Mix.Tasks.Phx.Gen.JsonTest do assert file =~ "def change_post" end) - Gen.Json.run(~w(Blog Comment comments message:string --merge-with-existing-context)) + Gen.Json.run(~w(Blog Comment comments message:string --merge-with-existing-context --no-scope)) refute_received {:mix_shell, :info, ["You are generating into an existing context" <> _notice]} @@ -154,7 +155,7 @@ defmodule Mix.Tasks.Phx.Gen.JsonTest do test "when more than 50 arguments are given", config do in_tmp_project(config.test, fn -> long_attribute_list = Enum.map_join(0..55, " ", &"attribute#{&1}:string") - Gen.Json.run(~w(Blog Post posts #{long_attribute_list})) + Gen.Json.run(~w(Blog Post posts #{long_attribute_list} --no-scope)) assert_file("test/phoenix_web/controllers/post_controller_test.exs", fn file -> refute file =~ "...}" @@ -164,7 +165,7 @@ defmodule Mix.Tasks.Phx.Gen.JsonTest do test "with json --web namespace generates namespaced web modules and directories", config do in_tmp_project(config.test, fn -> - Gen.Json.run(~w(Blog Post posts title:string --web Blog)) + Gen.Json.run(~w(Blog Post posts title:string --web Blog --no-scope)) assert_file("test/phoenix_web/controllers/blog/post_controller_test.exs", fn file -> assert file =~ "defmodule PhoenixWeb.Blog.PostControllerTest" @@ -203,7 +204,7 @@ defmodule Mix.Tasks.Phx.Gen.JsonTest do test "with --no-context skips context and schema file generation", config do in_tmp_project(config.test, fn -> - Gen.Json.run(~w(Blog Comment comments title:string --no-context)) + Gen.Json.run(~w(Blog Comment comments title:string --no-context --no-scope)) refute_file("lib/phoenix/blog.ex") refute_file("lib/phoenix/blog/comment.ex") @@ -226,12 +227,12 @@ defmodule Mix.Tasks.Phx.Gen.JsonTest do test "with --no-context no warning is emitted when context exists", config do in_tmp_project(config.test, fn -> - Gen.Json.run(~w(Blog Post posts title:string)) + Gen.Json.run(~w(Blog Post posts title:string --no-scope)) assert_file("lib/phoenix/blog.ex") assert_file("lib/phoenix/blog/post.ex") - Gen.Json.run(~w(Blog Comment comments title:string --no-context)) + Gen.Json.run(~w(Blog Comment comments title:string --no-context --no-scope)) refute_received {:mix_shell, :info, ["You are generating into an existing context" <> _]} assert_file("test/phoenix_web/controllers/comment_controller_test.exs", fn file -> @@ -251,7 +252,7 @@ defmodule Mix.Tasks.Phx.Gen.JsonTest do test "with --no-schema skips schema file generation", config do in_tmp_project(config.test, fn -> - Gen.Json.run(~w(Blog Comment comments title:string --no-schema)) + Gen.Json.run(~w(Blog Comment comments title:string --no-schema --no-scope)) assert_file("lib/phoenix/blog.ex") refute_file("lib/phoenix/blog/comment.ex") @@ -275,7 +276,7 @@ defmodule Mix.Tasks.Phx.Gen.JsonTest do describe "inside umbrella" do test "without context_app generators config uses web dir", config do in_tmp_umbrella_project(config.test, fn -> - Gen.Json.run(~w(Accounts User users name:string)) + Gen.Json.run(~w(Accounts User users name:string --no-scope)) assert_file("lib/phoenix/accounts.ex") assert_file("lib/phoenix/accounts/user.ex") @@ -300,7 +301,7 @@ defmodule Mix.Tasks.Phx.Gen.JsonTest do Application.put_env(:phoenix, :generators, context_app: false) assert_raise Mix.Error, ~r/no context_app configured/, fn -> - Gen.Json.run(~w(Accounts User users name:string)) + Gen.Json.run(~w(Accounts User users name:string --no-scope)) end end) end @@ -310,7 +311,7 @@ defmodule Mix.Tasks.Phx.Gen.JsonTest do File.mkdir!("another_app") Application.put_env(:phoenix, :generators, context_app: {:another_app, "another_app"}) - Gen.Json.run(~w(Accounts User users name:string)) + Gen.Json.run(~w(Accounts User users name:string --no-scope)) assert_file("another_app/lib/another_app/accounts.ex") assert_file("another_app/lib/another_app/accounts/user.ex") @@ -342,7 +343,7 @@ defmodule Mix.Tasks.Phx.Gen.JsonTest do [{module, _}] = Code.compile_file("lib/phoenix_web/components/core_components.ex") - Gen.Json.run(~w(Blog Post posts title:string --web Blog)) + Gen.Json.run(~w(Blog Post posts title:string --web Blog --no-scope)) assert_file("lib/phoenix_web/controllers/changeset_json.ex", fn file -> assert file =~ @@ -357,7 +358,7 @@ defmodule Mix.Tasks.Phx.Gen.JsonTest do test "with custom primary key", config do in_tmp_project(config.test, fn -> - Gen.Json.run(~w(Blog Post posts title:string --primary-key post_id)) + Gen.Json.run(~w(Blog Post posts title:string --primary-key post_id --no-scope)) assert_file "lib/phoenix_web/controllers/post_controller.ex", fn file -> refute file =~ ~s[%{"id" =>] diff --git a/test/mix/tasks/phx.gen.live_test.exs b/test/mix/tasks/phx.gen.live_test.exs index 2bc0661dc2..79418585f3 100644 --- a/test/mix/tasks/phx.gen.live_test.exs +++ b/test/mix/tasks/phx.gen.live_test.exs @@ -32,23 +32,23 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do test "invalid mix arguments", config do in_tmp_live_project config.test, fn -> assert_raise Mix.Error, ~r/Expected the context, "blog", to be a valid module name/, fn -> - Gen.Live.run(~w(blog Post posts title:string)) + Gen.Live.run(~w(blog Post posts title:string --no-scope)) end assert_raise Mix.Error, ~r/Expected the schema, "posts", to be a valid module name/, fn -> - Gen.Live.run(~w(Post posts title:string)) + Gen.Live.run(~w(Post posts title:string --no-scope)) end assert_raise Mix.Error, ~r/The context and schema should have different names/, fn -> - Gen.Live.run(~w(Blog Blog blogs)) + Gen.Live.run(~w(Blog Blog blogs --no-scope)) end assert_raise Mix.Error, ~r/Invalid arguments/, fn -> - Gen.Live.run(~w(Blog.Post posts)) + Gen.Live.run(~w(Blog.Post posts --no-scope)) end assert_raise Mix.Error, ~r/Invalid arguments/, fn -> - Gen.Live.run(~w(Blog Post)) + Gen.Live.run(~w(Blog Post --no-scope)) end end end @@ -66,7 +66,8 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do alarm_usec:time_usec secret:uuid:redact announcement_date:date alarm:time metadata:map - weight:float user_id:references:users)) + weight:float user_id:references:users + --no-scope)) assert_file "lib/phoenix/blog/post.ex" assert_file "lib/phoenix/blog.ex" @@ -140,7 +141,7 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do end send self(), {:mix_shell_input, :yes?, true} - Gen.Live.run(~w(Blog Comment comments title:string)) + Gen.Live.run(~w(Blog Comment comments title:string --no-scope)) assert_received {:mix_shell, :info, ["You are generating into an existing context" <> _]} assert_file "lib/phoenix/blog/comment.ex" @@ -187,7 +188,7 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do test "generates into existing context without prompt with --merge-with-existing-context", config do in_tmp_live_project config.test, fn -> - Gen.Live.run(~w(Blog Post posts title)) + Gen.Live.run(~w(Blog Post posts title --no-scope)) assert_file "lib/phoenix/blog.ex", fn file -> assert file =~ "def get_post!" @@ -198,7 +199,7 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do assert file =~ "def change_post" end - Gen.Live.run(~w(Blog Comment comments message:string --merge-with-existing-context)) + Gen.Live.run(~w(Blog Comment comments message:string --merge-with-existing-context --no-scope)) refute_received {:mix_shell, :info, ["You are generating into an existing context" <> _notice]} @@ -215,7 +216,7 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do test "with --web namespace generates namespaced web modules and directories", config do in_tmp_live_project config.test, fn -> - Gen.Live.run(~w(Blog Post posts title:string --web Blog)) + Gen.Live.run(~w(Blog Post posts title:string --web Blog --no-scope)) assert_file "lib/phoenix/blog/post.ex" assert_file "lib/phoenix/blog.ex" @@ -275,7 +276,7 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do test "with --no-context skips context and schema file generation", config do in_tmp_live_project config.test, fn -> - Gen.Live.run(~w(Blog Post posts title:string --no-context)) + Gen.Live.run(~w(Blog Post posts title:string --no-context --no-scope)) refute_file "lib/phoenix/blog.ex" refute_file "lib/phoenix/blog/post.ex" @@ -291,7 +292,7 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do test "with --no-schema skips schema file generation", config do in_tmp_live_project config.test, fn -> - Gen.Live.run(~w(Blog Post posts title:string --no-schema)) + Gen.Live.run(~w(Blog Post posts title:string --no-schema --no-scope)) assert_file "lib/phoenix/blog.ex" refute_file "lib/phoenix/blog/post.ex" @@ -307,12 +308,12 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do test "with --no-context does not emit warning when context exists", config do in_tmp_live_project config.test, fn -> - Gen.Live.run(~w(Blog Post posts title:string)) + Gen.Live.run(~w(Blog Post posts title:string --no-scope)) assert_file "lib/phoenix/blog.ex" assert_file "lib/phoenix/blog/post.ex" - Gen.Live.run(~w(Blog Comment comments title:string --no-context)) + Gen.Live.run(~w(Blog Comment comments title:string --no-context --no-scope)) refute_received {:mix_shell, :info, ["You are generating into an existing context" <> _]} assert_file "lib/phoenix_web/live/comment_live/index.ex" @@ -325,7 +326,7 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do test "with same singular and plural", config do in_tmp_live_project config.test, fn -> - Gen.Live.run(~w(Tracker Series series value:integer)) + Gen.Live.run(~w(Tracker Series series value:integer --no-scope)) assert_file "lib/phoenix/tracker.ex" assert_file "lib/phoenix/tracker/series.ex" @@ -348,7 +349,7 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do test "when more than 50 attributes are given", config do in_tmp_live_project config.test, fn -> long_attribute_list = Enum.map_join(0..55, " ", &("attribute#{&1}:string")) - Gen.Live.run(~w(Blog Post posts title #{long_attribute_list})) + Gen.Live.run(~w(Blog Post posts title #{long_attribute_list} --no-scope)) assert_file "test/phoenix/blog_test.exs", fn file -> refute file =~ "...}" @@ -365,7 +366,7 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do File.cd!("phoenix_web") Application.put_env(:phoenix, :generators, context_app: nil) - Gen.Live.run(~w(Accounts User users name:string)) + Gen.Live.run(~w(Accounts User users name:string --no-scope)) assert_file "lib/phoenix/accounts.ex" assert_file "lib/phoenix/accounts/user.ex" @@ -395,7 +396,7 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do in_tmp_live_umbrella_project config.test, fn -> Application.put_env(:phoenix, :generators, context_app: false) assert_raise Mix.Error, ~r/no context_app configured/, fn -> - Gen.Live.run(~w(Accounts User users name:string)) + Gen.Live.run(~w(Accounts User users name:string --no-scope)) end end end @@ -407,7 +408,7 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do File.cd!("phoenix") - Gen.Live.run(~w(Accounts User users name:string)) + Gen.Live.run(~w(Accounts User users name:string --no-scope)) assert_file "another_app/lib/another_app/accounts.ex" assert_file "another_app/lib/another_app/accounts/user.ex" @@ -437,7 +438,7 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do test "with custom primary key", config do in_tmp_live_project config.test, fn -> - Gen.Live.run(~w(Blog Post posts title:string --primary-key post_id)) + Gen.Live.run(~w(Blog Post posts title:string --primary-key post_id --no-scope)) assert_file "lib/phoenix_web/live/post_live/index.ex", fn file -> assert file =~ "defmodule PhoenixWeb.PostLive.Index" @@ -460,7 +461,7 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do test "raises on schema named form" do assert_raise Mix.Error, ~r/cannot use form as the schema name because it conflicts with the LiveView assigns/, fn -> - Mix.Tasks.Phx.Gen.Live.run(~w(Blog Form forms title:string)) + Mix.Tasks.Phx.Gen.Live.run(~w(Blog Form forms title:string --no-scope)) end end end diff --git a/test/mix/tasks/phx.gen.schema_test.exs b/test/mix/tasks/phx.gen.schema_test.exs index f808e8784a..cf84e7c5ed 100644 --- a/test/mix/tasks/phx.gen.schema_test.exs +++ b/test/mix/tasks/phx.gen.schema_test.exs @@ -16,7 +16,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do test "build" do in_tmp_project "build", fn -> - schema = Gen.Schema.build(~w(Blog.Post posts title:string tags:map), []) + schema = Gen.Schema.build(~w(Blog.Post posts title:string tags:map --no-scope), []) assert %Schema{ alias: Post, @@ -33,6 +33,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do optionals: [:tags], route_helper: "post", defaults: %{title: "", tags: ""}, + scope: nil } = schema assert String.ends_with?(schema.file, "lib/phoenix/blog/post.ex") end @@ -40,7 +41,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do test "build with nested web namespace", config do in_tmp_project config.test, fn -> - schema = Gen.Schema.build(~w(Blog.Post posts title:string --web API.V1), []) + schema = Gen.Schema.build(~w(Blog.Post posts title:string --web API.V1 --no-scope), []) assert %Schema{ alias: Post, @@ -56,6 +57,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do types: [title: :string], route_helper: "api_v1_post", defaults: %{title: ""}, + scope: nil } = schema assert String.ends_with?(schema.file, "lib/phoenix/blog/post.ex") end @@ -64,7 +66,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do test "table name missing from references", config do in_tmp_project config.test, fn -> assert_raise Mix.Error, ~r/expect the table to be given to user_id:references/, fn -> - Gen.Schema.run(~w(Blog.Post posts user_id:references)) + Gen.Schema.run(~w(Blog.Post posts user_id:references --no-scope)) end end end @@ -72,38 +74,38 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do test "type missing from array", config do in_tmp_project config.test, fn -> assert_raise Mix.Error, ~r/expect the type of the array to be given to settings:array/, fn -> - Gen.Schema.run(~w(Blog.Post posts settings:array)) + Gen.Schema.run(~w(Blog.Post posts settings:array --no-scope)) end end end test "plural can't contain a colon" do assert_raise Mix.Error, fn -> - Gen.Schema.run(~w(Blog Post title:string)) + Gen.Schema.run(~w(Blog Post title:string --no-scope)) end end test "plural can't have uppercased characters or camelized format" do assert_raise Mix.Error, fn -> - Gen.Schema.run(~w(Blog Post Posts title:string)) + Gen.Schema.run(~w(Blog Post Posts title:string --no-scope)) end assert_raise Mix.Error, fn -> - Gen.Schema.run(~w(Blog Post BlogPosts title:string)) + Gen.Schema.run(~w(Blog Post BlogPosts title:string --no-scope)) end end test "table name omitted", config do in_tmp_project config.test, fn -> assert_raise Mix.Error, fn -> - Gen.Schema.run(~w(Blog.Post)) + Gen.Schema.run(~w(Blog.Post --no-scope)) end end end test "generates schema", config do in_tmp_project config.test, fn -> - Gen.Schema.run(~w(Blog.Post blog_posts title:string)) + Gen.Schema.run(~w(Blog.Post blog_posts title:string --no-scope)) assert_file "lib/phoenix/blog/post.ex" assert [migration] = Path.wildcard("priv/repo/migrations/*_create_blog_posts.exs") @@ -115,7 +117,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do test "allows a custom repo", config do in_tmp_project config.test, fn -> - Gen.Schema.run(~w(Blog.Post blog_posts title:string --repo MyApp.CustomRepo)) + Gen.Schema.run(~w(Blog.Post blog_posts title:string --repo MyApp.CustomRepo --no-scope)) assert [migration] = Path.wildcard("priv/custom_repo/migrations/*_create_blog_posts.exs") assert_file migration, fn file -> @@ -126,7 +128,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do test "allows a custom migration dir", config do in_tmp_project config.test, fn -> - Gen.Schema.run(~w(Blog.Post blog_posts title:string --migration-dir priv/custom_dir)) + Gen.Schema.run(~w(Blog.Post blog_posts title:string --migration-dir priv/custom_dir --no-scope)) assert [migration] = Path.wildcard("priv/custom_dir/*_create_blog_posts.exs") assert_file migration, fn file -> @@ -138,7 +140,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do test "custom migration_dir takes precedence over custom repo name", config do in_tmp_project config.test, fn -> Gen.Schema.run(~w(Blog.Post blog_posts title:string \ - --repo MyApp.CustomRepo --migration-dir priv/custom_dir)) + --repo MyApp.CustomRepo --migration-dir priv/custom_dir --no-scope)) assert [migration] = Path.wildcard("priv/custom_dir/*_create_blog_posts.exs") assert_file migration, fn file -> @@ -149,7 +151,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do test "does not add maps to the required list", config do in_tmp_project config.test, fn -> - Gen.Schema.run(~w(Blog.Post blog_posts title:string tags:map published_at:naive_datetime)) + Gen.Schema.run(~w(Blog.Post blog_posts title:string tags:map published_at:naive_datetime --no-scope)) assert_file "lib/phoenix/blog/post.ex", fn file -> assert file =~ "cast(attrs, [:title, :tags, :published_at]" assert file =~ "validate_required([:title, :published_at]" @@ -159,7 +161,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do test "generates nested schema", config do in_tmp_project config.test, fn -> - Gen.Schema.run(~w(Blog.Admin.User users name:string)) + Gen.Schema.run(~w(Blog.Admin.User users name:string --no-scope)) assert [migration] = Path.wildcard("priv/repo/migrations/*_create_users.exs") assert_file migration, fn file -> @@ -176,7 +178,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do test "generates custom table name", config do in_tmp_project config.test, fn -> - Gen.Schema.run(~w(Blog.Post posts --table cms_posts)) + Gen.Schema.run(~w(Blog.Post posts --table cms_posts --no-scope)) assert [migration] = Path.wildcard("priv/repo/migrations/*_create_cms_posts.exs") assert_file migration, fn file -> @@ -187,7 +189,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do test "generates unique indices" , config do in_tmp_project config.test, fn -> - Gen.Schema.run(~w(Blog.Post posts title:unique secret:redact unique_int:integer:unique)) + Gen.Schema.run(~w(Blog.Post posts title:unique secret:redact unique_int:integer:unique --no-scope)) assert [migration] = Path.wildcard("priv/repo/migrations/*_create_posts.exs") assert_file migration, fn file -> @@ -212,7 +214,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do test "generates references and belongs_to associations", config do in_tmp_project config.test, fn -> - Gen.Schema.run(~w(Blog.Post posts title user_id:references:users)) + Gen.Schema.run(~w(Blog.Post posts title user_id:references:users --no-scope)) assert [migration] = Path.wildcard("priv/repo/migrations/*_create_posts.exs") assert_file migration, fn file -> @@ -228,7 +230,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do test "generates references with unique indexes", config do in_tmp_project config.test, fn -> - Gen.Schema.run(~w(Blog.Post posts title user_id:references:users unique_post_id:references:posts:unique)) + Gen.Schema.run(~w(Blog.Post posts title user_id:references:users unique_post_id:references:posts:unique --no-scope)) assert [migration] = Path.wildcard("priv/repo/migrations/*_create_posts.exs") @@ -251,7 +253,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do test "generates schema with proper datetime types", config do in_tmp_project config.test, fn -> - Gen.Schema.run(~w(Blog.Comment comments title:string drafted_at:datetime published_at:naive_datetime edited_at:utc_datetime locked_at:naive_datetime_usec)) + Gen.Schema.run(~w(Blog.Comment comments title:string drafted_at:datetime published_at:naive_datetime edited_at:utc_datetime locked_at:naive_datetime_usec --no-scope)) assert_file "lib/phoenix/blog/comment.ex", fn file -> assert file =~ "field :drafted_at, :naive_datetime" @@ -272,7 +274,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do test "generates schema with enum", config do in_tmp_project config.test, fn -> - Gen.Schema.run(~w(Blog.Comment comments title:string status:enum:unpublished:published:deleted)) + Gen.Schema.run(~w(Blog.Comment comments title:string status:enum:unpublished:published:deleted --no-scope)) assert_file "lib/phoenix/blog/comment.ex", fn file -> assert file =~ "field :status, Ecto.Enum, values: [:unpublished, :published, :deleted]" @@ -288,7 +290,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do test "generates migration with binary_id", config do in_tmp_project config.test, fn -> - Gen.Schema.run(~w(Blog.Post posts title user_id:references:users --binary-id)) + Gen.Schema.run(~w(Blog.Post posts title user_id:references:users --binary-id --no-scope)) assert_file "lib/phoenix/blog/post.ex", fn file -> assert file =~ "field :user_id, :binary_id" @@ -305,7 +307,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do test "generates migration with custom primary key", config do in_tmp_project config.test, fn -> - Gen.Schema.run(~w(Blog.Post posts title user_id:references:users --binary-id --primary-key post_id)) + Gen.Schema.run(~w(Blog.Post posts title user_id:references:users --binary-id --primary-key post_id --no-scope)) assert_file "lib/phoenix/blog/post.ex", fn file -> assert file =~ "@derive {Phoenix.Param, key: :post_id}" @@ -324,7 +326,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do test "generates schema and migration with prefix", config do in_tmp_project config.test, fn -> - Gen.Schema.run(~w(Blog.Post posts title --prefix cms)) + Gen.Schema.run(~w(Blog.Post posts title --prefix cms --no-scope)) assert_file "lib/phoenix/blog/post.ex", fn file -> assert file =~ "@schema_prefix :cms" @@ -339,7 +341,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do test "skips migration with --no-migration option", config do in_tmp_project config.test, fn -> - Gen.Schema.run(~w(Blog.Post posts --no-migration)) + Gen.Schema.run(~w(Blog.Post posts --no-migration --no-scope)) assert [] = Path.wildcard("priv/repo/migrations/*") end end @@ -347,7 +349,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do test "uses defaults from :generators configuration" do in_tmp_project "uses defaults from generators configuration (migration)", fn -> with_generator_env [migration: false], fn -> - Gen.Schema.run(~w(Blog.Post posts)) + Gen.Schema.run(~w(Blog.Post posts --no-scope)) assert [] = Path.wildcard("priv/repo/migrations/*") end @@ -355,7 +357,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do in_tmp_project "uses defaults from generators configuration (binary_id)", fn -> with_generator_env [binary_id: true], fn -> - Gen.Schema.run(~w(Blog.Post posts)) + Gen.Schema.run(~w(Blog.Post posts --no-scope)) assert [migration] = Path.wildcard("priv/repo/migrations/*_create_posts.exs") @@ -368,7 +370,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do in_tmp_project "uses defaults from generators configuration (:utc_datetime)", fn -> with_generator_env [timestamp_type: :utc_datetime], fn -> - Gen.Schema.run(~w(Blog.Post posts)) + Gen.Schema.run(~w(Blog.Post posts --no-scope)) assert [migration] = Path.wildcard("priv/repo/migrations/*_create_posts.exs") @@ -388,7 +390,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do try do Application.put_env(:ecto_sql, :migration_module, MyCustomApp.MigrationModule) - Gen.Schema.run(~w(Blog.Post posts)) + Gen.Schema.run(~w(Blog.Post posts --no-scope)) assert [migration] = Path.wildcard("priv/repo/migrations/*_create_posts.exs") @@ -404,7 +406,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do test "generates schema without extra line break", config do in_tmp_project config.test, fn -> - Gen.Schema.run(~w(Blog.Post posts title)) + Gen.Schema.run(~w(Blog.Post posts title --no-scope)) assert_file "lib/phoenix/blog/post.ex", fn file -> assert file =~ "import Ecto.Changeset\n\n schema" @@ -418,7 +420,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do Application.put_env(:phoenix, :generators, context_app: false) assert_raise Mix.Error, ~r/no context_app configured/, fn -> - Gen.Schema.run(~w(Blog.Post blog_posts title:string)) + Gen.Schema.run(~w(Blog.Post blog_posts title:string --no-scope)) end end end @@ -427,7 +429,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do in_tmp_umbrella_project config.test, fn -> Application.put_env(:phoenix, :generators, context_app: nil) - Gen.Schema.run(~w(Blog.Post blog_posts title:string)) + Gen.Schema.run(~w(Blog.Post blog_posts title:string --no-scope)) assert_file "lib/phoenix/blog/post.ex" assert [_] = Path.wildcard("priv/repo/migrations/*_create_blog_posts.exs") @@ -438,7 +440,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do in_tmp_umbrella_project config.test, fn -> Application.put_env(:phoenix, :generators, context_app: {:another_app, "another_app"}) - Gen.Schema.run(~w(Blog.Post blog_posts title:string)) + Gen.Schema.run(~w(Blog.Post blog_posts title:string --no-scope)) assert_file "another_app/lib/another_app/blog/post.ex" assert [_] = Path.wildcard("another_app/priv/repo/migrations/*_create_blog_posts.exs")